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:
parent
6ef880339f
commit
dbe54f075e
1 changed files with 11 additions and 3 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue