Skip to content

Commit

Permalink
Add PERMIT_EXTENSIONS_ENABLED flag to allow extending permits
Browse files Browse the repository at this point in the history
Refs: PV-794
  • Loading branch information
danjacob-anders authored and mhieta committed Feb 15, 2024
1 parent 7f4c68d commit c0b1a26
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions parking_permits/models/parking_permit.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ def can_extend_permit(self):
2. Cannot have any pending requests.
3. Must be within 14 days of end time.
"""
if not settings.PERMIT_EXTENSIONS_ENABLED:
return False

if self.status != ParkingPermitStatus.VALID:
return False
Expand Down
18 changes: 18 additions & 0 deletions parking_permits/tests/models/test_parking_permit.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ def test_get_price_list_for_extended_permit(self):
self.assertEqual(price_list[1]["net_price"], "32.26")
self.assertEqual(price_list[1]["vat_price"], "7.74")

@override_settings(PERMIT_EXTENSIONS_ENABLED=True)
def test_can_extend_permit_not_valid(self):
self.assertFalse(
ParkingPermitFactory(
Expand All @@ -881,6 +882,7 @@ def test_can_extend_permit_not_valid(self):
).can_extend_permit,
)

@override_settings(PERMIT_EXTENSIONS_ENABLED=True)
def test_can_extend_permit_open_ended(self):
self.assertFalse(
ParkingPermitFactory(
Expand All @@ -890,6 +892,7 @@ def test_can_extend_permit_open_ended(self):
).can_extend_permit,
)

@override_settings(PERMIT_EXTENSIONS_ENABLED=True)
def test_can_extend_permit_end_date_none(self):
self.assertFalse(
ParkingPermitFactory(
Expand All @@ -899,6 +902,7 @@ def test_can_extend_permit_end_date_none(self):
).can_extend_permit,
)

@override_settings(PERMIT_EXTENSIONS_ENABLED=True)
def test_can_extend_permit_end_date_too_late(self):
self.assertFalse(
ParkingPermitFactory(
Expand All @@ -908,6 +912,7 @@ def test_can_extend_permit_end_date_too_late(self):
).can_extend_permit,
)

@override_settings(PERMIT_EXTENSIONS_ENABLED=True)
def test_can_extend_permit_existing_pending_request(self):
permit = ParkingPermitFactory(
status=ParkingPermitStatus.VALID,
Expand All @@ -918,6 +923,17 @@ def test_can_extend_permit_existing_pending_request(self):

self.assertFalse(permit.can_extend_permit)

@override_settings(PERMIT_EXTENSIONS_ENABLED=False)
def test_can_extend_permit_feature_disabled(self):
self.assertFalse(
ParkingPermitFactory(
status=ParkingPermitStatus.VALID,
contract_type=ContractType.FIXED_PERIOD,
end_time=timezone.now() + timedelta(days=9),
).can_extend_permit,
)

@override_settings(PERMIT_EXTENSIONS_ENABLED=True)
def test_can_extend_permit_no_other_requests(self):
self.assertTrue(
ParkingPermitFactory(
Expand All @@ -927,6 +943,7 @@ def test_can_extend_permit_no_other_requests(self):
).can_extend_permit,
)

@override_settings(PERMIT_EXTENSIONS_ENABLED=True)
def test_can_extend_permit_existing_other_request(self):
permit = ParkingPermitFactory(
status=ParkingPermitStatus.VALID,
Expand All @@ -939,6 +956,7 @@ def test_can_extend_permit_existing_other_request(self):

self.assertTrue(permit.can_extend_permit)

@override_settings(PERMIT_EXTENSIONS_ENABLED=True)
def test_extend_permit(self):
now = timezone.now()
permit = ParkingPermitFactory(
Expand Down
2 changes: 2 additions & 0 deletions parking_permits/tests/test_customer_permit.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def test_second_permit_can_not_have_permit_more_then_primary_if_primary_is_fixed


class ExtendCustomerPermitTestCase(TestCase):
@override_settings(PERMIT_EXTENSIONS_ENABLED=True)
def test_ok(self):
now = tz.now()
permit = ParkingPermitFactory(
Expand All @@ -483,6 +484,7 @@ def test_ok(self):
ext_request = permit.get_pending_extension_requests().first()
self.assertEqual(ext_request.month_count, 3)

@override_settings(PERMIT_EXTENSIONS_ENABLED=True)
def test_invalid(self):
now = tz.now()
permit = ParkingPermitFactory(
Expand Down
2 changes: 2 additions & 0 deletions parking_permits/tests/test_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import timedelta

import pytest
from django.test import override_settings
from django.utils import timezone

from parking_permits.exceptions import PermitCanNotBeExtended
Expand Down Expand Up @@ -416,6 +417,7 @@ def test_resolve_get_extended_permit_price_list(rf):


@pytest.mark.django_db()
@override_settings(PERMIT_EXTENSIONS_ENABLED=True)
def test_resolve_extend_parking_permit_ok(rf):
request = rf.post("/")
customer = CustomerFactory()
Expand Down
4 changes: 4 additions & 0 deletions project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
PARKKIHUBI_TOKEN=(str, ""),
PARKKIHUBI_OPERATOR_ENDPOINT=(str, ""),
DEBUG_SKIP_PARKKIHUBI_SYNC=(bool, False),
PERMIT_EXTENSIONS_ENABLED=(bool, False),
TRAFICOM_MOCK=(bool, False),
TRAFICOM_ENDPOINT=(str, ""),
TRAFICOM_USERNAME=(str, ""),
Expand Down Expand Up @@ -222,6 +223,9 @@
TRAFICOM_CHECK = env("TRAFICOM_CHECK")
HELSINKI_ADDRESS_CHECK = env("HELSINKI_ADDRESS_CHECK")

# PARKING PERMIT EXTENSIONS
PERMIT_EXTENSIONS_ENABLED = env("PERMIT_EXTENSIONS_ENABLED")

# CORS
CORS_ALLOWED_ORIGINS = env("CORS_ALLOWED_ORIGINS")
CORS_ALLOW_HEADERS = list(default_headers) + [
Expand Down

0 comments on commit c0b1a26

Please sign in to comment.