def test_delete_view_can_only_be_called_if_product_is_deletable(self): one_item_listing = ListingFactory(product=self.product) publishing = PublishingFactory(listing=one_item_listing) self.client.login(username=self.user.username, password='******') response = self.client.post(reverse('bazaar:product-delete', kwargs={'pk': self.product.pk})) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) publishing.delete() response = self.client.post(reverse('bazaar:product-delete', kwargs={'pk': self.product.pk})) self.assertEqual(response.status_code, status.HTTP_302_FOUND)
def test_delete_view_let_delete_a_listing_only_if_it_has_not_publishing_associated(self): """ Test that the product has associated publishings """ # By default this operation will create a bound listing x1 of that product self.product = f.ProductFactory(name='product1', price=2, description='the best you can have!') self.listing = self.product.listings.first() publishing = PublishingFactory(listing=self.listing) self.client.login(username=self.user.username, password='******') response = self.client.post(reverse('bazaar:listing-delete', kwargs={'pk': self.listing.pk})) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) publishing.delete() response = self.client.post(reverse('bazaar:listing-delete', kwargs={'pk': self.listing.pk})) self.assertEqual(response.status_code, status.HTTP_302_FOUND) listing_exists = Listing.objects.filter(pk=self.listing.pk).exists() self.assertEqual(listing_exists, False)