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.
This commit is contained in:
Martin Pépin 2020-01-05 15:31:11 +01:00
parent 6ef880339f
commit dbe54f075e
No known key found for this signature in database
GPG key ID: E7520278B1774448

View file

@ -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)