Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
def test_has_roles_success():
    user = UserFactory(roles=[OutputPublisher])

    assert has_role(user, OutputPublisher)
Esempio n. 4
0
def test_has_role_unauthenticated():
    user = AnonymousUser()

    assert not has_role(user, ProjectCollaborator)
Esempio n. 5
0
def test_has_roles_failure():
    user = UserFactory(roles=[OutputPublisher])

    assert not has_role(user, ProjectCollaborator)