Skip to content

Commit

Permalink
Add test for destroying membership requests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabeweng committed Nov 8, 2024
1 parent 038a1bb commit 826f54c
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 @@ -3892,3 +3892,68 @@ def test_membershiprequests_accept(self):
).count(),
1,
)

def test_membershiprequests_destroy(self):
"""
Test the membership requests destroy (denial of request) 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 destroy membership requests
resp = self.client.delete(
reverse(
"club-membership-requests-detail",
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.delete(
reverse(
"club-membership-requests-detail",
kwargs={
"club_code": self.club1.code,
"requester__username": self.user2.username,
},
)
)
self.assertIn(resp.status_code, [200, 204], 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(),
0,
)

0 comments on commit 826f54c

Please sign in to comment.