From ba6599fa5691034749831e11e651f36edcab0511 Mon Sep 17 00:00:00 2001 From: lsacienne Date: Thu, 5 May 2022 23:24:08 +0200 Subject: [PATCH] Add of tests --- core/management/commands/populate.py | 2 ++ counter/tests.py | 48 ++++++++++++++++++++++++++++ doc/devenv/populate.rst | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index 06c5d3f3..0c661b1d 100644 --- a/core/management/commands/populate.py +++ b/core/management/commands/populate.py @@ -611,6 +611,7 @@ Welcome to the wiki page! mde.products.add(cons) mde.products.add(dcons) mde.sellers.add(skia) + mde.save() eboutic = Counter.objects.filter(name="Eboutic").first() @@ -935,6 +936,7 @@ Welcome to the wiki page! # Add barman to counter c = Counter.objects.get(id=2) c.sellers.add(User.objects.get(pk=krophil.pk)) + mde.sellers.add(sli) c.save() # Create an election diff --git a/counter/tests.py b/counter/tests.py index c0a9b40e..70f75b06 100644 --- a/counter/tests.py +++ b/counter/tests.py @@ -36,7 +36,10 @@ class CounterTest(TestCase): def setUp(self): call_command("populate") self.skia = User.objects.filter(username="skia").first() + self.sli = User.objects.filter(username="sli").first() + self.krophil = User.objects.filter(username="krophil").first() self.mde = Counter.objects.filter(name="MDE").first() + self.foyer = Counter.objects.get(id=2) def test_full_click(self): response = self.client.post( @@ -93,6 +96,51 @@ class CounterTest(TestCase): in str(response_content) ) + response = self.client.post( + reverse("counter:login", kwargs={"counter_id": self.mde.id}), + {"username": self.sli.username, "password": "plop"}, + ) + + response = self.client.post( + location, + { + "action": "refill", + "amount": "5", + "payment_method": "CASH", + "bank": "OTHER", + }, + ) + + response = self.client.post( + reverse("counter:login", kwargs={"counter_id": self.foyer.id}), + {"username": self.krophil.username, "password": "plop"}, + ) + + response = self.client.get( + reverse("counter:details", kwargs={"counter_id": self.foyer.id}) + ) + + counter_token = re.search( + r'name="counter_token" value="([^"]*)"', str(response.content) + ).group(1) + + response = self.client.post( + reverse("counter:details", kwargs={"counter_id": self.foyer.id}), + {"code": "4000k", "counter_token": counter_token}, + ) + location = response.get("location") + + response = self.client.post( + location, + { + "action": "refill", + "amount": "5", + "payment_method": "CASH", + "bank": "OTHER", + }, + ) + self.assertTrue(response.status_code == 403) + class CounterStatsTest(TestCase): def setUp(self): diff --git a/doc/devenv/populate.rst b/doc/devenv/populate.rst index 53ea6de2..1fcd3dbf 100644 --- a/doc/devenv/populate.rst +++ b/doc/devenv/populate.rst @@ -45,7 +45,7 @@ Par défaut, la base de données du site de prod contient des données nécessai * **comptable** -> administrateur comptabilité * **guy** -> utilisateur non cotisant et sans groupe * **rbatsbak** -> utilisateur non cotisant et sans groupe - * **sli** -> cotisant avec carte étudiante attachée au compte + * **sli** -> cotisant avec carte étudiante attachée au compte, barmen MDE * **krophil** -> cotisant avec des plein d'écocups, barmen foyer * **comunity** -> administrateur communication * **tutu** -> administrateur pédagogie