mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
actions: Change do_change_is_admin Exception to an Assertion Error.
- do_change_is_admin now raises AssertionError when a non-admin permission is given. - adds test to test_users to ensure admin asserts on invalid permission values.
This commit is contained in:
committed by
Tim Abbott
parent
4bdc8332fa
commit
f59adfa67c
@@ -2947,7 +2947,7 @@ def do_change_is_admin(user_profile: UserProfile, value: bool,
|
|||||||
user_profile.is_api_super_user = value
|
user_profile.is_api_super_user = value
|
||||||
user_profile.save(update_fields=["is_api_super_user"])
|
user_profile.save(update_fields=["is_api_super_user"])
|
||||||
else:
|
else:
|
||||||
raise Exception("Unknown permission")
|
raise AssertionError("Invalid admin permission")
|
||||||
|
|
||||||
if permission == 'administer':
|
if permission == 'administer':
|
||||||
event = dict(type="realm_user", op="update",
|
event = dict(type="realm_user", op="update",
|
||||||
|
|||||||
@@ -56,6 +56,24 @@ def find_dict(lst: Iterable[Dict[K, V]], k: K, v: V) -> Dict[K, V]:
|
|||||||
raise AssertionError('Cannot find element in list where key %s == %s' % (k, v))
|
raise AssertionError('Cannot find element in list where key %s == %s' % (k, v))
|
||||||
|
|
||||||
class PermissionTest(ZulipTestCase):
|
class PermissionTest(ZulipTestCase):
|
||||||
|
|
||||||
|
def test_do_change_is_admin(self) -> None:
|
||||||
|
"""
|
||||||
|
Ensures change_is_admin raises an AssertionError when invalid permissions
|
||||||
|
are provided to it.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# this should work fine
|
||||||
|
user_profile = self.example_user('hamlet')
|
||||||
|
do_change_is_admin(user_profile, True)
|
||||||
|
|
||||||
|
# this should work a-ok as well
|
||||||
|
do_change_is_admin(user_profile, True, permission='administer')
|
||||||
|
|
||||||
|
# this should "fail" with an AssertionError
|
||||||
|
with self.assertRaises(AssertionError):
|
||||||
|
do_change_is_admin(user_profile, True, permission='totally-not-valid-perm')
|
||||||
|
|
||||||
def test_get_admin_users(self) -> None:
|
def test_get_admin_users(self) -> None:
|
||||||
user_profile = self.example_user('hamlet')
|
user_profile = self.example_user('hamlet')
|
||||||
do_change_is_admin(user_profile, False)
|
do_change_is_admin(user_profile, False)
|
||||||
|
|||||||
Reference in New Issue
Block a user