-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c65598
commit b3c0fbc
Showing
1 changed file
with
58 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,8 +175,9 @@ def setUp(self): | |
self.club1 = Club.objects.create( | ||
code="test-club", | ||
name="Test Club", | ||
approved=True, | ||
email="[email protected]", | ||
approved=True, | ||
approved_on=timezone.now(), | ||
) | ||
|
||
self.event1 = Event.objects.create( | ||
|
@@ -1141,55 +1142,63 @@ def test_club_approve(self): | |
|
||
def test_club_display_after_deactivation_for_permissioned_vs_non_permissioned(self): | ||
""" | ||
Test club retrieval after deactivation script runs. Non-permissioned users | ||
should see the last approved version of the club. Permissioned users (e.g. | ||
admins, club members) should see the most up-to-date version. | ||
Test club retrieval during renewal period after deactivation. | ||
Non-permissioned users should see last approved version. | ||
Privileged users (e.g. admins, club members) should see most up-to-date. | ||
""" | ||
# club is approved before deactivation | ||
self.assertTrue(self.club1.approved) | ||
|
||
call_command("deactivate", "all", "--force") | ||
|
||
club = self.club1 | ||
club.refresh_from_db() | ||
|
||
# after deactivation, club should not be approved and should not have approver | ||
self.assertIsNone(club.approved) | ||
self.assertIsNone(club.approved_by) | ||
|
||
# non-permissioned users should see the last approved version | ||
non_admin_resp = self.client.get(reverse("clubs-detail", args=(club.code,))) | ||
self.assertEqual(non_admin_resp.status_code, 200) | ||
non_admin_data = non_admin_resp.json() | ||
self.assertTrue(non_admin_data["approved"]) | ||
|
||
# permissioned users should see the club as it is in the DB | ||
self.client.login(username=self.user5.username, password="test") | ||
admin_resp = self.client.get(reverse("clubs-detail", args=(club.code,))) | ||
self.assertEqual(admin_resp.status_code, 200) | ||
admin_data = admin_resp.json() | ||
self.assertIsNone(admin_data["approved"]) | ||
self.client.logout() | ||
|
||
cache.clear() | ||
|
||
# reversing the order of operations shouldn't change anything | ||
self.client.login(username=self.user5.username, password="test") | ||
admin_resp = self.client.get(reverse("clubs-detail", args=(club.code,))) | ||
self.assertEqual(admin_resp.status_code, 200) | ||
admin_data = admin_resp.json() | ||
self.assertIsNone(admin_data["approved"]) | ||
self.client.logout() | ||
|
||
non_admin_resp = self.client.get(reverse("clubs-detail", args=(club.code,))) | ||
self.assertEqual(non_admin_resp.status_code, 200) | ||
non_admin_data = non_admin_resp.json() | ||
self.assertTrue(non_admin_data["approved"]) | ||
|
||
# club object itself shouldn't have changed | ||
club.refresh_from_db() | ||
self.assertFalse(club.active) | ||
self.assertIsNone(club.approved) | ||
# Mock that we're in renewal period | ||
with patch( | ||
"django.conf.settings.RENEWAL_PERIOD", | ||
( | ||
(timezone.now() - datetime.timedelta(days=5)), | ||
(timezone.now() + datetime.timedelta(days=5)), | ||
), | ||
): | ||
# club is approved before deactivation | ||
self.assertTrue(self.club1.approved) | ||
|
||
call_command("deactivate", "all", "--force") | ||
|
||
club = self.club1 | ||
club.refresh_from_db() | ||
|
||
# club is not approved and does not have approver after deactivation | ||
self.assertIsNone(club.approved) | ||
self.assertIsNone(club.approved_by) | ||
|
||
# non-permissioned users should see the last approved version | ||
non_admin_resp = self.client.get(reverse("clubs-detail", args=(club.code,))) | ||
self.assertEqual(non_admin_resp.status_code, 200) | ||
non_admin_data = non_admin_resp.json() | ||
self.assertTrue(non_admin_data["approved"]) | ||
|
||
# permissioned users should see the club as it is in the DB | ||
self.client.login(username=self.user5.username, password="test") | ||
admin_resp = self.client.get(reverse("clubs-detail", args=(club.code,))) | ||
self.assertEqual(admin_resp.status_code, 200) | ||
admin_data = admin_resp.json() | ||
self.assertIsNone(admin_data["approved"]) | ||
self.client.logout() | ||
|
||
cache.clear() | ||
|
||
# reversing the order of operations shouldn't change anything | ||
self.client.login(username=self.user5.username, password="test") | ||
admin_resp = self.client.get(reverse("clubs-detail", args=(club.code,))) | ||
self.assertEqual(admin_resp.status_code, 200) | ||
admin_data = admin_resp.json() | ||
self.assertIsNone(admin_data["approved"]) | ||
self.client.logout() | ||
|
||
non_admin_resp = self.client.get(reverse("clubs-detail", args=(club.code,))) | ||
self.assertEqual(non_admin_resp.status_code, 200) | ||
non_admin_data = non_admin_resp.json() | ||
self.assertTrue(non_admin_data["approved"]) | ||
|
||
# club object itself shouldn't have changed | ||
club.refresh_from_db() | ||
self.assertFalse(club.active) | ||
self.assertIsNone(club.approved) | ||
|
||
def test_club_create_url_sanitize(self): | ||
""" | ||
|