Skip to content

Commit

Permalink
Test i_can_still_write in class
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Dec 20, 2023
1 parent 84757ef commit a100ebf
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions src/layman/common/prime_db_schema/publications_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,35 +172,34 @@ def test_who_can_write_can_read():
assert exc_info.value.code == 43


def test_i_can_still_write():
workspace_name = 'test_i_can_still_write_workspace'
username = 'test_who_can_write_can_read_user'

publications.i_can_still_write(None, {settings.RIGHTS_EVERYONE_ROLE, })
publications.i_can_still_write(None, {username, settings.RIGHTS_EVERYONE_ROLE, })
publications.i_can_still_write(username, {settings.RIGHTS_EVERYONE_ROLE, })
publications.i_can_still_write(username, {workspace_name, settings.RIGHTS_EVERYONE_ROLE, })
publications.i_can_still_write(username, {workspace_name, username, })

with pytest.raises(LaymanError) as exc_info:
publications.i_can_still_write(None, set())
assert exc_info.value.code == 43

with pytest.raises(LaymanError) as exc_info:
publications.i_can_still_write(None, {workspace_name, })
assert exc_info.value.code == 43

with pytest.raises(LaymanError) as exc_info:
publications.i_can_still_write(username, set())
assert exc_info.value.code == 43
class TestICanStillWrite:
username = 'test_i_can_still_write_user'
username2 = 'test_i_can_still_write_user2'
role1 = 'ROLE1'

with pytest.raises(LaymanError) as exc_info:
publications.i_can_still_write(username, {workspace_name, })
assert exc_info.value.code == 43
@classmethod
@pytest.mark.parametrize("actor_name, can_write", [
pytest.param(None, {settings.RIGHTS_EVERYONE_ROLE}, id='noname-rights-everyone'),
pytest.param(None, {username, settings.RIGHTS_EVERYONE_ROLE}, id='noname-rights-everyone-and-user'),
pytest.param(username, {settings.RIGHTS_EVERYONE_ROLE}, id='user-rights-everyone'),
pytest.param(username, {username2, settings.RIGHTS_EVERYONE_ROLE}, id='user-rights-other-user-and-everyone'),
pytest.param(username, {username, username2}, id='user-rights-user-and-other-user'),
])
def test_ok(cls, actor_name, can_write):
publications.i_can_still_write(actor_name, can_write)

with pytest.raises(LaymanError) as exc_info:
publications.i_can_still_write(username, {'ROLE1'})
assert exc_info.value.code == 43
@classmethod
@pytest.mark.parametrize("actor_name, can_write", [
pytest.param(None, set(), id='noname-empty-rights'),
pytest.param(None, {username2}, id='noname-rights-other-user'),
pytest.param(username, set(), id='user-empty-rights'),
pytest.param(username, {username2}, id='user-rights-other-user'),
pytest.param(username, {role1}, id='user-rights-role'),
])
def test_raises(cls, actor_name, can_write):
with pytest.raises(LaymanError) as exc_info:
publications.i_can_still_write(actor_name, can_write)
assert exc_info.value.code == 43


class TestOwnerCanStillWrite:
Expand Down

0 comments on commit a100ebf

Please sign in to comment.