diff --git a/opentech/apply/funds/tests/test_views.py b/opentech/apply/funds/tests/test_views.py index 2b1cc1c3bb748f1be73dc47e1dda271fb2b0f6ed..f0209aa6a70bfbed444fb0b919e88c4531a27d11 100644 --- a/opentech/apply/funds/tests/test_views.py +++ b/opentech/apply/funds/tests/test_views.py @@ -556,7 +556,10 @@ class ByRoundTestCase(BaseViewTestCase): base_view_name = 'by_round' def get_kwargs(self, instance): - return {'pk': instance.id} + try: + return {'pk': instance.id} + except AttributeError: + return {'pk': instance['id']} class TestStaffSubmissionByRound(ByRoundTestCase): @@ -578,6 +581,10 @@ class TestStaffSubmissionByRound(ByRoundTestCase): response = self.get_page(page) self.assertEqual(response.status_code, 404) + def test_cant_access_non_existing_page(self): + response = self.get_page({'id': 555}) + self.assertEqual(response.status_code, 404) + class TestApplicantSubmissionByRound(ByRoundTestCase): user_factory = UserFactory @@ -597,3 +604,7 @@ class TestApplicantSubmissionByRound(ByRoundTestCase): page = new_round.get_site().root_page response = self.get_page(page) self.assertEqual(response.status_code, 403) + + def test_cant_access_non_existing_page(self): + response = self.get_page({'id': 555}) + self.assertEqual(response.status_code, 403) diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py index 043ae8c9fc573a9bc86984a39938fd9571cac2e2..15f46128b7632b1977f458d5df2503722e7650b6 100644 --- a/opentech/apply/funds/views.py +++ b/opentech/apply/funds/views.py @@ -76,8 +76,11 @@ class SubmissionsByRound(BaseAdminSubmissionsTable): def get_queryset(self): # We want to only show lab or Rounds in this view, their base class is Page - self.obj = Page.objects.get(pk=self.kwargs.get('pk')) - self.obj = self.obj.specific + try: + self.obj = Page.objects.get(pk=self.kwargs.get('pk')).specific + except Page.DoesNotExist: + raise Http404(_("No Round or Lab found matching the query")) + if not isinstance(self.obj, (LabBase, RoundBase)): raise Http404(_("No Round or Lab found matching the query")) return super().get_queryset().filter(Q(round=self.obj) | Q(page=self.obj))