Skip to content

Commit

Permalink
Permit can be ended if current period end time same day or less than
Browse files Browse the repository at this point in the history
permit end time.

Refs: PV-786
  • Loading branch information
danjacob-anders authored and mhieta committed Feb 7, 2024
1 parent 453dcb3 commit eeb055c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
10 changes: 8 additions & 2 deletions parking_permits/models/parking_permit.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,14 @@ def can_end_immediately(self):

@property
def can_end_after_current_period(self):
return self.is_valid and (
self.end_time is None or self.current_period_end_time < self.end_time
if not self.is_valid:
return False

if self.end_time is None:
return False

return timezone.localdate(self.current_period_end_time) <= timezone.localdate(
self.end_time
)

@property
Expand Down
71 changes: 71 additions & 0 deletions parking_permits/tests/models/test_parking_permit.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ def _create_zone_products(self, zone, product_detail_list):

@freeze_time(timezone.make_aware(datetime(2021, 11, 15)))
def test_should_return_correct_months_used(self):
start_time = timezone.now()
end_time = get_end_time(start_time, 1)

open_ended_started_immediately = ParkingPermitFactory(
contract_type=ContractType.OPEN_ENDED,
start_time=start_time,
end_time=end_time,
)

self.assertEqual(open_ended_started_immediately.months_used, 1)

start_time = timezone.make_aware(datetime(2021, 9, 15))
end_time = get_end_time(start_time, 6)
fixed_period_permit_started_2_months_ago = ParkingPermitFactory(
Expand Down Expand Up @@ -95,6 +106,47 @@ def test_should_return_correct_months_used(self):
)
self.assertEqual(open_ended_permit_started_two_years_ago.months_used, 25)

@freeze_time(timezone.make_aware(datetime(2024, 1, 1)))
def test_can_end_after_current_period_end_time_fixed_period(self):
start_time = timezone.make_aware(datetime(2024, 1, 1))
end_time = get_end_time(start_time, 6)
permit = ParkingPermitFactory(
status=ParkingPermitStatus.VALID,
contract_type=ContractType.FIXED_PERIOD,
start_time=start_time,
end_time=end_time,
month_count=6,
)
self.assertTrue(permit.can_end_after_current_period)

@freeze_time(timezone.make_aware(datetime(2024, 1, 1)))
def test_can_end_after_current_period_end_time_fixed_period_current_period_end_time_gt_end_time(
self,
):
start_time = timezone.make_aware(datetime(2023, 11, 1))
end_time = get_end_time(start_time, 1)
permit = ParkingPermitFactory(
status=ParkingPermitStatus.VALID,
contract_type=ContractType.FIXED_PERIOD,
start_time=start_time,
end_time=end_time,
month_count=3,
)
self.assertFalse(permit.can_end_after_current_period)

@freeze_time(timezone.make_aware(datetime(2024, 1, 1)))
def test_can_end_after_current_period_end_time_open_ended(self):
start_time = timezone.make_aware(datetime(2024, 1, 1))
end_time = get_end_time(start_time, 1)
permit = ParkingPermitFactory(
status=ParkingPermitStatus.VALID,
contract_type=ContractType.OPEN_ENDED,
start_time=start_time,
end_time=end_time,
month_count=1,
)
self.assertTrue(permit.can_end_after_current_period)

@freeze_time(timezone.make_aware(datetime(2021, 11, 15)))
def test_should_return_correct_months_left(self):
start_time = timezone.make_aware(datetime(2021, 9, 15))
Expand Down Expand Up @@ -136,6 +188,25 @@ def test_should_return_correct_months_left(self):

@freeze_time(timezone.make_aware(datetime(2022, 1, 20)))
def test_should_return_correct_end_time_of_current_time(self):
start_time = timezone.make_aware(datetime(2022, 1, 20))
end_time = get_end_time(start_time, 1)
permit = ParkingPermitFactory(
contract_type=ContractType.OPEN_ENDED,
start_time=start_time,
end_time=end_time,
month_count=1,
)

self.assertEqual(
permit.end_time,
permit.current_period_end_time,
)

self.assertEqual(
permit.current_period_end_time,
timezone.make_aware(datetime(2022, 2, 19, 23, 59, 59, 999999)),
)

start_time = timezone.make_aware(datetime(2021, 11, 15))
end_time = get_end_time(start_time, 6)
permit = ParkingPermitFactory(
Expand Down

0 comments on commit eeb055c

Please sign in to comment.