013 add price multiplier
This commit is contained in:
@@ -6,6 +6,7 @@ service:
|
||||
|
||||
business_logic:
|
||||
weight_round_scale: 2
|
||||
provider_price_multiplier: 1.0
|
||||
|
||||
repository:
|
||||
redis_dsn: "redis://localhost:6379/0"
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
controller:
|
||||
api_prefix: "/api/v1"
|
||||
request_id_header: "X-Request-ID"
|
||||
|
||||
service:
|
||||
provider_timeout_seconds: 10.0
|
||||
max_parallel_providers: 8
|
||||
|
||||
business_logic:
|
||||
weight_round_scale: 2
|
||||
provider_price_multiplier: 0
|
||||
|
||||
repository:
|
||||
redis_dsn: "redis://localhost:6379/0"
|
||||
price_cache_ttl_seconds: 900
|
||||
|
||||
adapter:
|
||||
cdek_base_url: "https://api.cdek.ru/v2"
|
||||
cdek_client_id: "test-client-id"
|
||||
cdek_client_secret: "test-client-secret"
|
||||
cdek_retry_attempts: 2
|
||||
cdek_retry_backoff_seconds: 0.2
|
||||
cdek_timeout_seconds: 10.0
|
||||
cdek_cache_ttl_seconds: 900
|
||||
@@ -6,6 +6,7 @@ service:
|
||||
|
||||
business_logic:
|
||||
weight_round_scale: 2
|
||||
provider_price_multiplier: 1.0
|
||||
|
||||
repository:
|
||||
redis_dsn: "redis://localhost:6379/0"
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
controller:
|
||||
api_prefix: "/api/v1"
|
||||
request_id_header: "X-Request-ID"
|
||||
|
||||
service:
|
||||
provider_timeout_seconds: 10.0
|
||||
max_parallel_providers: 8
|
||||
|
||||
business_logic:
|
||||
weight_round_scale: 2
|
||||
|
||||
repository:
|
||||
redis_dsn: "redis://localhost:6379/0"
|
||||
price_cache_ttl_seconds: 900
|
||||
|
||||
adapter:
|
||||
cdek_base_url: "https://api.cdek.ru/v2"
|
||||
cdek_client_id: "test-client-id"
|
||||
cdek_client_secret: "test-client-secret"
|
||||
cdek_retry_attempts: 2
|
||||
cdek_retry_backoff_seconds: 0.2
|
||||
cdek_timeout_seconds: 10.0
|
||||
cdek_cache_ttl_seconds: 900
|
||||
@@ -6,6 +6,7 @@ service:
|
||||
|
||||
business_logic:
|
||||
weight_round_scale: 2
|
||||
provider_price_multiplier: 1.25
|
||||
|
||||
repository:
|
||||
redis_dsn: "redis://localhost:6379/0"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from decimal import Decimal
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
@@ -17,6 +18,12 @@ DEFAULT_CONFIG_FILE_FIXTURE = (
|
||||
TEST_OVERRIDE_CONFIG_FILE_FIXTURE = (
|
||||
PROJECT_ROOT / "tests" / "config" / "fixtures" / "config.test.override.yaml"
|
||||
)
|
||||
INVALID_PRICE_MULTIPLIER_CONFIG_FILE = (
|
||||
PROJECT_ROOT / "tests" / "config" / "fixtures" / "config.invalid_price_multiplier.yaml"
|
||||
)
|
||||
MISSING_PRICE_MULTIPLIER_CONFIG_FILE = (
|
||||
PROJECT_ROOT / "tests" / "config" / "fixtures" / "config.missing_price_multiplier.yaml"
|
||||
)
|
||||
|
||||
|
||||
def _use_runtime_config_files(
|
||||
@@ -47,6 +54,7 @@ def test_configuration_sections_are_loaded_from_yaml_file(
|
||||
assert settings.service.provider_timeout_seconds == 10.0
|
||||
assert settings.service.max_parallel_providers == 8
|
||||
assert settings.business_logic.weight_round_scale == 2
|
||||
assert settings.business_logic.provider_price_multiplier == Decimal("1.0")
|
||||
assert settings.repository.redis_dsn == "redis://localhost:6379/0"
|
||||
assert settings.repository.price_cache_ttl_seconds == 900
|
||||
assert settings.adapter.cdek_base_url == "https://api.cdek.ru/v2"
|
||||
@@ -82,6 +90,7 @@ def test_get_settings_returns_cached_instance(monkeypatch: pytest.MonkeyPatch) -
|
||||
|
||||
assert first is second
|
||||
assert first.service.provider_timeout_seconds == 10.0
|
||||
assert first.business_logic.provider_price_multiplier == Decimal("1.0")
|
||||
get_settings.cache_clear()
|
||||
|
||||
|
||||
@@ -98,5 +107,38 @@ def test_get_settings_uses_config_test_yaml_in_pytest_environment(
|
||||
|
||||
assert settings.service.provider_timeout_seconds == 17.0
|
||||
assert settings.controller.api_prefix == "/from-config-test-yaml"
|
||||
assert settings.business_logic.provider_price_multiplier == Decimal("1.25")
|
||||
assert settings.adapter.cdek_client_id == "test-id"
|
||||
get_settings.cache_clear()
|
||||
|
||||
|
||||
def test_get_settings_fails_when_provider_price_multiplier_is_invalid(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
_use_runtime_config_files(
|
||||
monkeypatch,
|
||||
test_config_file=INVALID_PRICE_MULTIPLIER_CONFIG_FILE,
|
||||
)
|
||||
|
||||
with pytest.raises(ValidationError) as error:
|
||||
get_settings()
|
||||
|
||||
locations = {tuple(item["loc"]) for item in error.value.errors()}
|
||||
assert ("business_logic", "provider_price_multiplier") in locations
|
||||
get_settings.cache_clear()
|
||||
|
||||
|
||||
def test_get_settings_fails_when_provider_price_multiplier_is_missing(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
_use_runtime_config_files(
|
||||
monkeypatch,
|
||||
test_config_file=MISSING_PRICE_MULTIPLIER_CONFIG_FILE,
|
||||
)
|
||||
|
||||
with pytest.raises(ValidationError) as error:
|
||||
get_settings()
|
||||
|
||||
locations = {tuple(item["loc"]) for item in error.value.errors()}
|
||||
assert ("business_logic", "provider_price_multiplier") in locations
|
||||
get_settings.cache_clear()
|
||||
|
||||
Reference in New Issue
Block a user