Ejemplo n.º 1
0
def test_user_get_user_project_permissions_on_public_project():
    user1 = factories.UserFactory()
    project = factories.ProjectFactory()
    project.anon_permissions = ["test1"]
    project.public_permissions = ["test2"]
    assert services.get_user_project_permissions(user1, project) == set(
        ["test1", "test2"])
Ejemplo n.º 2
0
def test_user_get_user_project_permissions_on_private_project():
    user1 = factories.UserFactory()
    project = factories.ProjectFactory()
    project.anon_permissions = ["test1"]
    project.public_permissions = ["test2"]
    project.is_private = True
    assert services.get_user_project_permissions(user1, project) == set(["test1", "test2"])
Ejemplo n.º 3
0
def test_member_get_user_project_permissions():
    user1 = factories.UserFactory()
    project = factories.ProjectFactory()
    project.anon_permissions = ["test1"]
    project.public_permissions = ["test2"]
    role = factories.RoleFactory(permissions=["test3"])
    factories.MembershipFactory(user=user1, project=project, role=role)

    assert services.get_user_project_permissions(user1, project) == set(["test1", "test2", "test3"])
Ejemplo n.º 4
0
def test_member_get_user_project_permissions():
    user1 = factories.UserFactory()
    project = factories.ProjectFactory()
    project.anon_permissions = ["test1"]
    project.public_permissions = ["test2"]
    role = factories.RoleFactory(permissions=["test3"])
    factories.MembershipFactory(user=user1, project=project, role=role)

    assert services.get_user_project_permissions(user1, project) == set(["test1", "test2", "test3"])
Ejemplo n.º 5
0
def test_owner_get_user_project_permissions():
    user1 = factories.UserFactory()
    project = factories.ProjectFactory()
    project.anon_permissions = ["test1"]
    project.public_permissions = ["test2"]
    project.owner = user1
    role = factories.RoleFactory(permissions=["view_us"])
    factories.MembershipFactory(user=user1, project=project, role=role)

    expected_perms = set(["test1", "test2", "view_us"])
    assert services.get_user_project_permissions(user1,
                                                 project) == expected_perms
Ejemplo n.º 6
0
def test_owner_get_user_project_permissions():
    user1 = factories.UserFactory()
    project = factories.ProjectFactory()
    project.anon_permissions = ["test1"]
    project.public_permissions = ["test2"]
    project.owner = user1
    role = factories.RoleFactory(permissions=["view_us"])
    factories.MembershipFactory(user=user1, project=project, role=role)

    expected_perms = set(
        ["test1", "test2", "view_us"]
    )
    assert services.get_user_project_permissions(user1, project) == expected_perms
Ejemplo n.º 7
0
def test_owner_member_get_user_project_permissions():
    user1 = factories.UserFactory()
    project = factories.ProjectFactory()
    project.anon_permissions = ["test1"]
    project.public_permissions = ["test2"]
    role = factories.RoleFactory(permissions=["test3"])
    factories.MembershipFactory(user=user1, project=project, role=role, is_admin=True)

    expected_perms = set(
        ["test1", "test2", "test3"] +
        [x[0] for x in choices.ADMINS_PERMISSIONS] +
        [x[0] for x in choices.MEMBERS_PERMISSIONS]
    )
    assert services.get_user_project_permissions(user1, project) == expected_perms
Ejemplo n.º 8
0
def test_owner_member_get_user_project_permissions():
    user1 = factories.UserFactory()
    project = factories.ProjectFactory()
    project.anon_permissions = ["test1"]
    project.public_permissions = ["test2"]
    role = factories.RoleFactory(permissions=["test3"])
    factories.MembershipFactory(user=user1, project=project, role=role, is_admin=True)

    expected_perms = set(
        ["test1", "test2", "test3"] +
        [x[0] for x in choices.ADMINS_PERMISSIONS] +
        [x[0] for x in choices.MEMBERS_PERMISSIONS]
    )
    assert services.get_user_project_permissions(user1, project) == expected_perms
Ejemplo n.º 9
0
 def get_my_permissions(self, obj):
     if "request" in self.context:
         return get_user_project_permissions(self.context["request"].user, obj)
     return []
Ejemplo n.º 10
0
def test_anon_get_user_project_permissions():
    project = factories.ProjectFactory()
    project.anon_permissions = ["test1"]
    project.public_permissions = ["test2"]
    assert services.get_user_project_permissions(AnonymousUser(), project) == set(["test1"])
Ejemplo n.º 11
0
def test_anon_get_user_project_permissions():
    project = factories.ProjectFactory()
    project.anon_permissions = ["test1"]
    project.public_permissions = ["test2"]
    assert services.get_user_project_permissions(AnonymousUser(),
                                                 project) == set(["test1"])