Добавлена отправка NotificationURL и SuccessURL

This commit is contained in:
Раис Юсупалиев
2026-04-18 00:58:13 +03:00
parent bddac60965
commit 78e9ad4fa9
18 changed files with 252 additions and 3 deletions
@@ -17,6 +17,8 @@ adapter:
tbank_payment:
init_url: "https://securepay.tinkoff.ru/v2/Init"
notification_url: "https://default.test/tbank/notification"
success_url: "https://default.test/payment/success"
auth:
terminal_key: "yaml-terminal-key"
password: "yaml-password"
@@ -25,6 +25,8 @@ adapter:
tbank_payment:
init_url: "https://securepay.tinkoff.ru/v2/Init"
notification_url: "https://merchant.test/tbank/notification"
success_url: "https://merchant.test/payment/success"
auth:
terminal_key: "test-terminal-key"
password: "test-password"
@@ -14,6 +14,8 @@ repository:
tbank_payment:
init_url: "https://securepay.tinkoff.ru/v2/Init"
notification_url: "https://merchant.test/tbank/notification"
success_url: "https://merchant.test/payment/success"
auth:
terminal_key: "test-terminal-key"
password: "test-password"
@@ -25,6 +25,8 @@ adapter:
tbank_payment:
init_url: "https://securepay.tinkoff.ru/v2/Init"
notification_url: "https://merchant.test/tbank/notification"
success_url: "https://merchant.test/payment/success"
auth:
terminal_key: "test-terminal-key"
password: "test-password"
@@ -25,6 +25,8 @@ adapter:
tbank_payment:
init_url: "https://securepay.tinkoff.ru/v2/Init"
notification_url: "https://merchant.test/tbank/notification"
success_url: "https://merchant.test/payment/success"
auth:
terminal_key: "test-terminal-key"
password: "test-password"
@@ -25,6 +25,8 @@ adapter:
tbank_payment:
init_url: "https://securepay.tinkoff.ru/v2/Init"
notification_url: "https://merchant.test/tbank/notification"
success_url: "https://merchant.test/payment/success"
auth:
terminal_key: "test-terminal-key"
password: "test-password"
@@ -24,6 +24,8 @@ adapter:
tbank_payment:
init_url: "https://securepay.tinkoff.ru/v2/Init"
notification_url: "https://merchant.test/tbank/notification"
success_url: "https://merchant.test/payment/success"
auth:
terminal_key: "test-terminal-key"
password: "test-password"
@@ -17,6 +17,8 @@ adapter:
tbank_payment:
init_url: "https://securepay.tinkoff.ru/v2/Init"
notification_url: "https://override.test/tbank/notification"
success_url: "https://override.test/payment/success"
auth:
terminal_key: "override-terminal-key"
password: "override-password"
+93
View File
@@ -104,6 +104,56 @@ def _use_runtime_config_files(
get_settings.cache_clear()
def _write_tbank_url_validation_config(
tmp_path: Path,
*,
include_notification_url: bool = True,
include_success_url: bool = True,
) -> Path:
notification_url = (
' notification_url: "https://merchant.test/tbank/notification"\n'
if include_notification_url
else ""
)
success_url = (
' success_url: "https://merchant.test/payment/success"\n'
if include_success_url
else ""
)
config_file = tmp_path / "config.yaml"
config_file.write_text(
f"""
controller: {{}}
service: {{}}
business_logic:
provider_price_multiplier: 1.0
repository: {{}}
adapter: {{}}
tbank_payment:
init_url: "https://securepay.tinkoff.ru/v2/Init"
{notification_url}{success_url} auth:
terminal_key: "test-terminal-key"
password: "test-password"
postgres:
dsn: "postgresql+asyncpg://postgres:postgres@localhost:5432/config_test"
address_suggestions: {{}}
observability:
service_name: "config-test"
otlp_endpoint: "http://collector:4317"
""".strip(),
encoding="utf-8",
)
return config_file
def test_configuration_sections_are_loaded_from_yaml_file(
monkeypatch: pytest.MonkeyPatch,
) -> None:
@@ -127,6 +177,11 @@ def test_configuration_sections_are_loaded_from_yaml_file(
assert settings.adapter.cdek_timeout_seconds == 10.0
assert settings.adapter.cdek_cache_ttl_seconds == 900
assert settings.tbank_payment.init_url == "https://securepay.tinkoff.ru/v2/Init"
assert (
settings.tbank_payment.notification_url
== "https://merchant.test/tbank/notification"
)
assert settings.tbank_payment.success_url == "https://merchant.test/payment/success"
assert settings.tbank_payment.auth.terminal_key == "test-terminal-key"
assert settings.tbank_payment.auth.password == "test-password"
assert settings.tbank_payment.timeout_seconds == 10.0
@@ -203,6 +258,10 @@ def test_get_settings_returns_cached_instance(monkeypatch: pytest.MonkeyPatch) -
assert first.service.provider_timeout_seconds == 10.0
assert first.business_logic.provider_price_multiplier == Decimal("1.0")
assert first.tbank_payment.auth.terminal_key == "test-terminal-key"
assert (
first.tbank_payment.notification_url
== "https://merchant.test/tbank/notification"
)
assert first.postgres.dsn.endswith("/g2s_aggregator_test")
assert first.address_suggestions.country_to_provider["RU"] == "dadata"
assert first.observability.service_name == "g2s-aggregator-test"
@@ -226,6 +285,11 @@ def test_get_settings_uses_config_test_yaml_in_pytest_environment(
assert settings.adapter.cdek_client_id == "test-id"
assert settings.tbank_payment.auth.terminal_key == "override-terminal-key"
assert settings.tbank_payment.auth.password == "override-password"
assert (
settings.tbank_payment.notification_url
== "https://override.test/tbank/notification"
)
assert settings.tbank_payment.success_url == "https://override.test/payment/success"
assert settings.tbank_payment.timeout_seconds == 4.25
assert settings.tbank_payment.retry_attempts == 1
assert settings.tbank_payment.retry_backoff_seconds == 0.05
@@ -283,6 +347,35 @@ def test_get_settings_fails_when_provider_price_multiplier_is_missing(
get_settings.cache_clear()
@pytest.mark.parametrize(
("include_notification_url", "include_success_url", "expected_location"),
(
(False, True, ("tbank_payment", "notification_url")),
(True, False, ("tbank_payment", "success_url")),
),
)
def test_get_settings_fails_when_tbank_payment_url_is_missing(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
include_notification_url: bool,
include_success_url: bool,
expected_location: tuple[str, str],
) -> None:
config_file = _write_tbank_url_validation_config(
tmp_path,
include_notification_url=include_notification_url,
include_success_url=include_success_url,
)
_use_runtime_config_files(monkeypatch, test_config_file=config_file)
with pytest.raises(ValidationError) as error:
get_settings()
locations = {tuple(item["loc"]) for item in error.value.errors()}
assert expected_location in locations
get_settings.cache_clear()
def test_get_settings_fails_when_observability_section_is_missing(
monkeypatch: pytest.MonkeyPatch,
) -> None: