def test_delete_location_with_inventory(self): location = Location(name="Test Location", organization=self.organization) location.save() self.assertEqual(Location.objects.count(), 1) product = Product(name="Test Product", organization=self.organization) product.save() self.assertEqual(Product.objects.count(), 1) inventory = Inventory( location=location, product=product, organization=self.organization ) inventory.amount = 1.0 inventory.save() self.assertEqual(inventory.amount, 1.0) # Deleting it should fail since we have inventory with pytest.raises(Exception) as deletion_error: location.delete() self.assertEqual( str(deletion_error.value), "We cannot delete a location if it still has inventory.", ) # Removing inventory should make the location deletable inventory.add(-1) location.delete() self.assertEqual(Location.objects.count(), 0)
def test_delete_location(self): location = Location(name="Test Location", organization=self.organization) location.save() self.assertEqual(Location.objects.count(), 1) location.delete() self.assertEqual(Location.objects.count(), 0)