Skip to content

Commit

Permalink
Handle pk when it's not an integer
Browse files Browse the repository at this point in the history
This format uses the new url processor
feature available in Django 4.2
https://docs.djangoproject.com/en/4.2/topics/http/urls/#example
  • Loading branch information
VirginiaDooley committed Jul 4, 2023
1 parent 97151e9 commit 399dd01
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions wcivf/apps/people/tests/test_person_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,13 @@ def test_local_party_for_non_local_election(self):
expected = f"{self.person.name} is a {local_party.label} candidate."
self.assertContains(response, expected)

def test_person_detail_404_with_string_pk(self):
"""
Regression test to ensure non-int person IDs raise a 404 not a 500
"""
req = self.client.get("/person/partywebsite.org/")
self.assertEqual(req.status_code, 404)


class TestPersonViewUnitTests:
@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions wcivf/apps/people/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
EmailPersonView.as_view(),
name="email_person_view",
),
re_path(
r"^(?P<pk>[^/]+)/(?P<ignored_slug>.*)$",
path(
"<int:pk>/<slug:ignored_slug>",
PersonView.as_view(),
name="person_view",
),
Expand Down

0 comments on commit 399dd01

Please sign in to comment.