From a457738081d58f3db75be7437839dc766a9020d0 Mon Sep 17 00:00:00 2001 From: Jiri Kozel Date: Thu, 14 Dec 2023 17:59:08 +0100 Subject: [PATCH] Parametrize TestOnlyValidUserNames --- .../prime_db_schema/publications_test.py | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/layman/common/prime_db_schema/publications_test.py b/src/layman/common/prime_db_schema/publications_test.py index 9bac4bf15..b9aa82f61 100644 --- a/src/layman/common/prime_db_schema/publications_test.py +++ b/src/layman/common/prime_db_schema/publications_test.py @@ -33,32 +33,24 @@ class TestOnlyValidUserNames: @pytest.fixture(scope="class", autouse=True) def provide_data(self, request): ensure_user(self.username, '10') + workspaces.ensure_workspace(self.workspace_name) yield if request.node.session.testsfailed == 0: + workspaces.delete_workspace(self.workspace_name) users.delete_user(self.username) @classmethod - def test_raises(cls): - workspace_name = cls.workspace_name - username = cls.username - + @pytest.mark.parametrize("names", [ + pytest.param({username, workspace_name}, id='username-and-workspace-name'), + pytest.param({workspace_name, username}, id='workspace-name-and-username'), + pytest.param({'skaljgdalskfglshfgd'}, id='non-existent-username'), + ]) + def test_raises(cls, names): with app.app_context(): - workspaces.ensure_workspace(workspace_name) - - with pytest.raises(LaymanError) as exc_info: - publications.only_valid_user_names({username, workspace_name}) - assert exc_info.value.code == 43 - with pytest.raises(LaymanError) as exc_info: - publications.only_valid_user_names({workspace_name, username}) + publications.only_valid_user_names(names) assert exc_info.value.code == 43 - with pytest.raises(LaymanError) as exc_info: - publications.only_valid_user_names({'skaljgdalskfglshfgd', }) - assert exc_info.value.code == 43 - - workspaces.delete_workspace(workspace_name) - class TestOnlyValidRoleNames: role1 = 'TEST_ONLY_VALID_ROLE_NAMES_ROLE1'