This commit is contained in:
Ludovic Stephan 2020-09-11 15:22:07 +02:00 committed by Martin Pépin
parent f3701d91fc
commit 521be6db85
No known key found for this signature in database
GPG key ID: E7520278B1774448

View file

@ -4579,6 +4579,87 @@ class InventoryReadViewTests(ViewTestCaseMixin, TestCase):
self.assertEqual(r.status_code, 200)
class InventoryDeleteViewTests(ViewTestCaseMixin, TestCase):
url_name = "kfet.inventory.delete"
auth_user = "team1"
auth_forbidden = [None, "user", "team"]
def get_users_extra(self):
return {
"user1": create_user("user1", "001"),
"team1": create_team("team1", "101", perms=["kfet.delete_inventory"]),
}
@property
def url_kwargs(self):
return {"pk": self.inventory1.pk}
@property
def url_expected(self):
return "/k-fet/inventaires/{}/delete".format(self.inventory1.pk)
def setUp(self):
super().setUp()
# Deux inventaires : un avec article 1 + 2, l'autre avec 1 + 3
self.inventory1 = Inventory.objects.create(
by=self.accounts["team"], at=self.now
)
self.inventory2 = Inventory.objects.create(
by=self.accounts["team"], at=self.now + timedelta(days=1)
)
category = ArticleCategory.objects.create(name="Category")
# Le stock des articles correspond à leur dernier inventaire
self.article1 = Article.objects.create(
name="Article1", category=category, stock=51
)
self.article2 = Article.objects.create(
name="Article2", category=category, stock=42
)
self.article3 = Article.objects.create(
name="Article3", category=category, stock=42
)
InventoryArticle.objects.create(
inventory=self.inventory1,
article=self.article1,
stock_old=23,
stock_new=42,
)
InventoryArticle.objects.create(
inventory=self.inventory1,
article=self.article2,
stock_old=23,
stock_new=42,
)
InventoryArticle.objects.create(
inventory=self.inventory2,
article=self.article1,
stock_old=42,
stock_new=51,
)
InventoryArticle.objects.create(
inventory=self.inventory2,
article=self.article3,
stock_old=23,
stock_new=42,
)
def test_ok(self):
r = self.client.post(self.url)
self.assertRedirects(r, reverse("kfet.inventory"))
# On vérifie que l'inventaire n'existe plus
self.assertFalse(Inventory.objects.filter(pk=self.inventory1.pk).exists())
# On check les stocks
self.article1.refresh_from_db()
self.article2.refresh_from_db()
self.article3.refresh_from_db()
self.assertEqual(self.article1.stock, 51)
self.assertEqual(self.article2.stock, 23)
self.assertEqual(self.article3.stock, 42)
class OrderListViewTests(ViewTestCaseMixin, TestCase):
url_name = "kfet.order"
url_expected = "/k-fet/orders/"