diff --git a/bda/tests/test_views.py b/bda/tests/test_views.py index 3dc1b4d1..1d4494cb 100644 --- a/bda/tests/test_views.py +++ b/bda/tests/test_views.py @@ -4,8 +4,9 @@ from datetime import timedelta from django.test import TestCase from django.utils import formats, timezone -from ..models import Participant +from ..models import CategorieSpectacle, Participant, Salle from .testcases import BdATestHelpers, BdAViewTestCaseMixin +from .utils import create_spectacle class InscriptionViewTestCase(BdATestHelpers, BdAViewTestCaseMixin, TestCase): @@ -280,6 +281,60 @@ class SendRemindersViewTestCase(BdATestHelpers, BdAViewTestCaseMixin, TestCase): # TODO: check that emails are sent +class DescriptionsSpectaclesViewTestCase( + BdATestHelpers, BdAViewTestCaseMixin, TestCase +): + url_name = "bda-descriptions" + + auth_user = None + auth_forbidden = [] + + bda_testdata = True + + @property + def url_kwargs(self): + return {"tirage_id": self.tirage.pk} + + @property + def url_expected(self): + return "/bda/descriptions/{}".format(self.tirage.pk) + + def test_get(self): + resp = self.client.get(self.url) + self.assertEqual(resp.status_code, 200) + self.assertListEqual( + list(resp.context["shows"]), [self.show1, self.show2, self.show3] + ) + + def test_get_filter_category(self): + category1 = CategorieSpectacle.objects.create(name="Category 1") + category2 = CategorieSpectacle.objects.create(name="Category 2") + show1 = create_spectacle(category=category1, tirage=self.tirage) + show2 = create_spectacle(category=category2, tirage=self.tirage) + + resp = self.client.get(self.url, {"category": "Category 1"}) + self.assertEqual(resp.status_code, 200) + self.assertListEqual(list(resp.context["shows"]), [show1]) + + resp = self.client.get(self.url, {"category": "Category 2"}) + self.assertEqual(resp.status_code, 200) + self.assertListEqual(list(resp.context["shows"]), [show2]) + + def test_get_filter_location(self): + location1 = Salle.objects.create(name="Location 1") + location2 = Salle.objects.create(name="Location 2") + show1 = create_spectacle(location=location1, tirage=self.tirage) + show2 = create_spectacle(location=location2, tirage=self.tirage) + + resp = self.client.get(self.url, {"location": str(location1.pk)}) + self.assertEqual(resp.status_code, 200) + self.assertListEqual(list(resp.context["shows"]), [show1]) + + resp = self.client.get(self.url, {"location": str(location2.pk)}) + self.assertEqual(resp.status_code, 200) + self.assertListEqual(list(resp.context["shows"]), [show2]) + + class CatalogueViewTestCase(BdATestHelpers, BdAViewTestCaseMixin, TestCase): auth_user = None auth_forbidden = []