From 491b5df42df82a7a8e79d7bcee628953bd129580 Mon Sep 17 00:00:00 2001 From: Julian Weng Date: Fri, 29 Nov 2024 18:10:16 -0500 Subject: [PATCH] Add test coverage for changes --- backend/tests/clubs/test_ticketing.py | 101 ++++++++++++++++++++++++++ backend/tests/clubs/test_views.py | 8 ++ 2 files changed, 109 insertions(+) diff --git a/backend/tests/clubs/test_ticketing.py b/backend/tests/clubs/test_ticketing.py index 128b12890..323b14016 100644 --- a/backend/tests/clubs/test_ticketing.py +++ b/backend/tests/clubs/test_ticketing.py @@ -51,6 +51,14 @@ def commonSetUp(self): email="example@example.com", ) + self.unapproved_club = Club.objects.create( + code="unapproved-club", + name="Unapproved Club", + approved=False, + ghost=False, + email="example2@example.com", + ) + self.event1 = Event.objects.create( code="test-event", club=self.club1, @@ -59,6 +67,14 @@ def commonSetUp(self): end_time=timezone.now() + timezone.timedelta(days=3), ) + self.unapproved_event = Event.objects.create( + code="unapproved-event", + club=self.unapproved_club, + name="Unapproved Event", + start_time=timezone.now() + timezone.timedelta(days=2), + end_time=timezone.now() + timezone.timedelta(days=3), + ) + self.ticket_totals = [ {"type": "normal", "count": 20, "price": 15.0}, {"type": "premium", "count": 10, "price": 30.0}, @@ -73,6 +89,11 @@ def commonSetUp(self): for _ in range(10) ] + self.unapproved_tickets = [ + Ticket.objects.create(type="normal", event=self.unapproved_event, price=15.0) + for _ in range(20) + ] + class TicketEventTestCase(TestCase): """ @@ -87,6 +108,30 @@ def setUp(self): def test_create_ticket_offerings(self): self.client.login(username=self.user1.username, password="test") + + # Test invalid start_time, ticket_drop_time editing + resp = self.client.patch( + reverse("club-events-detail", args=(self.club1.code, self.event1.pk)), + { + "ticket_drop_time": ( + self.event1.end_time + timezone.timedelta(days=20) + ).strftime("%Y-%m-%dT%H:%M:%S%z") + }, + format="json", + ) + self.assertEqual(resp.status_code, 400, resp.content) + + resp = self.client.patch( + reverse("club-events-detail", args=(self.club1.code, self.event1.pk)), + { + "start_time": ( + self.event1.end_time + timezone.timedelta(days=20) + ).strftime("%Y-%m-%dT%H:%M:%S%z") + }, + format="json", + ) + self.assertEqual(resp.status_code, 400, resp.content) + qts = { "quantities": [ {"type": "_normal", "count": 20, "price": 10}, @@ -277,6 +322,18 @@ def test_create_ticket_offerings_already_owned_or_held(self): ) self.assertEqual(resp.status_code, 403, resp.content) + # Changing ticket drop time should fail + resp = self.client.patch( + reverse("club-events-detail", args=(self.club1.code, self.event1.pk)), + { + "ticket_drop_time": ( + timezone.now() + timezone.timedelta(hours=12) + ).strftime("%Y-%m-%dT%H:%M:%S%z") + }, + format="json", + ) + self.assertEqual(resp.status_code, 400, resp.content) + def test_issue_tickets(self): self.client.login(username=self.user1.username, password="test") args = { @@ -590,6 +647,50 @@ def test_add_to_cart_before_ticket_drop(self): # Tickets should not be added to cart before drop time self.assertEqual(resp.status_code, 403, resp.content) + def test_add_to_cart_unapproved_club(self): + self.client.login(username=self.user1.username, password="test") + tickets_to_add = { + "quantities": [ + {"type": "normal", "count": 2}, + ] + } + resp = self.client.post( + reverse( + "club-events-add-to-cart", + args=(self.unapproved_club.code, self.unapproved_event.pk), + ), + tickets_to_add, + format="json", + ) + self.assertEqual(resp.status_code, 403, resp.content) + self.client.login(username=self.user2.username, password="test") + resp = self.client.post( + reverse( + "club-events-add-to-cart", + args=(self.unapproved_club.code, self.unapproved_event.pk), + ), + tickets_to_add, + format="json", + ) + # Cannot see event + self.assertEqual(resp.status_code, 404, resp.content) + + def test_add_to_cart_nonexistent_club(self): + tickets_to_add = { + "quantities": [ + {"type": "normal", "count": 2}, + ] + } + resp = self.client.post( + reverse( + "club-events-add-to-cart", + args=("Random club name", self.unapproved_event.pk), + ), + tickets_to_add, + format="json", + ) + self.assertEqual(resp.status_code, 404, resp.content) + def test_remove_from_cart(self): self.client.login(username=self.user1.username, password="test") diff --git a/backend/tests/clubs/test_views.py b/backend/tests/clubs/test_views.py index b4931d737..65c289292 100644 --- a/backend/tests/clubs/test_views.py +++ b/backend/tests/clubs/test_views.py @@ -227,6 +227,14 @@ def setUp(self): visibility=Advisor.ADVISOR_VISIBILITY_ALL, ) + def test_directory(self): + """ + Test retrieving the club directory. + """ + resp = self.client.get(reverse("clubs-directory")) + self.assertIn(resp.status_code, [200, 201], resp.content) + self.assertEqual(len(resp.data), 1) + def test_advisor_visibility(self): """ Tests each tier of advisor visibility.