Skip to content

Commit

Permalink
Add test coverage for changes
Browse files Browse the repository at this point in the history
  • Loading branch information
julianweng committed Nov 29, 2024
1 parent a660ea7 commit 491b5df
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
101 changes: 101 additions & 0 deletions backend/tests/clubs/test_ticketing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def commonSetUp(self):
email="[email protected]",
)

self.unapproved_club = Club.objects.create(
code="unapproved-club",
name="Unapproved Club",
approved=False,
ghost=False,
email="[email protected]",
)

self.event1 = Event.objects.create(
code="test-event",
club=self.club1,
Expand All @@ -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},
Expand All @@ -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):
"""
Expand All @@ -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},
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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")

Expand Down
8 changes: 8 additions & 0 deletions backend/tests/clubs/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 491b5df

Please sign in to comment.