Skip to content

Commit

Permalink
Add test for accepting membership requests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabeweng committed Nov 8, 2024
1 parent cf89829 commit 038a1bb
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions backend/tests/clubs/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3827,3 +3827,68 @@ def test_membershiprequests_withdraw(self):
)
self.assertEqual(resp.status_code, 200, resp.content)
self.assertEqual(len(resp.json()), 1, resp.content)

def test_membershiprequests_accept(self):
"""
Test the membership requests accept feature
"""

Membership.objects.create(
person=self.user1, club=self.club1, role=Membership.ROLE_OWNER
)

self.client.login(username=self.user2.username, password="test")
resp = self.client.post(
reverse("membership-requests-list"),
{"club": self.club1.code},
content_type="application/json",
)
self.assertEqual(resp.status_code, 201, resp.content)
self.assertEqual(
MembershipRequest.objects.filter(
club=self.club1, requester=self.user2
).count(),
1,
)
self.assertEqual(len(mail.outbox), 1, mail.outbox)

# Requester cannot accept membership requests
resp = self.client.post(
reverse(
"club-membership-requests-accept",
kwargs={
"club_code": self.club1.code,
"requester__username": self.user2.username,
},
)
)
self.assertEqual(resp.status_code, 403, resp.content)

# Owner can accept membership requests
self.client.login(username=self.user1.username, password="test")

resp = self.client.post(
reverse(
"club-membership-requests-accept",
kwargs={
"club_code": self.club1.code,
"requester__username": self.user2.username,
},
)
)
self.assertEqual(resp.status_code, 200, resp.content)

self.assertEqual(
MembershipRequest.objects.filter(
club=self.club1, requester=self.user2
).count(),
0,
)

self.assertEqual(
Membership.objects.filter(
club=self.club1,
person=self.user2,
).count(),
1,
)

0 comments on commit 038a1bb

Please sign in to comment.