def test_get_changed_reversion_comment(self): with reversion.create_revision(): permit = ParkingPermitFactory(status=ParkingPermitStatus.DRAFT) with reversion.create_revision(): permit.status = ParkingPermitStatus.VALID permit.save(update_fields=["status"]) comment = get_reversion_comment(EventType.CHANGED, permit) self.assertEqual(comment, "CHANGED|Status: DRAFT --> VALID")
def test_create_renewable_order_should_create_renewal_order(self): start_time = timezone.make_aware(datetime(CURRENT_YEAR, 3, 15)) end_time = get_end_time(start_time, 6) # end at CURRENT_YEAR-09-14 23:59 high_emission_vehicle = VehicleFactory( power_type=VehiclePowerType.BENSIN, emission=100, euro_class=6, emission_type=EmissionType.WLTP, ) low_emission_vehicle = VehicleFactory( power_type=VehiclePowerType.BENSIN, emission=70, euro_class=6, emission_type=EmissionType.WLTP, ) LowEmissionCriteriaFactory( start_date=start_time, end_date=end_time, nedc_max_emission_limit=None, wltp_max_emission_limit=80, euro_min_class_limit=6, power_type=low_emission_vehicle.power_type, ) permit = ParkingPermitFactory( parking_zone=self.zone, vehicle=high_emission_vehicle, customer=self.customer, contract_type=ContractType.FIXED_PERIOD, status=ParkingPermitStatus.DRAFT, start_time=start_time, end_time=end_time, month_count=6, ) order = Order.objects.create_for_permits([permit]) order.status = OrderStatus.CONFIRMED order.save() permit.refresh_from_db() permit.status = ParkingPermitStatus.VALID permit.vehicle = low_emission_vehicle permit.save() with freeze_time(timezone.make_aware(datetime(CURRENT_YEAR, 5, 5))): new_order = Order.objects.create_renewal_order(self.customer) order_items = new_order.order_items.all().order_by("start_date") self.assertEqual(order_items.count(), 2) self.assertEqual(order_items[0].unit_price, Decimal(15)) self.assertEqual(order_items[0].payment_unit_price, Decimal(-15)) self.assertEqual(order_items[0].quantity, 2) self.assertEqual(order_items[1].unit_price, Decimal(25)) self.assertEqual(order_items[1].payment_unit_price, Decimal(-25)) self.assertEqual(order_items[1].quantity, 2)
def test_get_changelogs(self): user = UserFactory() with reversion.create_revision(): permit = ParkingPermitFactory() reversion.set_user(user) comment = get_reversion_comment(EventType.CREATED, permit) reversion.set_comment(comment) with reversion.create_revision(): permit.status = ParkingPermitStatus.VALID permit.save(update_fields=["status"]) comment = get_reversion_comment(EventType.CHANGED, permit) reversion.set_comment(comment) changelogs = get_obj_changelogs(permit) self.assertEqual(len(changelogs), 2) # most recent changelog is in the beginning of th elist self.assertEqual(changelogs[0]["event"], EventType.CHANGED) self.assertEqual(changelogs[1]["event"], EventType.CREATED)
def test_create_renewable_order_should_raise_error_for_open_ended_permits( self): start_time = timezone.make_aware(datetime(CURRENT_YEAR, 3, 15)) end_time = get_end_time(start_time, 6) # end at 2022-09-14 23:59 permit = ParkingPermitFactory( parking_zone=self.zone, customer=self.customer, contract_type=ContractType.OPEN_ENDED, status=ParkingPermitStatus.DRAFT, start_time=start_time, end_time=end_time, month_count=6, ) Order.objects.create_for_permits([permit]) permit.status = ParkingPermitStatus.VALID permit.save() with freeze_time(timezone.make_aware(datetime(CURRENT_YEAR, 5, 5))): with self.assertRaises(OrderCreationFailed): Order.objects.create_renewal_order(self.customer)