013 add price multiplier
This commit is contained in:
@@ -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