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.superuser = f.UserFactory.create(is_superuser=True)

    m.public_project = f.ProjectFactory(is_private=False,
                                        anon_permissions=['view_project'],
                                        public_permissions=['view_project'])
    m.public_project = attach_extra_info(
        project_models.Project.objects.all()).get(id=m.public_project.id)

    m.private_project1 = f.ProjectFactory(is_private=True,
                                          anon_permissions=['view_project'],
                                          public_permissions=['view_project'],
                                          owner=m.project_owner)
    m.private_project1 = attach_extra_info(
        project_models.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_extra_info(
        project_models.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_extra_info(
        project_models.Project.objects.all()).get(id=m.blocked_project.id)

    f.RoleFactory(project=m.public_project)

    m.membership = 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)))
    m.membership = f.MembershipFactory(project=m.private_project1,
                                       user=m.project_member_without_perms,
                                       role__project=m.private_project1,
                                       role__permissions=[])
    m.membership = 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)))
    m.membership = f.MembershipFactory(project=m.private_project2,
                                       user=m.project_member_without_perms,
                                       role__project=m.private_project2,
                                       role__permissions=[])
    m.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)))
    m.membership = 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)

    ContentType = apps.get_model("contenttypes", "ContentType")
    Project = apps.get_model("projects", "Project")

    project_ct = ContentType.objects.get_for_model(Project)

    f.LikeFactory(content_type=project_ct,
                  object_id=m.public_project.pk,
                  user=m.project_member_with_perms)
    f.LikeFactory(content_type=project_ct,
                  object_id=m.public_project.pk,
                  user=m.project_owner)
    f.LikeFactory(content_type=project_ct,
                  object_id=m.private_project1.pk,
                  user=m.project_member_with_perms)
    f.LikeFactory(content_type=project_ct,
                  object_id=m.private_project1.pk,
                  user=m.project_owner)
    f.LikeFactory(content_type=project_ct,
                  object_id=m.private_project2.pk,
                  user=m.project_member_with_perms)
    f.LikeFactory(content_type=project_ct,
                  object_id=m.private_project2.pk,
                  user=m.project_owner)
    f.LikeFactory(content_type=project_ct,
                  object_id=m.blocked_project.pk,
                  user=m.project_member_with_perms)
    f.LikeFactory(content_type=project_ct,
                  object_id=m.blocked_project.pk,
                  user=m.project_owner)

    return m
Esempio n. 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.superuser = f.UserFactory.create(is_superuser=True)

    m.public_project = f.ProjectFactory(is_private=False,
                                        anon_permissions=['view_project'],
                                        public_permissions=['view_project'])
    m.private_project1 = f.ProjectFactory(is_private=True,
                                          anon_permissions=['view_project'],
                                          public_permissions=['view_project'],
                                          owner=m.project_owner)
    m.private_project2 = f.ProjectFactory(is_private=True,
                                          anon_permissions=[],
                                          public_permissions=[],
                                          owner=m.project_owner)

    f.RoleFactory(project=m.public_project)

    m.membership = 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)))
    m.membership = f.MembershipFactory(project=m.private_project1,
                                       user=m.project_member_without_perms,
                                       role__project=m.private_project1,
                                       role__permissions=[])
    m.membership = 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)))
    m.membership = f.MembershipFactory(project=m.private_project2,
                                       user=m.project_member_without_perms,
                                       role__project=m.private_project2,
                                       role__permissions=[])

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

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

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

    ContentType = apps.get_model("contenttypes", "ContentType")
    Project = apps.get_model("projects", "Project")

    project_ct = ContentType.objects.get_for_model(Project)

    f.LikeFactory(content_type=project_ct, object_id=m.public_project.pk, user=m.project_member_with_perms)
    f.LikeFactory(content_type=project_ct, object_id=m.public_project.pk, user=m.project_owner)
    f.LikeFactory(content_type=project_ct, object_id=m.private_project1.pk, user=m.project_member_with_perms)
    f.LikeFactory(content_type=project_ct, object_id=m.private_project1.pk, user=m.project_owner)
    f.LikeFactory(content_type=project_ct, object_id=m.private_project2.pk, user=m.project_member_with_perms)
    f.LikeFactory(content_type=project_ct, object_id=m.private_project2.pk, user=m.project_owner)

    f.LikesFactory(content_type=project_ct, object_id=m.public_project.pk, count=2)
    f.LikesFactory(content_type=project_ct, object_id=m.private_project1.pk, count=2)
    f.LikesFactory(content_type=project_ct, object_id=m.private_project2.pk, count=2)

    return m