mirror of https://github.com/zulip/zulip.git
tests: Refactor test_can_create_streams and test_can_subscribe_other_users.
We refactor test_can_create_streams and test_can_subscribe_other_users in test_subs.py. We want to follow a specific order in such tests which is just set the policy value one by one and then checking that the role in policy returns true and role just below that returns false. This approach is explained in detail below. Following hierarchy of roles is considered for these tests - 1. Realm admin 2. Full members 3. Members 4. Guests. Then if the policy is set to admins only, we check that the having role as admin returns true and the role just below that, i.e. full member returns false. Similarly, if the policy is set to members only, we check that a member should return true and role below it which is guest should return false. We basically follow these as we can assume that if a user with particular role cannot do the required task, then user with role below in the hierarchy would be not allowed to do the task too. This commit refactors the above mentioned two tests to have above explained workflow.
This commit is contained in:
parent
bc72d2dbc4
commit
683b6f7d65
|
@ -3209,6 +3209,9 @@ class SubscriptionAPITest(ZulipTestCase):
|
|||
|
||||
othello.role = UserProfile.ROLE_MEMBER
|
||||
othello.realm.create_stream_policy = Realm.POLICY_ADMINS_ONLY
|
||||
# Make sure that we are checking the permission with a full member,
|
||||
# as full member is the user just below admin in the role hierarchy.
|
||||
self.assertFalse(othello.is_provisional_member)
|
||||
self.assertFalse(othello.can_create_streams())
|
||||
|
||||
othello.realm.create_stream_policy = Realm.POLICY_MEMBERS_ONLY
|
||||
|
@ -3216,6 +3219,8 @@ class SubscriptionAPITest(ZulipTestCase):
|
|||
self.assertFalse(othello.can_create_streams())
|
||||
|
||||
othello.role = UserProfile.ROLE_MEMBER
|
||||
self.assertTrue(othello.can_create_streams())
|
||||
|
||||
othello.realm.waiting_period_threshold = 1000
|
||||
othello.realm.create_stream_policy = Realm.POLICY_FULL_MEMBERS_ONLY
|
||||
othello.date_joined = timezone_now() - timedelta(
|
||||
|
@ -3285,10 +3290,20 @@ class SubscriptionAPITest(ZulipTestCase):
|
|||
do_change_user_role(othello, UserProfile.ROLE_REALM_ADMINISTRATOR)
|
||||
self.assertTrue(othello.can_subscribe_other_users())
|
||||
|
||||
do_set_realm_property(othello.realm, "invite_to_stream_policy", Realm.POLICY_ADMINS_ONLY)
|
||||
do_change_user_role(othello, UserProfile.ROLE_MEMBER)
|
||||
# Make sure that we are checking the permission with a full member,
|
||||
# as full member is the user just below admin in the role hierarchy.
|
||||
self.assertFalse(othello.is_provisional_member)
|
||||
self.assertFalse(othello.can_subscribe_other_users())
|
||||
|
||||
do_set_realm_property(othello.realm, "invite_to_stream_policy", Realm.POLICY_MEMBERS_ONLY)
|
||||
do_change_user_role(othello, UserProfile.ROLE_GUEST)
|
||||
self.assertFalse(othello.can_subscribe_other_users())
|
||||
|
||||
do_change_user_role(othello, UserProfile.ROLE_MEMBER)
|
||||
self.assertTrue(othello.can_subscribe_other_users())
|
||||
|
||||
do_set_realm_property(othello.realm, "waiting_period_threshold", 1000)
|
||||
do_set_realm_property(
|
||||
othello.realm, "invite_to_stream_policy", Realm.POLICY_FULL_MEMBERS_ONLY
|
||||
|
|
Loading…
Reference in New Issue