def test_delete_listing(self): username = '******' air_mail = models.Listing.objects.for_user(username).get( title='Air Mail') model_access.delete_listing(username, air_mail) self.assertEquals(0, models.Listing.objects.for_user(username).filter( title='Air Mail').count())
def destroy(self, request, pk=None): """ Delete a listing """ queryset = self.get_queryset() listing = get_object_or_404(queryset, pk=pk) model_access.delete_listing(request.user.username, listing) return Response(status=status.HTTP_204_NO_CONTENT)
def destroy(self, request, pk=None): """ Delete a listing """ queryset = self.get_queryset() listing = get_object_or_404(queryset, pk=pk) try: model_access.delete_listing(request.user.username, listing) except errors.PermissionDenied as e: return Response({'detail': 'Permission Denied', 'reason': str(e)}, status=status.HTTP_403_FORBIDDEN) return Response(status=status.HTTP_204_NO_CONTENT)
def test_delete_listing(self): username = '******' air_mail = models.Listing.objects.for_user(username).get( title='Air Mail') model_access.delete_listing(username, air_mail) self.assertEquals( 1, models.Listing.objects.for_user(username).filter( title='Air Mail').count()) self.assertTrue( models.Listing.objects.for_user(username).filter( title='Air Mail').first().is_deleted)
def destroy(self, request, pk=None): """ Delete a listing """ queryset = self.get_queryset() listing = get_object_or_404(queryset, pk=pk) description = request.data['description'] if 'description' in request.data else None if not description: raise errors.InvalidInput('Description is required when deleting a listing') model_access.delete_listing(request.user.username, listing, description) return Response(status=status.HTTP_204_NO_CONTENT)
def test_delete_listing(self): username = '******' air_mail = models.Listing.objects.for_user(username).get(title='Air Mail') description = 'this app has been deleted' model_access.delete_listing(username, air_mail, description) self.assertEqual(1, models.Listing.objects.for_user(username).filter(title='Air Mail').count()) self.assertTrue(models.Listing.objects.for_user(username).filter(title='Air Mail').first().is_deleted) listing_activities = air_mail.listing_activities.filter(action=models.ListingActivity.DELETED) deleted_activity = listing_activities[0] self.assertEqual(deleted_activity.author.user.username, username) self.assertEqual(deleted_activity.description, description)
def destroy(self, request, pk=None): """ Delete a listing """ queryset = self.get_queryset() listing = get_object_or_404(queryset, pk=pk) description = request.data[ 'description'] if 'description' in request.data else None if not description: raise errors.InvalidInput( 'Description is required when deleting a listing') model_access.delete_listing(request.user.username, listing, description) return Response(status=status.HTTP_204_NO_CONTENT)