Skip to content

Commit

Permalink
test_model: Re parametrize for inline ids.
Browse files Browse the repository at this point in the history
  • Loading branch information
mounilKshah committed Mar 14, 2022
1 parent 590ef42 commit 159e039
Showing 1 changed file with 80 additions and 125 deletions.
205 changes: 80 additions & 125 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,177 +754,147 @@ def test_send_stream_message(
@pytest.mark.parametrize(
"user_role, stream_properties",
[
# is admin :: announcement_only :: 2.1
(
case(
{"is_admin": True},
{"is_announcement_only": True},
id="is_admin:announcement_only:Zulip2.1",
),
# is admin :: not_announcement_only :: 2.1
(
case(
{"is_admin": True},
{"is_announcement_only": False},
id="is_admin:not_announcement_only:Zulip2.1",
),
# is not admin :: not_announcement_only :: 2.1
(
case(
{"is_admin": False},
{"is_announcement_only": False},
id="is_not_admin:not_announcement_only:Zulip2.1",
),
# is owner :: anyone_can_post :: ZFL 8
(
case(
{"is_owner": True, "is_admin": True, "is_guest": False},
{"is_announcement_only": False, "stream_post_policy": 1},
id="is_owner:anyone_can_post:Zulip3.0+:ZFL8",
),
# is owner :: only_admins_can_post :: ZFL 8
(
case(
{"is_owner": True, "is_admin": True, "is_guest": False},
{"is_announcement_only": True, "stream_post_policy": 2},
id="is_owner:admins_only:Zulip3.0+:ZFL8",
),
# is owner :: only_members_can_post :: ZFL 8
(
case(
{"is_owner": True, "is_admin": True, "is_guest": False},
{"is_announcement_only": False, "stream_post_policy": 3},
id="is_owner:members_only:Zulip3.0+:ZFL8",
),
# is owner :: only_moderators_can_post :: ZFL 8
(
case(
{"is_owner": True, "is_admin": True, "is_guest": False},
{"is_announcement_only": False, "stream_post_policy": 4},
id="is_owner:moderators_only:Zulip3.0+:ZFL8",
),
# is admin :: anyone_can_post :: ZFL 8
(
case(
{"is_owner": False, "is_admin": True, "is_guest": False},
{"is_announcement_only": False, "stream_post_policy": 1},
id="is_admin:anyone_can_post:Zulip3.0+:ZFL8",
),
# is admin :: only_admins_can_post :: ZFL 8
(
case(
{"is_owner": False, "is_admin": True, "is_guest": False},
{"is_announcement_only": True, "stream_post_policy": 2},
id="is_admin:admins_only:Zulip3.0+:ZFL8",
),
# is admin :: only_members_can_post :: ZFL 8
(
case(
{"is_owner": False, "is_admin": True, "is_guest": False},
{"is_announcement_only": False, "stream_post_policy": 3},
id="is_admin:members_only:Zulip3.0+:ZFL8",
),
# is admin :: only_members_can_post :: ZFL 8
(
case(
{"is_owner": False, "is_admin": True, "is_guest": False},
{"is_announcement_only": False, "stream_post_policy": 4},
id="is_admin:moderators_only:Zulip3.0+:ZFL8",
),
# is member :: anyone_can_post :: ZFL 8
(
case(
{"is_owner": False, "is_admin": False, "is_guest": False},
{"is_announcement_only": False, "stream_post_policy": 1},
id="is_member:anyone_can_post:Zulip3.0+:ZFL8",
),
# is member :: only_members_can_post :: ZFL 8
(
case(
{"is_owner": False, "is_admin": False, "is_guest": False},
{"is_announcement_only": False, "stream_post_policy": 3},
id="is_member:members_only:Zulip3.0+:ZFL8",
),
# is guest :: anyone_can_post :: ZFL 59
(
case(
{"is_owner": False, "is_admin": False, "is_guest": True},
{"is_announcement_only": False, "stream_post_policy": 1},
id="is_guest:anyone_can_post:Zulip3.0+:ZFL8",
),
# is_owner :: anyone_can_post :: ZFL 59
(
case(
{"is_admin": True, "is_owner": True, "is_guest": False, "role": 100},
{"is_announcement_only": False, "stream_post_policy": 1},
id="is_owner:anyone_can_post:Zulip4.0+:ZFL59",
),
# is owner :: only_admins_can_post :: ZFL 59
(
case(
{"is_admin": True, "is_owner": True, "is_guest": False, "role": 100},
{"is_announcement_only": True, "stream_post_policy": 2},
id="is_owner:admins_only:Zulip4.0+:ZFL59",
),
# is owner :: only_members_can_post :: ZFL 59
(
case(
{"is_admin": True, "is_owner": True, "is_guest": False, "role": 100},
{"is_announcement_only": False, "stream_post_policy": 3},
id="is_owner:members_only:Zulip4.0+:ZFL59",
),
# is owner :: only_moderators_can_post :: ZFL 59
(
case(
{"is_admin": True, "is_owner": True, "is_guest": False, "role": 100},
{"is_announcement_only": False, "stream_post_policy": 4},
id="is_owner:moderators_only:Zulip4.0+:ZFL59",
),
# is admin :: anyone_can_post :: ZFL 59
(
case(
{"is_admin": True, "is_owner": False, "is_guest": False, "role": 200},
{"is_announcement_only": False, "stream_post_policy": 1},
id="is_admin:anyone_can_post:Zulip4.0+:ZFL59",
),
# is admin :: only_admins_can_post :: ZFL 59
(
case(
{"is_admin": True, "is_owner": False, "is_guest": False, "role": 200},
{"is_announcement_only": True, "stream_post_policy": 2},
id="is_admin:admins_only:Zulip4.0+:ZFL59",
),
# is admin :: only_members_can_post :: ZFL 59
(
case(
{"is_admin": True, "is_owner": False, "is_guest": False, "role": 200},
{"is_announcement_only": False, "stream_post_policy": 3},
id="is_admin:members_only:Zulip4.0+:ZFL59",
),
# is admin :: only_members_can_post :: ZFL 59
(
case(
{"is_admin": True, "is_owner": False, "is_guest": False, "role": 200},
{"is_announcement_only": False, "stream_post_policy": 4},
id="is_admin:moderators_only:Zulip4.0+:ZFL59",
),
# is_moderator :: anyone_can_post :: ZFL 59
(
case(
{"is_admin": False, "is_owner": False, "is_guest": False, "role": 300},
{"is_announcement_only": False, "stream_post_policy": 1},
id="is_moderator:anyone_can_post:Zulip4.0+:ZFL59",
),
# is_moderator :: only_members_can_post :: ZFL 59
(
case(
{"is_admin": False, "is_owner": False, "is_guest": False, "role": 300},
{"is_announcement_only": False, "stream_post_policy": 3},
id="is_moderator:admins_only:Zulip4.0+:ZFL59",
),
# is_moderator :: only_moderators_can_post :: ZFL 59
(
case(
{"is_admin": False, "is_owner": False, "is_guest": False, "role": 300},
{"is_announcement_only": False, "stream_post_policy": 4},
id="is_moderator:moderators_only:Zulip4.0+:ZFL59",
),
# is_member :: anyone_can_post :: ZFL 59
(
case(
{"is_admin": False, "is_owner": False, "is_guest": False, "role": 400},
{"is_announcement_only": False, "stream_post_policy": 1},
id="is_member:anyone_can_post:Zulip4.0+:ZFL59",
),
# is_member :: only_members_can_post :: ZFL 59
(
case(
{"is_admin": False, "is_owner": False, "is_guest": False, "role": 400},
{"is_announcement_only": False, "stream_post_policy": 3},
id="is_member:members_only:Zulip4.0+:ZFL59",
),
# is_guest :: anyone_can_post :: ZFL 59
(
case(
{"is_admin": False, "is_owner": False, "is_guest": True, "role": 600},
{"is_announcement_only": False, "stream_post_policy": 1},
id="is_guest:anyone_can_post:Zulip4.0+:ZFL59",
),
],
ids=[
"is_admin:announcement_only:Zulip2.1",
"is_admin:not_announcement_only:Zulip2.1",
"is_not_admin:not_announcement_only:Zulip2.1",
"is_owner:anyone_can_post:Zulip3.0+:ZFL8",
"is_owner:admins_only:Zulip3.0+:ZFL8",
"is_owner:members_only:Zulip3.0+:ZFL8",
"is_owner:moderators_only:Zulip3.0+:ZFL8",
"is_admin:anyone_can_post:Zulip3.0+:ZFL8",
"is_admin:admins_only:Zulip3.0+:ZFL8",
"is_admin:members_only:Zulip3.0+:ZFL8",
"is_admin:moderators_only:Zulip3.0+:ZFL8",
"is_member:anyone_can_post:Zulip3.0+:ZFL8",
"is_member:members_only:Zulip3.0+:ZFL8",
"is_guest:anyone_can_post:Zulip3.0+:ZFL8",
"is_owner:anyone_can_post:Zulip4.0+:ZFL59",
"is_owner:admins_only:Zulip4.0+:ZFL59",
"is_owner:members_only:Zulip4.0+:ZFL59",
"is_owner:moderators_only:Zulip4.0+:ZFL59",
"is_admin:anyone_can_post:Zulip4.0+:ZFL59",
"is_admin:admins_only:Zulip4.0+:ZFL59",
"is_admin:members_only:Zulip4.0+:ZFL59",
"is_admin:moderators_only:Zulip4.0+:ZFL59",
"is_moderator:anyone_can_post:Zulip4.0+:ZFL59",
"is_moderator:admins_only:Zulip4.0+:ZFL59",
"is_moderator:moderators_only:Zulip4.0+:ZFL59",
"is_member:anyone_can_post:Zulip4.0+:ZFL59",
"is_member:members_only:Zulip4.0+:ZFL59",
"is_guest:anyone_can_post:Zulip4.0+:ZFL59",
],
)
def test_is_unauthorised_to_post_in_stream_can_post(
self,
Expand All @@ -942,97 +912,82 @@ def test_is_unauthorised_to_post_in_stream_can_post(
model.user_id = 11
assert model.is_unauthorised_to_post_in_stream(stream_id=99) is None

# @pytest.mark.two
@pytest.mark.parametrize(
"user_role, stream_properties, expected_response",
[
# is not admin of the stream 2.1
(
case(
{"is_admin": False},
{"is_announcement_only": True},
"Only Admins and owners can type",
id="is_not_admin:announcement_only:Zulip2.1",
),
# is_member :: admins_only :: ZFL 8
(
case(
{"is_owner": False, "is_admin": False, "is_guest": False},
{"is_announcement_only": False, "stream_post_policy": 2},
"Only Admins and owners can type",
id="is_member:admins_only:Zulip3.0+:ZFL8",
),
# is member :: moderators_only :: ZFL 8
(
case(
{"is_owner": False, "is_admin": False, "is_guest": False},
{"is_announcement_only": False, "stream_post_policy": 4},
"Only Admins, moderators and owners are allowed to type",
id="is_member:moderators_only:Zulip3.0+:ZFL8",
),
# is guest :: admins_only :: ZFL 8
(
case(
{"is_owner": False, "is_admin": False, "is_guest": True},
{"is_announcement_only": False, "stream_post_policy": 2},
"Only Admins and owners can type",
id="is_guest:admins_only:Zulip3.0+:ZFL8",
),
# is guest :: members_only :: ZFL 8
(
case(
{"is_owner": False, "is_admin": False, "is_guest": True},
{"is_announcement_only": False, "stream_post_policy": 3},
"Only Admins, moderators, owners and members are allowed to type",
id="is_guest:members_only:Zulip3.0+:ZFL8",
),
# is guest :: moderators_only :: ZFL 8
(
case(
{"is_owner": False, "is_admin": False, "is_guest": True},
{"is_announcement_only": False, "stream_post_policy": 4},
"Only Admins, moderators and owners are allowed to type",
id="is_guest:moderators_only:Zulip3.0+:ZFL8",
),
# is_moderator :: admins_only :: ZFL 59
(
case(
{"is_admin": False, "is_owner": False, "is_guest": False, "role": 300},
{"is_announcement_only": False, "stream_post_policy": 2},
"Only Admins and owners can type",
id="is_moderator:admins_only:Zulip4.0+:ZFL59",
),
# is_member :: admins_only :: ZFL 59
(
case(
{"is_admin": False, "is_owner": False, "is_guest": False, "role": 400},
{"is_announcement_only": False, "stream_post_policy": 2},
"Only Admins and owners can type",
id="is_member:admins_only:Zulip4.0+:ZFL59",
),
# is_member :: moderators_only :: ZFL 59
(
case(
{"is_admin": False, "is_owner": False, "is_guest": False, "role": 400},
{"is_announcement_only": False, "stream_post_policy": 4},
"Only Admins, moderators and owners are allowed to type",
id="is_member:moderators_only:Zulip4.0+:ZFL59",
),
# is_guest :: admins_only :: ZFL 59
(
case(
{"is_admin": False, "is_owner": False, "is_guest": True, "role": 600},
{"is_announcement_only": False, "stream_post_policy": 2},
"Only Admins and owners can type",
id="is_guest:admins_only:Zulip4.0+:ZFL59",
),
# is_guest :: members_only :: ZFL 59
(
case(
{"is_admin": False, "is_owner": False, "is_guest": True, "role": 600},
{"is_announcement_only": False, "stream_post_policy": 3},
"Only Admins, moderators, owners and members are allowed to type",
id="is_guest:members_only:Zulip4.0+:ZFL59",
),
# is_guest :: moderators_only :: ZFL 59
(
case(
{"is_admin": False, "is_owner": False, "is_guest": True, "role": 600},
{"is_announcement_only": False, "stream_post_policy": 4},
"Only Admins, moderators and owners are allowed to type",
id="is_guest:moderators_only:Zulip4.0+:ZFL59",
),
],
ids=[
"is_not_admin:announcement_only:Zulip2.1",
"is_member:admins_only:Zulip3.0+:ZFL8",
"is_member:moderators_only:Zulip3.0+:ZFL8",
"is_guest:admins_only:Zulip3.0+:ZFL8",
"is_guest:members_only:Zulip3.0+:ZFL8",
"is_guest:moderators_only:Zulip3.0+:ZFL8",
"is_moderator:admins_only:Zulip4.0+:ZFL59",
"is_member:admins_only:Zulip4.0+:ZFL59",
"is_member:moderators_only:Zulip4.0+:ZFL59",
"is_guest:admins_only:Zulip4.0+:ZFL59",
"is_guest:members_only:Zulip4.0+:ZFL59",
"is_guest:moderators_only:Zulip4.0+:ZFL59",
],
)
def test_is_unauthorised_to_post_in_stream_cannot_post(
self,
Expand Down

0 comments on commit 159e039

Please sign in to comment.