-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ValueError in MobilitySerializer
Handle cases where MobilityServiceNode's `service_reference` contains non-integer values. In such cases we otherwise get `ValueError: invalid literal for int() with base 10` and the endpoint breaks.
- Loading branch information
1 parent
b74409e
commit eeeba48
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from datetime import datetime | ||
|
||
import pytest | ||
import pytz | ||
from django.urls import reverse | ||
from rest_framework.test import APIClient | ||
|
||
from services.models import MobilityServiceNode | ||
from services.tests.utils import get | ||
|
||
|
||
@pytest.fixture | ||
def api_client(): | ||
return APIClient() | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_get_mobility_list(api_client): | ||
MobilityServiceNode.objects.create( | ||
id=1, name="Urheilukeskus", last_modified_time=datetime.now(pytz.utc) | ||
) | ||
MobilityServiceNode.objects.create( | ||
id=2, | ||
name="Kenttä", | ||
last_modified_time=datetime.now(pytz.utc), | ||
service_reference="1+2", | ||
) # Test that non-integer values in `service_reference` don't break the endpoint | ||
|
||
response = get(api_client, reverse("mobilityservicenode-list")) | ||
|
||
assert response.status_code == 200 | ||
assert response.data["count"] == 2 |