From 11159601075680efe2bd30d61fdebbc26c9b26c6 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 27 Nov 2019 16:57:48 +0100 Subject: [PATCH] Add unit test --- kfet/tests/test_views.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/kfet/tests/test_views.py b/kfet/tests/test_views.py index 82997e44..34127cb5 100644 --- a/kfet/tests/test_views.py +++ b/kfet/tests/test_views.py @@ -1726,6 +1726,15 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase): price=Decimal("2.5"), stock=20, ) + # Another Article, price=2.5, stock=20, no COF reduction + self.article_no_reduction = Article.objects.create( + category=ArticleCategory.objects.create( + name="Category_no_reduction", has_reduction=False, + ), + name="Article_no_reduction", + price=Decimal("2.5"), + stock=20, + ) # An Account, trigramme=000, balance=50 # Do not assume user is cof, nor not cof. self.account = self.accounts["user"] @@ -2079,6 +2088,35 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase): self.article.refresh_from_db() self.assertEqual(self.article.stock, 18) + def test_purchase_no_reduction(self): + kfet_config.set(kfet_reduction_cof=Decimal("20")) + self.account.cofprofile.is_cof = True + self.account.cofprofile.save() + data = dict( + self.base_post_data, + **{ + "form-TOTAL_FORMS": "2", + "form-0-type": "purchase", + "form-0-amount": "", + "form-0-article": str(self.article_no_reduction.pk), + "form-0-article_nb": "1", + "form-1-type": "purchase", + "form-1-amount": "", + "form-1-article": str(self.article.pk), + "form-1-article_nb": "1", + } + ) + + resp = self.client.post(self.url, data) + self._assertResponseOk(resp) + + operation_group = OperationGroup.objects.get() + self.assertEqual(operation_group.amount, Decimal("-4.50")) + operation = Operation.objects.get(article=self.article) + self.assertEqual(operation.amount, Decimal("-2.00")) + operation = Operation.objects.get(article=self.article_no_reduction) + self.assertEqual(operation.amount, Decimal("-2.50")) + def test_invalid_purchase_expects_article(self): data = dict( self.base_post_data,