From c12cc07d724e9ff8cb9f75390179bc9226f9e59b Mon Sep 17 00:00:00 2001 From: chapeau Date: Thu, 29 Feb 2024 11:07:26 +0100 Subject: [PATCH] Fix cotisations/test_views tests --- api/tests.py | 2 +- cotisations/test_views.py | 77 +++++++++++++++++++-------------------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/api/tests.py b/api/tests.py index 04455114..3350a3fe 100644 --- a/api/tests.py +++ b/api/tests.py @@ -670,7 +670,7 @@ class APIEndpointsTestCase(APITestCase): def assert_more(response, url, format): """Assert the response is valid json when format is json""" - if format is "json": + if format == "json": json.loads(response.content.decode()) self.check_responses_code( diff --git a/cotisations/test_views.py b/cotisations/test_views.py index 1d6cbe3d..bf3a3229 100644 --- a/cotisations/test_views.py +++ b/cotisations/test_views.py @@ -12,13 +12,41 @@ from .models import Article, Cotisation, Facture, Paiement, Vente class NewFactureTests(TestCase): + @classmethod + def setUpTestData(cls): + cls.paiement = Paiement.objects.create(moyen="test payment") + cls.article_one_day = Article.objects.create( + name="One day", + prix=0, + duration_connection=0, + duration_days_connection=1, + duration_membership=0, + duration_days_membership=1, + available_for_everyone=True, + ) + cls.article_one_month = Article.objects.create( + name="One mounth", + prix=0, + duration_connection=1, + duration_days_connection=0, + duration_membership=1, + duration_days_membership=0, + available_for_everyone=True, + ) + cls.article_one_month_and_one_week = Article.objects.create( + name="One mounth and one week", + prix=0, + duration_connection=1, + duration_days_connection=7, + duration_membership=1, + duration_days_membership=7, + available_for_everyone=True, + ) + + def tearDown(self): self.user.facture_set.all().delete() self.user.delete() - self.paiement.delete() - self.article_one_day.delete() - self.article_one_month.delete() - self.article_one_month_and_one_week.delete() def setUp(self): self.user = Adherent.objects.create(pseudo="testUser", email="test@example.org") @@ -34,35 +62,6 @@ class NewFactureTests(TestCase): ] ) self.user.save() - - self.paiement = Paiement.objects.create(moyen="test payment") - self.article_one_day = Article.objects.create( - name="One day", - prix=0, - duration_connection=0, - duration_days_connection=1, - duration_membership=0, - duration_days_membership=1, - available_for_everyone=True, - ) - self.article_one_month = Article.objects.create( - name="One mounth", - prix=0, - duration_connection=1, - duration_days_connection=0, - duration_membership=1, - duration_days_membership=0, - available_for_everyone=True, - ) - self.article_one_month_and_one_week = Article.objects.create( - name="One mounth and one week", - prix=0, - duration_connection=1, - duration_days_connection=7, - duration_membership=1, - duration_days_membership=7, - available_for_everyone=True, - ) self.client.login(username="testUser", password="plopiplop") def test_invoice_with_one_day(self): @@ -72,7 +71,7 @@ class NewFactureTests(TestCase): "form-INITIAL_FORMS": 0, "form-MIN_NUM_FORMS": 0, "form-MAX_NUM_FORMS": 1000, - "form-0-article": 1, + "form-0-article": self.article_one_day.pk, "form-0-quantity": 1, } date = timezone.now() @@ -94,7 +93,7 @@ class NewFactureTests(TestCase): "form-INITIAL_FORMS": 0, "form-MIN_NUM_FORMS": 0, "form-MAX_NUM_FORMS": 1000, - "form-0-article": 2, + "form-0-article": self.article_one_month.pk, "form-0-quantity": 1, } date = timezone.now() @@ -114,9 +113,9 @@ class NewFactureTests(TestCase): "form-INITIAL_FORMS": 0, "form-MIN_NUM_FORMS": 0, "form-MAX_NUM_FORMS": 1000, - "form-0-article": 1, + "form-0-article": self.article_one_day.pk, "form-0-quantity": 7, - "form-1-article": 2, + "form-1-article": self.article_one_month.pk, "form-1-quantity": 1, } date = timezone.now() @@ -137,9 +136,9 @@ class NewFactureTests(TestCase): "form-INITIAL_FORMS": 0, "form-MIN_NUM_FORMS": 0, "form-MAX_NUM_FORMS": 1000, - "form-0-article": 2, + "form-0-article": self.article_one_month.pk, "form-0-quantity": 1, - "form-1-article": 2, + "form-1-article": self.article_one_month.pk, "form-1-quantity": 1, } response = self.client.post(