def data():
    m = type("Models", (object,), {})

    m.registered_user = f.UserFactory.create()
    m.project_member_with_perms = f.UserFactory.create()
    m.project_member_without_perms = f.UserFactory.create()
    m.project_owner = f.UserFactory.create()
    m.other_user = f.UserFactory.create()

    m.public_project = f.ProjectFactory(is_private=False,
                                        anon_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)),
                                        public_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)) + ["comment_issue"],
                                        owner=m.project_owner,
                                        issues_csv_uuid=uuid.uuid4().hex)
    m.public_project = attach_project_extra_info(Project.objects.all()).get(id=m.public_project.id)

    m.private_project1 = f.ProjectFactory(is_private=True,
                                          anon_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)),
                                          public_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)),
                                          owner=m.project_owner,
                                          issues_csv_uuid=uuid.uuid4().hex)
    m.private_project1 = attach_project_extra_info(Project.objects.all()).get(id=m.private_project1.id)

    m.private_project2 = f.ProjectFactory(is_private=True,
                                          anon_permissions=[],
                                          public_permissions=[],
                                          owner=m.project_owner,
                                          issues_csv_uuid=uuid.uuid4().hex)
    m.private_project2 = attach_project_extra_info(Project.objects.all()).get(id=m.private_project2.id)

    m.blocked_project = f.ProjectFactory(is_private=True,
                                         anon_permissions=[],
                                         public_permissions=[],
                                         owner=m.project_owner,
                                         issues_csv_uuid=uuid.uuid4().hex,
                                         blocked_code=project_choices.BLOCKED_BY_STAFF)
    m.blocked_project = attach_project_extra_info(Project.objects.all()).get(id=m.blocked_project.id)

    m.public_membership = f.MembershipFactory(project=m.public_project,
                                              user=m.project_member_with_perms,
                                              role__project=m.public_project,
                                              role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))
    m.private_membership1 = f.MembershipFactory(project=m.private_project1,
                                                user=m.project_member_with_perms,
                                                role__project=m.private_project1,
                                                role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))
    f.MembershipFactory(project=m.private_project1,
                        user=m.project_member_without_perms,
                        role__project=m.private_project1,
                        role__permissions=[])
    m.private_membership2 = f.MembershipFactory(project=m.private_project2,
                                                user=m.project_member_with_perms,
                                                role__project=m.private_project2,
                                                role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))
    f.MembershipFactory(project=m.private_project2,
                        user=m.project_member_without_perms,
                        role__project=m.private_project2,
                        role__permissions=[])
    m.blocked_membership = f.MembershipFactory(project=m.blocked_project,
                                                user=m.project_member_with_perms,
                                                role__project=m.blocked_project,
                                                role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))
    f.MembershipFactory(project=m.blocked_project,
                        user=m.project_member_without_perms,
                        role__project=m.blocked_project,
                        role__permissions=[])

    f.MembershipFactory(project=m.public_project,
                        user=m.project_owner,
                        is_admin=True)

    f.MembershipFactory(project=m.private_project1,
                        user=m.project_owner,
                        is_admin=True)

    f.MembershipFactory(project=m.private_project2,
                        user=m.project_owner,
                        is_admin=True)

    f.MembershipFactory(project=m.blocked_project,
                    user=m.project_owner,
                    is_admin=True)

    m.public_issue = f.IssueFactory(project=m.public_project,
                                    status__project=m.public_project,
                                    severity__project=m.public_project,
                                    priority__project=m.public_project,
                                    type__project=m.public_project,
                                    milestone__project=m.public_project)
    m.public_issue = attach_issue_extra_info(Issue.objects.all()).get(id=m.public_issue.id)

    m.private_issue1 = f.IssueFactory(project=m.private_project1,
                                      status__project=m.private_project1,
                                      severity__project=m.private_project1,
                                      priority__project=m.private_project1,
                                      type__project=m.private_project1,
                                      milestone__project=m.private_project1)
    m.private_issue1 = attach_issue_extra_info(Issue.objects.all()).get(id=m.private_issue1.id)

    m.private_issue2 = f.IssueFactory(project=m.private_project2,
                                      status__project=m.private_project2,
                                      severity__project=m.private_project2,
                                      priority__project=m.private_project2,
                                      type__project=m.private_project2,
                                      milestone__project=m.private_project2)
    m.private_issue2 = attach_issue_extra_info(Issue.objects.all()).get(id=m.private_issue2.id)

    m.blocked_issue = f.IssueFactory(project=m.blocked_project,
                                     status__project=m.blocked_project,
                                     severity__project=m.blocked_project,
                                     priority__project=m.blocked_project,
                                     type__project=m.blocked_project,
                                     milestone__project=m.blocked_project)
    m.blocked_issue = attach_issue_extra_info(Issue.objects.all()).get(id=m.blocked_issue.id)

    return m
Example #2
0
def data():
    m = type("Models", (object,), {})

    m.registered_user = f.UserFactory.create()
    m.project_member_with_perms = f.UserFactory.create()
    m.project_member_without_perms = f.UserFactory.create()
    m.project_owner = f.UserFactory.create()
    m.other_user = f.UserFactory.create()

    m.public_project = f.ProjectFactory(is_private=False,
                                        anon_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)),
                                        public_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)) + ["comment_issue"],
                                        owner=m.project_owner,
                                        issues_csv_uuid=uuid.uuid4().hex)
    m.public_project = attach_project_extra_info(Project.objects.all()).get(id=m.public_project.id)

    m.private_project1 = f.ProjectFactory(is_private=True,
                                          anon_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)),
                                          public_permissions=list(map(lambda x: x[0], ANON_PERMISSIONS)),
                                          owner=m.project_owner,
                                          issues_csv_uuid=uuid.uuid4().hex)
    m.private_project1 = attach_project_extra_info(Project.objects.all()).get(id=m.private_project1.id)

    m.private_project2 = f.ProjectFactory(is_private=True,
                                          anon_permissions=[],
                                          public_permissions=[],
                                          owner=m.project_owner,
                                          issues_csv_uuid=uuid.uuid4().hex)
    m.private_project2 = attach_project_extra_info(Project.objects.all()).get(id=m.private_project2.id)

    m.blocked_project = f.ProjectFactory(is_private=True,
                                         anon_permissions=[],
                                         public_permissions=[],
                                         owner=m.project_owner,
                                         issues_csv_uuid=uuid.uuid4().hex,
                                         blocked_code=project_choices.BLOCKED_BY_STAFF)
    m.blocked_project = attach_project_extra_info(Project.objects.all()).get(id=m.blocked_project.id)

    m.public_membership = f.MembershipFactory(project=m.public_project,
                                              user=m.project_member_with_perms,
                                              role__project=m.public_project,
                                              role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))
    m.private_membership1 = f.MembershipFactory(project=m.private_project1,
                                                user=m.project_member_with_perms,
                                                role__project=m.private_project1,
                                                role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))
    f.MembershipFactory(project=m.private_project1,
                        user=m.project_member_without_perms,
                        role__project=m.private_project1,
                        role__permissions=[])
    m.private_membership2 = f.MembershipFactory(project=m.private_project2,
                                                user=m.project_member_with_perms,
                                                role__project=m.private_project2,
                                                role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))
    f.MembershipFactory(project=m.private_project2,
                        user=m.project_member_without_perms,
                        role__project=m.private_project2,
                        role__permissions=[])
    m.blocked_membership = f.MembershipFactory(project=m.blocked_project,
                                                user=m.project_member_with_perms,
                                                role__project=m.blocked_project,
                                                role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))
    f.MembershipFactory(project=m.blocked_project,
                        user=m.project_member_without_perms,
                        role__project=m.blocked_project,
                        role__permissions=[])

    f.MembershipFactory(project=m.public_project,
                        user=m.project_owner,
                        is_admin=True)

    f.MembershipFactory(project=m.private_project1,
                        user=m.project_owner,
                        is_admin=True)

    f.MembershipFactory(project=m.private_project2,
                        user=m.project_owner,
                        is_admin=True)

    f.MembershipFactory(project=m.blocked_project,
                    user=m.project_owner,
                    is_admin=True)

    m.public_issue = f.IssueFactory(project=m.public_project,
                                    status__project=m.public_project,
                                    severity__project=m.public_project,
                                    priority__project=m.public_project,
                                    type__project=m.public_project,
                                    milestone__project=m.public_project)
    m.public_issue = attach_issue_extra_info(Issue.objects.all()).get(id=m.public_issue.id)

    m.private_issue1 = f.IssueFactory(project=m.private_project1,
                                      status__project=m.private_project1,
                                      severity__project=m.private_project1,
                                      priority__project=m.private_project1,
                                      type__project=m.private_project1,
                                      milestone__project=m.private_project1)
    m.private_issue1 = attach_issue_extra_info(Issue.objects.all()).get(id=m.private_issue1.id)

    m.private_issue2 = f.IssueFactory(project=m.private_project2,
                                      status__project=m.private_project2,
                                      severity__project=m.private_project2,
                                      priority__project=m.private_project2,
                                      type__project=m.private_project2,
                                      milestone__project=m.private_project2)
    m.private_issue2 = attach_issue_extra_info(Issue.objects.all()).get(id=m.private_issue2.id)

    m.blocked_issue = f.IssueFactory(project=m.blocked_project,
                                     status__project=m.blocked_project,
                                     severity__project=m.blocked_project,
                                     priority__project=m.blocked_project,
                                     type__project=m.blocked_project,
                                     milestone__project=m.blocked_project)
    m.blocked_issue = attach_issue_extra_info(Issue.objects.all()).get(id=m.blocked_issue.id)

    return m
def test_issue_put_update_with_project_change(client):
    user1 = f.UserFactory.create()
    user2 = f.UserFactory.create()
    user3 = f.UserFactory.create()
    user4 = f.UserFactory.create()
    project1 = f.ProjectFactory()
    project2 = f.ProjectFactory()

    issue_status1 = f.IssueStatusFactory.create(project=project1)
    issue_status2 = f.IssueStatusFactory.create(project=project2)

    priority1 = f.PriorityFactory.create(project=project1)
    priority2 = f.PriorityFactory.create(project=project2)

    severity1 = f.SeverityFactory.create(project=project1)
    severity2 = f.SeverityFactory.create(project=project2)

    issue_type1 = f.IssueTypeFactory.create(project=project1)
    issue_type2 = f.IssueTypeFactory.create(project=project2)

    project1.default_issue_status = issue_status1
    project2.default_issue_status = issue_status2

    project1.default_priority = priority1
    project2.default_priority = priority2

    project1.default_severity = severity1
    project2.default_severity = severity2

    project1.default_issue_type = issue_type1
    project2.default_issue_type = issue_type2

    project1.save()
    project2.save()

    project1 = attach_project_extra_info(Project.objects.all()).get(id=project1.id)
    project2 = attach_project_extra_info(Project.objects.all()).get(id=project2.id)

    f.MembershipFactory(project=project1,
                        user=user1,
                        role__project=project1,
                        role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))
    f.MembershipFactory(project=project2,
                        user=user1,
                        role__project=project2,
                        role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))
    f.MembershipFactory(project=project1,
                        user=user2,
                        role__project=project1,
                        role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))
    f.MembershipFactory(project=project2,
                        user=user3,
                        role__project=project2,
                        role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))

    issue = f.IssueFactory.create(project=project1)
    issue = attach_issue_extra_info(Issue.objects.all()).get(id=issue.id)

    url = reverse('issues-detail', kwargs={"pk": issue.pk})

    # Test user with permissions in both projects
    client.login(user1)

    issue_data = IssueSerializer(issue).data
    issue_data["project"] = project2.id
    issue_data = json.dumps(issue_data)

    response = client.put(url, data=issue_data, content_type="application/json")

    assert response.status_code == 200

    issue.project = project1
    issue.save()

    # Test user with permissions in only origin project
    client.login(user2)

    issue_data = IssueSerializer(issue).data
    issue_data["project"] = project2.id
    issue_data = json.dumps(issue_data)

    response = client.put(url, data=issue_data, content_type="application/json")

    assert response.status_code == 403

    issue.project = project1
    issue.save()

    # Test user with permissions in only destionation project
    client.login(user3)

    issue_data = IssueSerializer(issue).data
    issue_data["project"] = project2.id
    issue_data = json.dumps(issue_data)

    response = client.put(url, data=issue_data, content_type="application/json")

    assert response.status_code == 403

    issue.project = project1
    issue.save()

    # Test user without permissions in the projects
    client.login(user4)

    issue_data = IssueSerializer(issue).data
    issue_data["project"] = project2.id
    issue_data = json.dumps(issue_data)

    response = client.put(url, data=issue_data, content_type="application/json")

    assert response.status_code == 403

    issue.project = project1
    issue.save()
Example #4
0
def test_issue_put_update_with_project_change(client):
    user1 = f.UserFactory.create()
    user2 = f.UserFactory.create()
    user3 = f.UserFactory.create()
    user4 = f.UserFactory.create()
    project1 = f.ProjectFactory()
    project2 = f.ProjectFactory()

    issue_status1 = f.IssueStatusFactory.create(project=project1)
    issue_status2 = f.IssueStatusFactory.create(project=project2)

    priority1 = f.PriorityFactory.create(project=project1)
    priority2 = f.PriorityFactory.create(project=project2)

    severity1 = f.SeverityFactory.create(project=project1)
    severity2 = f.SeverityFactory.create(project=project2)

    issue_type1 = f.IssueTypeFactory.create(project=project1)
    issue_type2 = f.IssueTypeFactory.create(project=project2)

    project1.default_issue_status = issue_status1
    project2.default_issue_status = issue_status2

    project1.default_priority = priority1
    project2.default_priority = priority2

    project1.default_severity = severity1
    project2.default_severity = severity2

    project1.default_issue_type = issue_type1
    project2.default_issue_type = issue_type2

    project1.save()
    project2.save()

    project1 = attach_project_extra_info(Project.objects.all()).get(id=project1.id)
    project2 = attach_project_extra_info(Project.objects.all()).get(id=project2.id)

    f.MembershipFactory(project=project1,
                        user=user1,
                        role__project=project1,
                        role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))
    f.MembershipFactory(project=project2,
                        user=user1,
                        role__project=project2,
                        role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))
    f.MembershipFactory(project=project1,
                        user=user2,
                        role__project=project1,
                        role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))
    f.MembershipFactory(project=project2,
                        user=user3,
                        role__project=project2,
                        role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS)))

    issue = f.IssueFactory.create(project=project1)
    issue = attach_issue_extra_info(Issue.objects.all()).get(id=issue.id)

    url = reverse('issues-detail', kwargs={"pk": issue.pk})

    # Test user with permissions in both projects
    client.login(user1)

    issue_data = IssueSerializer(issue).data
    issue_data["project"] = project2.id
    issue_data = json.dumps(issue_data)

    response = client.put(url, data=issue_data, content_type="application/json")

    assert response.status_code == 200

    issue.project = project1
    issue.save()

    # Test user with permissions in only origin project
    client.login(user2)

    issue_data = IssueSerializer(issue).data
    issue_data["project"] = project2.id
    issue_data = json.dumps(issue_data)

    response = client.put(url, data=issue_data, content_type="application/json")

    assert response.status_code == 403

    issue.project = project1
    issue.save()

    # Test user with permissions in only destionation project
    client.login(user3)

    issue_data = IssueSerializer(issue).data
    issue_data["project"] = project2.id
    issue_data = json.dumps(issue_data)

    response = client.put(url, data=issue_data, content_type="application/json")

    assert response.status_code == 403

    issue.project = project1
    issue.save()

    # Test user without permissions in the projects
    client.login(user4)

    issue_data = IssueSerializer(issue).data
    issue_data["project"] = project2.id
    issue_data = json.dumps(issue_data)

    response = client.put(url, data=issue_data, content_type="application/json")

    assert response.status_code == 403

    issue.project = project1
    issue.save()