Skip to content

Commit

Permalink
Merge pull request #574 from praekeltfoundation/MOMZA-2371-track-what…
Browse files Browse the repository at this point in the history
…sapp-send-failures

Fix deliveryfailure get not found
  • Loading branch information
erikh360 authored Jul 5, 2023
2 parents 505f121 + 7f1d831 commit 0f78d27
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions eventstore/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3019,6 +3019,19 @@ def test_get_deliveryfailure_by_msisdn(self):
},
)

def test_get_deliveryfailure_by_msisdn_not_found(self):
"""
Should return 404 if there is no DeliveryFailure object found
"""
user = get_user_model().objects.create_user("test")
user.user_permissions.add(
Permission.objects.get(codename="view_deliveryfailure")
)
self.client.force_authenticate(user)

response = self.client.get(self.url)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

def test_deliveryfailure_data_validation(self):
"""
The supplied data must be validated, and any errors returned
Expand Down
5 changes: 3 additions & 2 deletions eventstore/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,9 @@ class DeliveryFailureViewSet(GenericViewSet, CreateModelMixin, RetrieveModelMixi
pagination_class = CursorPaginationFactory("timestamp")

def get_object(self):
obj = DeliveryFailure.objects.get(contact_id=self.kwargs["pk"])
if not obj.pk:
try:
obj = DeliveryFailure.objects.get(contact_id=self.kwargs["pk"])
except DeliveryFailure.DoesNotExist:
raise Http404()
self.check_object_permissions(self.request, obj)
return obj
Expand Down

0 comments on commit 0f78d27

Please sign in to comment.