def destroy(self, request, pk=None, listing_pk=None): queryset = self.get_queryset() review = get_object_or_404(queryset, pk=pk) try: model_access.delete_listing_review(request.user.username, review) except errors.PermissionDenied: return Response('Cannot update another user\'s review', status=status.HTTP_403_FORBIDDEN) return Response(status=status.HTTP_204_NO_CONTENT)
def test_delete_listing_review(self): username = '******' air_mail = models.Listing.objects.for_user(username).get(title='Air Mail') review = models.Review.objects.get(listing=air_mail, author__user__username=username) model_access.delete_listing_review(username, review) air_mail = models.Listing.objects.for_user(username).get(title='Air Mail') self.assertEqual(air_mail.last_activity.action, models.ListingActivity.REVIEW_DELETED) listing_activities = air_mail.listing_activities.filter(action=models.ListingActivity.REVIEW_DELETED) enabled_activity = listing_activities[0] self.assertEqual(enabled_activity.author.user.username, username)
def destroy(self, request, pk=None, listing_pk=None): queryset = self.get_queryset() review = get_object_or_404(queryset, pk=pk) model_access.delete_listing_review(request.user.username, review) return Response(status=status.HTTP_204_NO_CONTENT)