Skip to content

Commit

Permalink
Parametrize TestOnlyValidUserNames
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Dec 15, 2023
1 parent a9b457d commit 1b884f0
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/layman/common/prime_db_schema/publications_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 1b884f0

Please sign in to comment.