-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backend] Add method to check if a user is staff (#4045)
* Adeed function to check a user staff * Added test for the function * Fix user being same in test * Name Change --------- Co-authored-by: Gunjan Chhablani <[email protected]>
- Loading branch information
1 parent
7d1cd20
commit 74d7396
Showing
2 changed files
with
37 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
from rest_framework import status | ||
from rest_framework.test import APITestCase, APIClient | ||
|
||
from base.utils import RandomFileName, send_slack_notification | ||
from base.utils import RandomFileName, send_slack_notification, is_user_a_staff | ||
from challenges.models import Challenge, ChallengePhase | ||
from hosts.models import ChallengeHostTeam | ||
from jobs.models import Submission | ||
|
@@ -134,3 +134,26 @@ def test_if_slack_notification_works(self): | |
response = send_slack_notification(message=message) | ||
self.assertEqual(type(response), requests.models.Response) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
|
||
class TestUserIsStaff(BaseAPITestClass): | ||
|
||
def test_if_user_is_staff(self): | ||
self.user = User.objects.create( | ||
username="someuser1", | ||
email="[email protected]", | ||
password="secret_password", | ||
is_staff=True, | ||
) | ||
self.assertTrue(is_user_a_staff(self.user)) | ||
|
||
def test_if_user_is_not_staff(self): | ||
self.user = User.objects.create( | ||
username="someuser2", | ||
email="[email protected]", | ||
password="secret_password", | ||
is_staff=False, | ||
) | ||
self.user.is_staff = False | ||
self.user.save() | ||
self.assertFalse(is_user_a_staff(self.user)) |