Skip to content

Commit

Permalink
Rewrite test_update_rights positive cases with parametrization
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Nov 29, 2023
1 parent de28393 commit 90386f1
Showing 1 changed file with 92 additions and 50 deletions.
142 changes: 92 additions & 50 deletions src/layman/common/prime_db_schema/publications_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,98 @@ def test_rights(self, username, access_rights, read_to_test, write_to_test, ):
publications.delete_publication(username, publication_info["publ_type_name"], publication_info["name"])


class TestUpdateRights:
workspace_name = 'test_update_rights_workspace'
username = 'test_update_rights_user'
username2 = 'test_update_rights_user2'

publication_name = 'test_update_rights_publication_name'
publication_type = MAP_TYPE
publication_insert_info = {"name": publication_name,
"title": publication_name,
"publ_type_name": publication_type,
"actor_name": username,
"uuid": uuid.uuid4(),
"access_rights": {"read": {settings.RIGHTS_EVERYONE_ROLE, },
"write": {settings.RIGHTS_EVERYONE_ROLE, },
},
"image_mosaic": False,
}

@pytest.fixture(scope="class", autouse=True)
def provide_data(self, request):
with app.app_context():
workspaces.ensure_workspace(self.workspace_name)
id_workspace_user = workspaces.ensure_workspace(self.username)
userinfo = userinfo_baseline.copy()
userinfo['sub'] = '50'
users.ensure_user(id_workspace_user, userinfo)
id_workspace_user2 = workspaces.ensure_workspace(self.username2)
userinfo = userinfo_baseline.copy()
userinfo['sub'] = '60'
users.ensure_user(id_workspace_user2, userinfo)

publications.insert_publication(self.username, self.publication_insert_info)
yield
if request.node.session.testsfailed == 0:
with app.app_context():
publications.delete_publication(self.username, self.publication_insert_info["publ_type_name"],
self.publication_insert_info["name"])
users.delete_user(self.username)
users.delete_user(self.username2)
workspaces.delete_workspace(self.workspace_name)

@pytest.mark.parametrize("username, publication_update_info, read_to_test, write_to_test", [
pytest.param(
username,
{"access_rights": {"read": {settings.RIGHTS_EVERYONE_ROLE, },
"write": {settings.RIGHTS_EVERYONE_ROLE, }},
"actor_name": username},
[username, settings.RIGHTS_EVERYONE_ROLE, ], [username, settings.RIGHTS_EVERYONE_ROLE, ],
id='personal_everyone',
),
pytest.param(
username,
{"access_rights": {"read": {username, username2, },
"write": {username, username2, }},
"actor_name": username},
[username, username2, ], [username, username2, ],
id='personal_owner_editor',
),
pytest.param(
username,
{"access_rights": {"read": {username, },
"write": {username, }},
"actor_name": username},
[username, ], [username, ],
id='personal_owner',
),
pytest.param(
username,
{"access_rights": {"read": {settings.RIGHTS_EVERYONE_ROLE, },
"write": {settings.RIGHTS_EVERYONE_ROLE, }},
"actor_name": None},
[username, settings.RIGHTS_EVERYONE_ROLE, ], [username, settings.RIGHTS_EVERYONE_ROLE, ],
id='personal_everyone_as_anonym',
),
])
def test_rights(self, username, publication_update_info, read_to_test, write_to_test, ):
publication_info_original = self.publication_insert_info
if not publication_update_info.get("publ_type_name"):
publication_update_info["publ_type_name"] = publication_info_original["publ_type_name"]
if not publication_update_info.get("name"):
publication_update_info["name"] = publication_info_original["name"]
publications.update_publication(username,
publication_update_info,
)
assert_access_rights(username,
publication_info_original["name"],
publication_info_original["publ_type_name"],
read_to_test,
write_to_test,
)


def test_update_rights():
def case_test_update_rights(username,
publication_info_original,
Expand Down Expand Up @@ -393,56 +485,6 @@ def case_test_update_rights(username,

publications.insert_publication(username, publication_insert_info)

case_test_update_rights(username,
publication_insert_info,
{"access_rights": {"read": {settings.RIGHTS_EVERYONE_ROLE, },
"write": {settings.RIGHTS_EVERYONE_ROLE, },
},
'actor_name': username},
[username, settings.RIGHTS_EVERYONE_ROLE, ],
[username, settings.RIGHTS_EVERYONE_ROLE, ],
)

case_test_update_rights(username,
publication_insert_info,
{"access_rights": {"read": {username, username2, },
"write": {username, username2, },
},
'actor_name': username},
[username, username2, ],
[username, username2, ],
)

case_test_update_rights(username,
publication_insert_info,
{"access_rights": {"read": {settings.RIGHTS_EVERYONE_ROLE, },
"write": {settings.RIGHTS_EVERYONE_ROLE, },
},
'actor_name': username},
[username, settings.RIGHTS_EVERYONE_ROLE, ],
[username, settings.RIGHTS_EVERYONE_ROLE, ],
)

case_test_update_rights(username,
publication_insert_info,
{"access_rights": {"read": {username, },
"write": {username, },
},
'actor_name': username},
[username, ],
[username, ],
)

case_test_update_rights(username,
publication_insert_info,
{"access_rights": {"read": {settings.RIGHTS_EVERYONE_ROLE, },
"write": {settings.RIGHTS_EVERYONE_ROLE, },
},
'actor_name': None},
[username, settings.RIGHTS_EVERYONE_ROLE, ],
[username, settings.RIGHTS_EVERYONE_ROLE, ],
)

with pytest.raises(LaymanError) as exc_info:
case_test_update_rights(username,
publication_insert_info,
Expand Down

0 comments on commit 90386f1

Please sign in to comment.