Coverage for app/tests/delivery_fee/calculation_transformers/test_reduce_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 ReduceFeeTransformer,
5)
6from app.delivery_fee import settings as settings
9@pytest.fixture
10def reduce_fee_transformer():
11 return ReduceFeeTransformer(settings.EXCLUDE_FEE_CONFIG_OPTIONS)
14def test__exclude_fee_transformer_no_exclusion_applied(reduce_fee_transformer: ReduceFeeTransformer):
15 current_fee = DeliveryFee(delivery_fee=10e2)
16 expected_fee = current_fee + 0
18 order_info = OrderInfo(
19 cart_value=1,
20 delivery_distance=0,
21 number_of_items=0,
22 time="2024-01-30T13:00:00Z"
23 )
24 delivery_fee = reduce_fee_transformer.transform(
25 order_info,
26 current_fee
27 )
28 # Cart value is 1, so no exclusion should be applied.
29 assert delivery_fee == expected_fee
32def test__exclude_fee_transformer_exclusion_applied(reduce_fee_transformer: ReduceFeeTransformer):
33 current_fee = DeliveryFee(delivery_fee=10e2)
34 expected_fee = DeliveryFee(delivery_fee=0)
36 order_info = OrderInfo(
37 cart_value=settings.EXCLUDE_FEE_CONFIG_OPTIONS.exclusion_cart_value_threshold,
38 delivery_distance=0,
39 number_of_items=0,
40 time="2024-01-30T13:00:00Z"
41 )
42 delivery_fee = reduce_fee_transformer.transform(
43 order_info,
44 current_fee
45 )
46 # Cart value is 200€, so exclusion should be applied.
47 assert delivery_fee == expected_fee
50def test__exclude_fee_transformer_exclusion_applied_with_over_threshold(reduce_fee_transformer: ReduceFeeTransformer):
51 current_fee = DeliveryFee(delivery_fee=10e2)
52 expected_fee = DeliveryFee(delivery_fee=0)
54 order_info = OrderInfo(
55 cart_value=settings.EXCLUDE_FEE_CONFIG_OPTIONS.exclusion_cart_value_threshold + 1,
56 delivery_distance=0,
57 number_of_items=0,
58 time="2024-01-30T13:00:00Z"
59 )
60 delivery_fee = reduce_fee_transformer.transform(
61 order_info,
62 current_fee
63 )
64 # Cart value is 200€, so exclusion should be applied.
65 assert delivery_fee == expected_fee