Coverage for app/tests/delivery_fee/calculation_transformers/test_limit_fee_transformer.py: 100%
25 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-11-27 09:26 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2024-11-27 09:26 +0000
1import pytest
2from app.delivery_fee.models import DeliveryFee, OrderInfo
3from app.delivery_fee.fee_transformers import (
4 LimitFeeTransformer,
5)
6from app.delivery_fee import settings as settings
9@pytest.fixture
10def limit_fee_transformer():
11 return LimitFeeTransformer(settings.LIMIT_FEE_CONFIG_OPTIONS)
14def test__limit_fee_transformer(limit_fee_transformer: LimitFeeTransformer):
15 current_fee = DeliveryFee(
16 delivery_fee=settings.LIMIT_FEE_CONFIG_OPTIONS.highest_limit_of_delivery_fee-1)
17 expected_fee = current_fee + 0
19 order_info = OrderInfo(
20 cart_value=0,
21 delivery_distance=0,
22 number_of_items=0,
23 time="2024-01-30T13:00:00Z"
24 )
25 delivery_fee = limit_fee_transformer.transform(
26 order_info,
27 current_fee
28 )
29 # Delivery fee is below limit, so no limit should not be applied.
30 assert delivery_fee == expected_fee
33def test__limit_fee_transformer__edge_value(limit_fee_transformer: LimitFeeTransformer):
34 current_fee = DeliveryFee(
35 delivery_fee=settings.LIMIT_FEE_CONFIG_OPTIONS.highest_limit_of_delivery_fee)
36 expected_fee = current_fee + 0
38 order_info = OrderInfo(
39 cart_value=0,
40 delivery_distance=0,
41 number_of_items=0,
42 time="2024-01-30T13:00:00Z"
43 )
44 delivery_fee = limit_fee_transformer.transform(
45 order_info,
46 current_fee
47 )
49 # Delivery fee is 15€, so no limit should be applied.
50 assert delivery_fee == expected_fee
53def test__limit_fee_transformer__limit_applied(limit_fee_transformer: LimitFeeTransformer):
54 current_fee = DeliveryFee(delivery_fee=16e2)
55 expected_fee = DeliveryFee(
56 delivery_fee=settings.LIMIT_FEE_CONFIG_OPTIONS.highest_limit_of_delivery_fee)
58 order_info = OrderInfo(
59 cart_value=0,
60 delivery_distance=0,
61 number_of_items=0,
62 time="2024-01-30T13:00:00Z"
63 )
64 delivery_fee = limit_fee_transformer.transform(
65 order_info,
66 current_fee
67 )
68 # Delivery fee is over 15€, so it should be transformed to 15€.
69 assert delivery_fee == expected_fee