diff --git a/parking_permits/models/parking_permit.py b/parking_permits/models/parking_permit.py index 746289c3..4e266d8b 100644 --- a/parking_permits/models/parking_permit.py +++ b/parking_permits/models/parking_permit.py @@ -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 diff --git a/parking_permits/tests/models/test_parking_permit.py b/parking_permits/tests/models/test_parking_permit.py index c4ddc997..0c73cdab 100644 --- a/parking_permits/tests/models/test_parking_permit.py +++ b/parking_permits/tests/models/test_parking_permit.py @@ -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( @@ -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( @@ -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( @@ -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( @@ -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, @@ -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( @@ -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, @@ -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( diff --git a/parking_permits/tests/test_customer_permit.py b/parking_permits/tests/test_customer_permit.py index 2282f3f9..f680858b 100644 --- a/parking_permits/tests/test_customer_permit.py +++ b/parking_permits/tests/test_customer_permit.py @@ -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( @@ -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( diff --git a/parking_permits/tests/test_resolvers.py b/parking_permits/tests/test_resolvers.py index d61581f8..3b8c8759 100644 --- a/parking_permits/tests/test_resolvers.py +++ b/parking_permits/tests/test_resolvers.py @@ -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 @@ -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() diff --git a/project/settings.py b/project/settings.py index 482b1e62..4e1b3f84 100644 --- a/project/settings.py +++ b/project/settings.py @@ -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, ""), @@ -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) + [