From dbe54f075e7a931a235f226ca738fc426c311600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sun, 5 Jan 2020 15:31:11 +0100 Subject: [PATCH] More robust tests for the propositions list view Creating some data to populate the page revealed some bug in the template while refactoring the Reponses/Answer model in the previous commit. --- propositions/tests.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/propositions/tests.py b/propositions/tests.py index fb477f7..aa96060 100644 --- a/propositions/tests.py +++ b/propositions/tests.py @@ -3,7 +3,7 @@ from django.test import Client, TestCase from django.urls import reverse_lazy, reverse from gestion.models import ErnestoUser -from propositions.models import Prop +from propositions.models import Answer, Prop User = get_user_model() @@ -51,14 +51,22 @@ class PropositionCreateTest(TestCase): class PropositionListTest(TestCase): url = reverse_lazy("propositions:list") + def setUp(self): + self.user = new_user("toto") + for name in ["foo", "bar", "baz"]: + p = Prop.objects.create(nom=name, user=self.user.profile) + Answer.objects.create(proposition=p, user=self.user, answer=Answer.YES) + for name in ["oof", "rab", "zab"]: + p = Prop.objects.create(nom=name, user=self.user.profile) + Answer.objects.create(proposition=p, user=self.user, answer=Answer.NO) + def test_anonymous_get(self): response = Client().get(self.url) self.assertRedirects(response, "/login?next={}".format(self.url)) def test_get(self): - user = new_user("toto") client = Client() - client.force_login(user) + client.force_login(self.user) response = client.get(self.url) self.assertEqual(response.status_code, 200)