Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/enforcement api check parking add details parameter #26

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
Set time_start and operator to None if parking not allowed
  • Loading branch information
juuso-j committed Oct 22, 2024
commit 1f224e53e13775ba2784eb5d7f803d00d72c2b6a
7 changes: 4 additions & 3 deletions parkings/api/enforcement/check_parking.py
Original file line number Diff line number Diff line change
@@ -99,10 +99,10 @@ def post(self, request):
operator_detail, time_start_detail, permissions_detail = get_details(params)

if operator_detail:
result["operator"] = parking.operator.name if parking and parking.operator else None
result["operator"] = parking.operator.name if allowed and parking and parking.operator else None

if time_start_detail:
result["time_start"] = parking.time_start if parking and parking.time_start else None
result["time_start"] = parking.time_start if allowed and parking and parking.time_start else None

if permissions_detail:
if isinstance(parking, EventParking):
@@ -225,8 +225,9 @@ def check_parking(registration_number, zone, area, time, domain, event_area):

for parking in active_parkings:
if parking.zone.number > zone:
return (None, parking, parking.time_end, permit_lookup_item_qs)
return (None, parking, None, permit_lookup_item_qs)

# move up
active_event_parking = (
EventParking.objects
.registration_number_like(registration_number)
15 changes: 8 additions & 7 deletions parkings/tests/api/enforcement/test_check_parking.py
Original file line number Diff line number Diff line change
@@ -157,8 +157,8 @@ def test_check_event_parking_parked_in_wrong_event_area_include_details(
event_area_2 = event_area_factory.create(geom=create_area_geom(geom=GEOM_2), domain=enforcer.enforced_domain)
# Parked inside event_area_2, i.e., inside GEOM_2, but event_area_1 is assigned
location = Point(PARKING_DATA_2["location"]["longitude"], PARKING_DATA_2["location"]["latitude"], srid=WGS84_SRID)
event_parking = event_parking_factory(registration_number="ABC-123",
domain=enforcer.enforced_domain, event_area=event_area_1, location=location)
event_parking_factory(registration_number="ABC-123", domain=enforcer.enforced_domain,
event_area=event_area_1, location=location)
data = deepcopy(PARKING_DATA_2)
data["details"] = ["operator", "time_start", "permissions"]
response = enforcer_api_client.post(list_url, data=data)
@@ -169,8 +169,8 @@ def test_check_event_parking_parked_in_wrong_event_area_include_details(
assert response.data["end_time"] is None
assert response.data["permissions"]["event_area"] == event_area_1.origin_id
assert response.data["permissions"]["zone"] is None
assert response.data["operator"] == event_parking.operator.name
assert response.data["time_start"] == event_parking.time_start
assert response.data["operator"] is None
assert response.data["time_start"] is None
assert ParkingCheck.objects.filter(
registration_number=PARKING_DATA["registration_number"]).first().result["allowed"] is False

@@ -287,10 +287,10 @@ def test_check_parking_details_invalid_zone(operator, enforcer, enforcer_api_cli

assert response.status_code == HTTP_200_OK
assert response.data["allowed"] is False
assert response.data["end_time"] == parking.time_end
assert response.data["end_time"] is None
assert response.data["permissions"]["zone"] == parking.zone.number
assert response.data["operator"] == operator.name
assert response.data["time_start"] == parking.time_start
assert response.data["operator"] is None
assert response.data["time_start"] is None


def test_check_parking_invalid_time_parking(operator, enforcer, enforcer_api_client, history_parking_factory):
@@ -379,6 +379,7 @@ def test_check_parking_valid_parking_with_permit_details(enforcer_api_client, pa
assert len(response.data["permissions"]["permits"]) == 1
assert response.data["permissions"]["permits"][0]["subjects"] == permit_1.subjects
assert response.data["permissions"]["permits"][0]["areas"] == permit_1.areas
assert response.data["permissions"]["zone"] == parking.zone.number
assert response.data["time_start"] == parking.time_start
assert response.data["operator"] == parking.operator.name