forked from DGNum/gestioCOF
Add unit test
This commit is contained in:
parent
38aecdd741
commit
1115960107
1 changed files with 38 additions and 0 deletions
|
@ -1726,6 +1726,15 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
price=Decimal("2.5"),
|
price=Decimal("2.5"),
|
||||||
stock=20,
|
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
|
# An Account, trigramme=000, balance=50
|
||||||
# Do not assume user is cof, nor not cof.
|
# Do not assume user is cof, nor not cof.
|
||||||
self.account = self.accounts["user"]
|
self.account = self.accounts["user"]
|
||||||
|
@ -2079,6 +2088,35 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
|
||||||
self.article.refresh_from_db()
|
self.article.refresh_from_db()
|
||||||
self.assertEqual(self.article.stock, 18)
|
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):
|
def test_invalid_purchase_expects_article(self):
|
||||||
data = dict(
|
data = dict(
|
||||||
self.base_post_data,
|
self.base_post_data,
|
||||||
|
|
Loading…
Reference in a new issue