Coverage for app/tests/delivery_fee/calculation_steps/test_cart_value_fee.py: 100%

25 statements  

« 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_calculation_steps import ( 

4 CartValueFee 

5) 

6import app.delivery_fee.settings as settings 

7 

8 

9@pytest.fixture 

10def cart_value_fee(): 

11 return CartValueFee(settings.CART_VALUE_CONFIG_OPTIONS) 

12 

13 

14def test__cart_value_fee_applies_surcharge(cart_value_fee: CartValueFee): 

15 expected_fee = 300 

16 

17 order_info = OrderInfo( 

18 cart_value=settings.CART_VALUE_CONFIG_OPTIONS.cart_value_surcharge_threshold - expected_fee, 

19 delivery_distance=0, 

20 number_of_items=0, 

21 time="2024-01-15T13:00:00Z" 

22 ) 

23 delivery_fee = cart_value_fee.calculate(order_info) 

24 # Cart value is less than 10€, so surcharge is applied. 

25 assert delivery_fee == DeliveryFee(delivery_fee=expected_fee) 

26 

27 

28def test__cart_value_fee_no_surcharge(cart_value_fee: CartValueFee): 

29 order_info = OrderInfo( 

30 cart_value=settings.CART_VALUE_CONFIG_OPTIONS.cart_value_surcharge_threshold, 

31 delivery_distance=0, 

32 number_of_items=0, 

33 time="2024-01-15T13:00:00Z" 

34 ) 

35 delivery_fee = cart_value_fee.calculate(order_info) 

36 # Cart value is equal to 10€, so no surcharge is applied. 

37 assert delivery_fee == DeliveryFee(delivery_fee=0) 

38 

39 

40def test__cart_value_fee_test_case_from_example(cart_value_fee: CartValueFee): 

41 order_info = OrderInfo( 

42 cart_value=8.9e2, 

43 delivery_distance=0, 

44 number_of_items=0, 

45 time="2024-01-15T13:00:00Z" 

46 ) 

47 delivery_fee = cart_value_fee.calculate(order_info) 

48 # Test case from example 

49 assert delivery_fee == DeliveryFee(delivery_fee=1.1e2) 

50 

51 

52def test__cart_value_fee_over_threshold(cart_value_fee: CartValueFee): 

53 expected_fee = 0 

54 

55 order_info = OrderInfo( 

56 cart_value=settings.CART_VALUE_CONFIG_OPTIONS.cart_value_surcharge_threshold + 1, 

57 delivery_distance=0, 

58 number_of_items=0, 

59 time="2024-01-15T13:00:00Z" 

60 ) 

61 delivery_fee = cart_value_fee.calculate(order_info) 

62 

63 # Cart value is more than 10€, so no surcharge is applied. 

64 assert delivery_fee == DeliveryFee(delivery_fee=expected_fee)