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_epic"],
        owner=m.project_owner,
        epics_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,
        epics_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,
                                          epics_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,
        epics_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_epic = f.EpicFactory(project=m.public_project,
                                  status__project=m.public_project)
    m.public_epic = attach_epic_extra_info(
        Epic.objects.all()).get(id=m.public_epic.id)

    m.private_epic1 = f.EpicFactory(project=m.private_project1,
                                    status__project=m.private_project1)
    m.private_epic1 = attach_epic_extra_info(
        Epic.objects.all()).get(id=m.private_epic1.id)

    m.private_epic2 = f.EpicFactory(project=m.private_project2,
                                    status__project=m.private_project2)
    m.private_epic2 = attach_epic_extra_info(
        Epic.objects.all()).get(id=m.private_epic2.id)

    m.blocked_epic = f.EpicFactory(project=m.blocked_project,
                                   status__project=m.blocked_project)
    m.blocked_epic = attach_epic_extra_info(
        Epic.objects.all()).get(id=m.blocked_epic.id)

    m.public_us = f.UserStoryFactory(project=m.public_project)
    m.private_us1 = f.UserStoryFactory(project=m.private_project1)
    m.private_us2 = f.UserStoryFactory(project=m.private_project2)
    m.blocked_us = f.UserStoryFactory(project=m.blocked_project)

    m.public_related_us = f.RelatedUserStory(epic=m.public_epic,
                                             user_story=m.public_us)
    m.private_related_us1 = f.RelatedUserStory(epic=m.private_epic1,
                                               user_story=m.private_us1)
    m.private_related_us2 = f.RelatedUserStory(epic=m.private_epic2,
                                               user_story=m.private_us2)
    m.blocked_related_us = f.RelatedUserStory(epic=m.blocked_epic,
                                              user_story=m.blocked_us)

    m.public_project.default_epic_status = m.public_epic.status
    m.public_project.save()
    m.private_project1.default_epic_status = m.private_epic1.status
    m.private_project1.save()
    m.private_project2.default_epic_status = m.private_epic2.status
    m.private_project2.save()
    m.blocked_project.default_epic_status = m.blocked_epic.status
    m.blocked_project.save()

    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_points = f.PointsFactory()
    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_us"],
        owner=m.project_owner,
        userstories_csv_uuid=uuid.uuid4().hex,
        default_points=m.public_points)
    m.public_project = attach_project_extra_info(
        Project.objects.all()).get(id=m.public_project.id)

    m.private_points1 = f.PointsFactory()
    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,
        userstories_csv_uuid=uuid.uuid4().hex,
        default_points=m.private_points1)
    m.private_project1 = attach_project_extra_info(
        Project.objects.all()).get(id=m.private_project1.id)

    m.private_sprint1 = f.MilestoneFactory.create(project=m.private_project1,
                                                  owner=m.project_owner)

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

    m.blocked_points = f.PointsFactory()
    m.blocked_project = f.ProjectFactory(
        is_private=True,
        anon_permissions=[],
        public_permissions=[],
        owner=m.project_owner,
        userstories_csv_uuid=uuid.uuid4().hex,
        blocked_code=project_choices.BLOCKED_BY_STAFF,
        default_points=m.blocked_points)
    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_user_story = f.UserStoryFactory(
        project=m.public_project,
        milestone__project=m.public_project,
        status__project=m.public_project)
    m.public_user_story = attach_userstory_extra_info(
        UserStory.objects.all()).get(id=m.public_user_story.id)

    m.private_user_story1 = f.UserStoryFactory(
        project=m.private_project1,
        milestone__project=m.private_project1,
        status__project=m.private_project1)
    m.private_user_story1 = attach_userstory_extra_info(
        UserStory.objects.all()).get(id=m.private_user_story1.id)

    m.private_user_story2 = f.UserStoryFactory(
        project=m.private_project2,
        milestone__project=m.private_project2,
        status__project=m.private_project2)
    m.private_user_story2 = attach_userstory_extra_info(
        UserStory.objects.all()).get(id=m.private_user_story2.id)

    m.blocked_user_story = f.UserStoryFactory(
        project=m.blocked_project,
        milestone__project=m.blocked_project,
        status__project=m.blocked_project)
    m.blocked_user_story = attach_userstory_extra_info(
        UserStory.objects.all()).get(id=m.blocked_user_story.id)

    return m
def test_epic_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()

    epic_status1 = f.EpicStatusFactory.create(project=project1)
    epic_status2 = f.EpicStatusFactory.create(project=project2)

    project1.default_epic_status = epic_status1
    project2.default_epic_status = epic_status2

    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)))

    epic = f.EpicFactory.create(project=project1)
    epic = attach_epic_extra_info(Epic.objects.all()).get(id=epic.id)

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

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

    epic_data = EpicSerializer(epic).data
    epic_data["project"] = project2.id
    epic_data = json.dumps(epic_data)

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

    assert response.status_code == 200

    epic.project = project1
    epic.save()

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

    epic_data = EpicSerializer(epic).data
    epic_data["project"] = project2.id
    epic_data = json.dumps(epic_data)

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

    assert response.status_code == 403

    epic.project = project1
    epic.save()

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

    epic_data = EpicSerializer(epic).data
    epic_data["project"] = project2.id
    epic_data = json.dumps(epic_data)

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

    assert response.status_code == 403

    epic.project = project1
    epic.save()

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

    epic_data = EpicSerializer(epic).data
    epic_data["project"] = project2.id
    epic_data = json.dumps(epic_data)

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

    assert response.status_code == 403

    epic.project = project1
    epic.save()
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_points = f.PointsFactory()
    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_us"],
                                        owner=m.project_owner,
                                        userstories_csv_uuid=uuid.uuid4().hex,
                                        default_points=m.public_points)
    m.public_project = attach_project_extra_info(Project.objects.all()).get(id=m.public_project.id)

    m.private_points1 = f.PointsFactory()
    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,
                                          userstories_csv_uuid=uuid.uuid4().hex,
                                          default_points=m.private_points1)
    m.private_project1 = attach_project_extra_info(Project.objects.all()).get(id=m.private_project1.id)

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

    m.blocked_points = f.PointsFactory()
    m.blocked_project = f.ProjectFactory(is_private=True,
                                         anon_permissions=[],
                                         public_permissions=[],
                                         owner=m.project_owner,
                                         userstories_csv_uuid=uuid.uuid4().hex,
                                         blocked_code=project_choices.BLOCKED_BY_STAFF,
                                         default_points=m.blocked_points)
    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_user_story = f.UserStoryFactory(project=m.public_project,
                                             milestone__project=m.public_project,
                                             status__project=m.public_project)
    m.public_user_story = attach_userstory_extra_info(UserStory.objects.all()).get(id=m.public_user_story.id)

    m.private_user_story1 = f.UserStoryFactory(project=m.private_project1,
                                             milestone__project=m.private_project1,
                                             status__project=m.private_project1)
    m.private_user_story1 = attach_userstory_extra_info(UserStory.objects.all()).get(id=m.private_user_story1.id)

    m.private_user_story2 = f.UserStoryFactory(project=m.private_project2,
                                             milestone__project=m.private_project2,
                                             status__project=m.private_project2)
    m.private_user_story2 = attach_userstory_extra_info(UserStory.objects.all()).get(id=m.private_user_story2.id)

    m.blocked_user_story = f.UserStoryFactory(project=m.blocked_project,
                                             milestone__project=m.blocked_project,
                                             status__project=m.blocked_project)
    m.blocked_user_story = attach_userstory_extra_info(UserStory.objects.all()).get(id=m.blocked_user_story.id)

    return m
Example #5
0
def test_user_story_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()

    us_status1 = f.UserStoryStatusFactory.create(project=project1)
    us_status2 = f.UserStoryStatusFactory.create(project=project2)
    points1 = f.PointsFactory.create(project=project1)
    points2 = f.PointsFactory.create(project=project2)

    project1.default_us_status = us_status1
    project2.default_us_status = us_status2
    project1.default_points = points1
    project2.default_points = points2

    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)))

    us = f.UserStoryFactory.create(project=project1)
    us = attach_userstory_extra_info(UserStory.objects.all()).get(id=us.id)

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

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

    us_data = UserStorySerializer(us).data
    us_data["project"] = project2.id
    del us_data["points"]
    us_data = json.dumps(us_data)

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

    assert response.status_code == 200

    us.project = project1
    us.save()

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

    us_data = UserStorySerializer(us).data
    us_data["project"] = project2.id
    del us_data["points"]
    us_data = json.dumps(us_data)

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

    assert response.status_code == 403

    us.project = project1
    us.save()

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

    us_data = UserStorySerializer(us).data
    us_data["project"] = project2.id
    del us_data["points"]
    us_data = json.dumps(us_data)

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

    assert response.status_code == 403

    us.project = project1
    us.save()

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

    us_data = UserStorySerializer(us).data
    us_data["project"] = project2.id
    del us_data["points"]
    us_data = json.dumps(us_data)

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

    assert response.status_code == 403

    us.project = project1
    us.save()
Example #6
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()
def test_user_story_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()

    us_status1 = f.UserStoryStatusFactory.create(project=project1)
    us_status2 = f.UserStoryStatusFactory.create(project=project2)
    points1 = f.PointsFactory.create(project=project1)
    points2 = f.PointsFactory.create(project=project2)

    project1.default_us_status = us_status1
    project2.default_us_status = us_status2
    project1.default_points = points1
    project2.default_points = points2

    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)))

    us = f.UserStoryFactory.create(project=project1)
    us = attach_userstory_extra_info(UserStory.objects.all()).get(id=us.id)

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

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

    us_data = UserStorySerializer(us).data
    us_data["project"] = project2.id
    del us_data["points"]
    us_data = json.dumps(us_data)

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

    assert response.status_code == 200

    us.project = project1
    us.save()

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

    us_data = UserStorySerializer(us).data
    us_data["project"] = project2.id
    del us_data["points"]
    us_data = json.dumps(us_data)

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

    assert response.status_code == 403

    us.project = project1
    us.save()

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

    us_data = UserStorySerializer(us).data
    us_data["project"] = project2.id
    del us_data["points"]
    us_data = json.dumps(us_data)

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

    assert response.status_code == 403

    us.project = project1
    us.save()

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

    us_data = UserStorySerializer(us).data
    us_data["project"] = project2.id
    del us_data["points"]
    us_data = json.dumps(us_data)

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

    assert response.status_code == 403

    us.project = project1
    us.save()
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_task"],
                                        owner=m.project_owner,
                                        tasks_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,
                                          tasks_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,
                                          tasks_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,
                                         tasks_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)

    milestone_public_task = f.MilestoneFactory(project=m.public_project)
    milestone_private_task1 = f.MilestoneFactory(project=m.private_project1)
    milestone_private_task2 = f.MilestoneFactory(project=m.private_project2)
    milestone_blocked_task = f.MilestoneFactory(project=m.blocked_project)

    m.public_task = f.TaskFactory(project=m.public_project,
                                  status__project=m.public_project,
                                  milestone=milestone_public_task,
                                  user_story__project=m.public_project,
                                  user_story__milestone=milestone_public_task)
    m.public_task = attach_task_extra_info(Task.objects.all()).get(id=m.public_task.id)

    m.private_task1 = f.TaskFactory(project=m.private_project1,
                                    status__project=m.private_project1,
                                    milestone=milestone_private_task1,
                                    user_story__project=m.private_project1,
                                    user_story__milestone=milestone_private_task1)
    m.private_task1 = attach_task_extra_info(Task.objects.all()).get(id=m.private_task1.id)

    m.private_task2 = f.TaskFactory(project=m.private_project2,
                                    status__project=m.private_project2,
                                    milestone=milestone_private_task2,
                                    user_story__project=m.private_project2,
                                    user_story__milestone=milestone_private_task2)
    m.private_task2 = attach_task_extra_info(Task.objects.all()).get(id=m.private_task2.id)

    m.blocked_task = f.TaskFactory(project=m.blocked_project,
                                   status__project=m.blocked_project,
                                   milestone=milestone_blocked_task,
                                   user_story__project=m.blocked_project,
                                   user_story__milestone=milestone_blocked_task)
    m.blocked_task = attach_task_extra_info(Task.objects.all()).get(id=m.blocked_task.id)

    m.public_project.default_task_status = m.public_task.status
    m.public_project.save()
    m.private_project1.default_task_status = m.private_task1.status
    m.private_project1.save()
    m.private_project2.default_task_status = m.private_task2.status
    m.private_project2.save()
    m.blocked_project.default_task_status = m.blocked_task.status
    m.blocked_project.save()

    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 #10
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)),
        owner=m.project_owner)
    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)
    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)
    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,
        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_milestone = f.MilestoneFactory(project=m.public_project)
    m.public_milestone = attach_milestone_extra_info(
        Milestone.objects.all()).get(id=m.public_milestone.id)
    m.private_milestone1 = f.MilestoneFactory(project=m.private_project1)
    m.private_milestone1 = attach_milestone_extra_info(
        Milestone.objects.all()).get(id=m.private_milestone1.id)
    m.private_milestone2 = f.MilestoneFactory(project=m.private_project2)
    m.private_milestone2 = attach_milestone_extra_info(
        Milestone.objects.all()).get(id=m.private_milestone2.id)
    m.blocked_milestone = f.MilestoneFactory(project=m.blocked_project)
    m.blocked_milestone = attach_milestone_extra_info(
        Milestone.objects.all()).get(id=m.blocked_milestone.id)

    return m
def test_task_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()

    task_status1 = f.TaskStatusFactory.create(project=project1)
    task_status2 = f.TaskStatusFactory.create(project=project2)

    project1.default_task_status = task_status1
    project2.default_task_status = task_status2

    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)))

    task = f.TaskFactory.create(project=project1)
    task = attach_task_extra_info(Task.objects.all()).get(id=task.id)

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

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

    task_data = TaskSerializer(task).data
    task_data["project"] = project2.id
    task_data = json.dumps(task_data)

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

    assert response.status_code == 200

    task.project = project1
    task.save()

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

    task_data = TaskSerializer(task).data
    task_data["project"] = project2.id
    task_data = json.dumps(task_data)

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

    assert response.status_code == 403

    task.project = project1
    task.save()

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

    task_data = TaskSerializer(task).data
    task_data["project"] = project2.id
    task_data = json.dumps(task_data)

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

    assert response.status_code == 403

    task.project = project1
    task.save()

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

    task_data = TaskSerializer(task).data
    task_data["project"] = project2.id
    task_data = json.dumps(task_data)

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

    assert response.status_code == 403

    task.project = project1
    task.save()
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_epic"],
                                        owner=m.project_owner,
                                        epics_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,
                                          epics_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,
                                          epics_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,
                                         epics_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_epic = f.EpicFactory(project=m.public_project,
                                  status__project=m.public_project)
    m.public_epic = attach_epic_extra_info(Epic.objects.all()).get(id=m.public_epic.id)

    m.private_epic1 = f.EpicFactory(project=m.private_project1,
                                    status__project=m.private_project1)
    m.private_epic1 = attach_epic_extra_info(Epic.objects.all()).get(id=m.private_epic1.id)

    m.private_epic2 = f.EpicFactory(project=m.private_project2,
                                    status__project=m.private_project2)
    m.private_epic2 = attach_epic_extra_info(Epic.objects.all()).get(id=m.private_epic2.id)

    m.blocked_epic = f.EpicFactory(project=m.blocked_project,
                                   status__project=m.blocked_project)
    m.blocked_epic = attach_epic_extra_info(Epic.objects.all()).get(id=m.blocked_epic.id)


    m.public_us = f.UserStoryFactory(project=m.public_project)
    m.private_us1 = f.UserStoryFactory(project=m.private_project1)
    m.private_us2 = f.UserStoryFactory(project=m.private_project2)
    m.blocked_us = f.UserStoryFactory(project=m.blocked_project)

    m.public_related_us = f.RelatedUserStory(epic=m.public_epic, user_story=m.public_us)
    m.private_related_us1 = f.RelatedUserStory(epic=m.private_epic1, user_story=m.private_us1)
    m.private_related_us2 = f.RelatedUserStory(epic=m.private_epic2, user_story=m.private_us2)
    m.blocked_related_us = f.RelatedUserStory(epic=m.blocked_epic, user_story=m.blocked_us)

    m.public_project.default_epic_status = m.public_epic.status
    m.public_project.save()
    m.private_project1.default_epic_status = m.private_epic1.status
    m.private_project1.save()
    m.private_project2.default_epic_status = m.private_epic2.status
    m.private_project2.save()
    m.blocked_project.default_epic_status = m.blocked_epic.status
    m.blocked_project.save()

    return m
def test_epic_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()

    epic_status1 = f.EpicStatusFactory.create(project=project1)
    epic_status2 = f.EpicStatusFactory.create(project=project2)

    project1.default_epic_status = epic_status1
    project2.default_epic_status = epic_status2

    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)))

    epic = f.EpicFactory.create(project=project1)
    epic = attach_epic_extra_info(Epic.objects.all()).get(id=epic.id)

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

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

    epic_data = EpicSerializer(epic).data
    epic_data["project"] = project2.id
    epic_data = json.dumps(epic_data)

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

    assert response.status_code == 200

    epic.project = project1
    epic.save()

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

    epic_data = EpicSerializer(epic).data
    epic_data["project"] = project2.id
    epic_data = json.dumps(epic_data)

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

    assert response.status_code == 403

    epic.project = project1
    epic.save()

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

    epic_data = EpicSerializer(epic).data
    epic_data["project"] = project2.id
    epic_data = json.dumps(epic_data)

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

    assert response.status_code == 403

    epic.project = project1
    epic.save()

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

    epic_data = EpicSerializer(epic).data
    epic_data["project"] = project2.id
    epic_data = json.dumps(epic_data)

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

    assert response.status_code == 403

    epic.project = project1
    epic.save()
Example #14
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_task_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()

    task_status1 = f.TaskStatusFactory.create(project=project1)
    task_status2 = f.TaskStatusFactory.create(project=project2)

    project1.default_task_status = task_status1
    project2.default_task_status = task_status2

    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)))

    task = f.TaskFactory.create(project=project1)
    task = attach_task_extra_info(Task.objects.all()).get(id=task.id)

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

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

    task_data = TaskSerializer(task).data
    task_data["project"] = project2.id
    task_data = json.dumps(task_data)

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

    assert response.status_code == 200

    task.project = project1
    task.save()

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

    task_data = TaskSerializer(task).data
    task_data["project"] = project2.id
    task_data = json.dumps(task_data)

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

    assert response.status_code == 403

    task.project = project1
    task.save()

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

    task_data = TaskSerializer(task).data
    task_data["project"] = project2.id
    task_data = json.dumps(task_data)

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

    assert response.status_code == 403

    task.project = project1
    task.save()

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

    task_data = TaskSerializer(task).data
    task_data["project"] = project2.id
    task_data = json.dumps(task_data)

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

    assert response.status_code == 403

    task.project = project1
    task.save()
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 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_task"],
        owner=m.project_owner,
        tasks_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,
        tasks_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,
                                          tasks_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,
        tasks_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)

    milestone_public_task = f.MilestoneFactory(project=m.public_project)
    milestone_private_task1 = f.MilestoneFactory(project=m.private_project1)
    milestone_private_task2 = f.MilestoneFactory(project=m.private_project2)
    milestone_blocked_task = f.MilestoneFactory(project=m.blocked_project)

    m.public_task = f.TaskFactory(project=m.public_project,
                                  status__project=m.public_project,
                                  milestone=milestone_public_task,
                                  user_story__project=m.public_project,
                                  user_story__milestone=milestone_public_task)
    m.public_task = attach_task_extra_info(
        Task.objects.all()).get(id=m.public_task.id)

    m.private_task1 = f.TaskFactory(
        project=m.private_project1,
        status__project=m.private_project1,
        milestone=milestone_private_task1,
        user_story__project=m.private_project1,
        user_story__milestone=milestone_private_task1)
    m.private_task1 = attach_task_extra_info(
        Task.objects.all()).get(id=m.private_task1.id)

    m.private_task2 = f.TaskFactory(
        project=m.private_project2,
        status__project=m.private_project2,
        milestone=milestone_private_task2,
        user_story__project=m.private_project2,
        user_story__milestone=milestone_private_task2)
    m.private_task2 = attach_task_extra_info(
        Task.objects.all()).get(id=m.private_task2.id)

    m.blocked_task = f.TaskFactory(
        project=m.blocked_project,
        status__project=m.blocked_project,
        milestone=milestone_blocked_task,
        user_story__project=m.blocked_project,
        user_story__milestone=milestone_blocked_task)
    m.blocked_task = attach_task_extra_info(
        Task.objects.all()).get(id=m.blocked_task.id)

    m.public_project.default_task_status = m.public_task.status
    m.public_project.save()
    m.private_project1.default_task_status = m.private_task1.status
    m.private_project1.save()
    m.private_project2.default_task_status = m.private_task2.status
    m.private_project2.save()
    m.blocked_project.default_task_status = m.blocked_task.status
    m.blocked_project.save()

    return m
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)),
                                        owner=m.project_owner)
    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)
    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)
    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,
                                         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_milestone = f.MilestoneFactory(project=m.public_project)
    m.public_milestone = attach_milestone_extra_info(Milestone.objects.all()).get(id=m.public_milestone.id)
    m.private_milestone1 = f.MilestoneFactory(project=m.private_project1)
    m.private_milestone1 = attach_milestone_extra_info(Milestone.objects.all()).get(id=m.private_milestone1.id)
    m.private_milestone2 = f.MilestoneFactory(project=m.private_project2)
    m.private_milestone2 = attach_milestone_extra_info(Milestone.objects.all()).get(id=m.private_milestone2.id)
    m.blocked_milestone = f.MilestoneFactory(project=m.blocked_project)
    m.blocked_milestone = attach_milestone_extra_info(Milestone.objects.all()).get(id=m.blocked_milestone.id)

    return m