Example #1
0
 def test_get_products_with_quantities_raise_error_when_no_product_available_for_open_ended(
     self, ):
     zone = ParkingZoneFactory()
     start_time = timezone.make_aware(datetime(2021, 2, 15))
     permit = ParkingPermitFactory(
         parking_zone=zone,
         contract_type=ContractType.OPEN_ENDED,
         start_time=start_time,
         month_count=1,
     )
     with self.assertRaises(ProductCatalogError):
         permit.get_products_with_quantities()
Example #2
0
 def test_get_products_with_quantities_should_return_products_with_quantities_for_fix_period_with_mid_month_start(
     self, ):
     product_detail_list = [
         [(date(2021, 1, 10), date(2021, 5, 9)),
          Decimal("30")],
         [(date(2021, 5, 10), date(2021, 8, 9)),
          Decimal("30")],
         [(date(2021, 8, 10), date(2021, 12, 31)),
          Decimal("30")],
     ]
     products = self._create_zone_products(self.zone_a, product_detail_list)
     start_time = timezone.make_aware(datetime(2021, 2, 15))
     end_time = get_end_time(start_time, 10)  # ends at 2021-2-14, 23:59
     permit = ParkingPermitFactory(
         parking_zone=self.zone_a,
         contract_type=ContractType.FIXED_PERIOD,
         start_time=start_time,
         end_time=end_time,
         month_count=10,
     )
     products_with_quantities = permit.get_products_with_quantities()
     self.assertEqual(products_with_quantities[0][0].id, products[0].id)
     self.assertEqual(products_with_quantities[0][1], 3)
     self.assertEqual(products_with_quantities[1][0].id, products[1].id)
     self.assertEqual(products_with_quantities[1][1], 3)
     self.assertEqual(products_with_quantities[2][0].id, products[2].id)
     self.assertEqual(products_with_quantities[2][1], 4)
Example #3
0
 def test_get_products_with_quantities_raise_error_when_multiple_products_available_for_open_ended(
     self, ):
     product_detail_list = [
         [(date(2021, 1, 1), date(2021, 6, 30)),
          Decimal("30")],
         [(date(2021, 5, 1), date(2021, 12, 31)),
          Decimal("30")],
     ]
     self._create_zone_products(self.zone_a, product_detail_list)
     start_time = timezone.make_aware(datetime(2021, 6, 15))
     permit = ParkingPermitFactory(
         parking_zone=self.zone_a,
         contract_type=ContractType.OPEN_ENDED,
         start_time=start_time,
         month_count=1,
     )
     with self.assertRaises(ProductCatalogError):
         permit.get_products_with_quantities()
Example #4
0
 def test_get_products_with_quantities_should_raise_error_when_products_does_not_cover_permit_duration(
     self, ):
     product_detail_list = [
         [(date(2021, 1, 10), date(2021, 5, 9)),
          Decimal("30")],
         [(date(2021, 5, 10), date(2021, 10, 9)),
          Decimal("30")],
     ]
     self._create_zone_products(self.zone_a, product_detail_list)
     start_time = timezone.make_aware(datetime(2021, 2, 15))
     end_time = get_end_time(start_time, 10)  # ends at 2021-2-14, 23:59
     permit = ParkingPermitFactory(
         parking_zone=self.zone_a,
         contract_type=ContractType.FIXED_PERIOD,
         start_time=start_time,
         end_time=end_time,
         month_count=10,
     )
     with self.assertRaises(ProductCatalogError):
         permit.get_products_with_quantities()
Example #5
0
 def test_get_products_with_quantities_should_return_a_single_product_for_open_ended(
     self, ):
     product_detail_list = [[(date(2021, 1, 1), date(2021, 12, 31)),
                             Decimal("30")]]
     self._create_zone_products(self.zone_a, product_detail_list)
     start_time = timezone.make_aware(datetime(2021, 2, 15))
     permit = ParkingPermitFactory(
         parking_zone=self.zone_a,
         contract_type=ContractType.OPEN_ENDED,
         start_time=start_time,
         month_count=1,
     )
     products = permit.get_products_with_quantities()
     self.assertEqual(len(products), 1)
     self.assertEqual(products[0][1], 1)