def test_has_role_with_context_success(): project = ProjectFactory() user = UserFactory() ProjectMembershipFactory(project=project, user=user, roles=[ProjectCollaborator]) assert has_role(user, ProjectCollaborator, project=project)
def test_has_role_with_context_failure(): project = ProjectFactory() user = UserFactory() ProjectMembershipFactory(project=project, user=user, roles=[ProjectCollaborator]) # key must be a known key with pytest.raises( ValueError, match="Some invalid keys were used in the context:\n - test"): has_role(user, ProjectCollaborator, test=project) # value must be the correct type with pytest.raises(ValueError, match='key "project" got a User, expected a Project'): has_role(user, ProjectCollaborator, project=user)
def test_has_roles_success(): user = UserFactory(roles=[OutputPublisher]) assert has_role(user, OutputPublisher)
def test_has_role_unauthenticated(): user = AnonymousUser() assert not has_role(user, ProjectCollaborator)
def test_has_roles_failure(): user = UserFactory(roles=[OutputPublisher]) assert not has_role(user, ProjectCollaborator)