Skip to content

Commit

Permalink
Create test for destroy feature of OwnershipRequests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabeweng committed Nov 1, 2024
1 parent 60f0962 commit d5e4b6c
Showing 1 changed file with 179 additions and 0 deletions.
179 changes: 179 additions & 0 deletions backend/tests/clubs/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3508,3 +3508,182 @@ def test_ownershiprequests_accept(self):
).count(),
1,
)

def test_ownershiprequests_destroy(self):
"""
Test the ownership requests destroy (denial of request) feature
"""

Membership.objects.create(
person=self.user1, club=self.club1, role=Membership.ROLE_OWNER
)
Membership.objects.create(
person=self.user2, club=self.club1, role=Membership.ROLE_OFFICER
)
Membership.objects.create(
person=self.user3, club=self.club1, role=Membership.ROLE_MEMBER
)

# Create ownership requests for officer, member, non-member
self.client.login(username=self.user2.username, password="test")
resp = self.client.post(
reverse("ownership-requests-list"),
{"club": self.club1.code},
content_type="application/json",
)
self.assertEqual(resp.status_code, 201, resp.content)
self.assertEqual(
OwnershipRequest.objects.filter(
club=self.club1, requester=self.user2
).count(),
1,
)

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

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

# Officer cannot destroy requests
self.client.login(username=self.user2.username, password="test")
resp = self.client.delete(
reverse(
"club-ownership-requests-detail",
kwargs={
"club_code": self.club1.code,
"requester__username": self.user2.username,
},
)
)
self.assertEqual(resp.status_code, 403, resp.content)

# Member cannot accept requests
self.client.login(username=self.user3.username, password="test")
resp = self.client.delete(
reverse(
"club-ownership-requests-detail",
kwargs={
"club_code": self.club1.code,
"requester__username": self.user3.username,
},
)
)
self.assertEqual(resp.status_code, 403, resp.content)

# Non-member cannot accept requests
self.client.login(username=self.user4.username, password="test")
resp = self.client.delete(
reverse(
"club-ownership-requests-detail",
kwargs={
"club_code": self.club1.code,
"requester__username": self.user4.username,
},
)
)
self.assertEqual(resp.status_code, 403, resp.content)

# Owner can accept requests

# Accept for officer
self.client.login(username=self.user1.username, password="test")

resp = self.client.delete(
reverse(
"club-ownership-requests-detail",
kwargs={
"club_code": self.club1.code,
"requester__username": self.user2.username,
},
)
)
self.assertEqual(resp.status_code, 204, resp.content)

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

self.assertEqual(
Membership.objects.filter(
club=self.club1, person=self.user2, role=Membership.ROLE_OWNER
).count(),
0,
)

# Accept for member
resp = self.client.delete(
reverse(
"club-ownership-requests-detail",
kwargs={
"club_code": self.club1.code,
"requester__username": self.user3.username,
},
)
)
self.assertEqual(resp.status_code, 204, resp.content)

self.assertEqual(
OwnershipRequest.objects.filter(
club=self.club1, requester=self.user3
).count(),
0,
)

self.assertEqual(
Membership.objects.filter(
club=self.club1, person=self.user3, role=Membership.ROLE_OWNER
).count(),
0,
)

# Accept for non-member
resp = self.client.delete(
reverse(
"club-ownership-requests-detail",
kwargs={
"club_code": self.club1.code,
"requester__username": self.user4.username,
},
)
)
self.assertEqual(resp.status_code, 204, resp.content)

self.assertEqual(
OwnershipRequest.objects.filter(
club=self.club1, requester=self.user4
).count(),
0,
)

self.assertEqual(
Membership.objects.filter(
club=self.club1, person=self.user4, role=Membership.ROLE_OWNER
).count(),
0,
)

0 comments on commit d5e4b6c

Please sign in to comment.