Пример #1
0
def test_add_to_object_timeline():
    Timeline.objects.all().delete()
    user1 = factories.UserFactory()
    task = factories.TaskFactory()

    service.register_timeline_implementation("tasks.task", "test", lambda x, extra_data=None: str(id(x)))

    service._add_to_object_timeline(user1, task, "test", task.created_date)

    assert Timeline.objects.filter(object_id=user1.id).count() == 2
    assert Timeline.objects.order_by("-id")[0].data == id(task)
Пример #2
0
def test_filter_timeline_no_privileges():
    Timeline.objects.all().delete()
    user1 = factories.UserFactory()
    user2 = factories.UserFactory()
    task1= factories.TaskFactory()

    service.register_timeline_implementation("tasks.task", "test", lambda x, extra_data=None: str(id(x)))
    service._add_to_object_timeline(user1, task1, "test", task1.created_date)
    timeline = Timeline.objects.exclude(event_type="users.user.create")
    timeline = service.filter_timeline_for_user(timeline, user2)
    assert timeline.count() == 0
Пример #3
0
def test_add_to_object_timeline():
    Timeline.objects.all().delete()
    user1 = factories.UserFactory()
    user2 = factories.UserFactory()

    service.register_timeline_implementation("users.user", "test", lambda x, extra_data=None: str(id(x)))

    service._add_to_object_timeline(user1, user2, "test")

    assert Timeline.objects.filter(object_id=user1.id).count() == 1
    assert Timeline.objects.order_by("-id")[0].data == id(user2)
Пример #4
0
def test_filter_timeline_no_privileges():
    Timeline.objects.all().delete()
    user1 = factories.UserFactory()
    user2 = factories.UserFactory()
    task1= factories.TaskFactory()

    service.register_timeline_implementation("tasks.task", "test", lambda x, extra_data=None: str(id(x)))
    service._add_to_object_timeline(user1, task1, "test", task1.created_date)
    timeline = Timeline.objects.exclude(event_type="users.user.create")
    timeline = service.filter_timeline_for_user(timeline, user2)
    assert timeline.count() == 0
Пример #5
0
def test_add_to_object_timeline():
    Timeline.objects.all().delete()
    user1 = factories.UserFactory()
    task = factories.TaskFactory()

    service.register_timeline_implementation("tasks.task", "test", lambda x, extra_data=None: str(id(x)))

    service._add_to_object_timeline(user1, task, "test", task.created_date)

    assert Timeline.objects.filter(object_id=user1.id).count() == 2
    assert Timeline.objects.order_by("-id")[0].data == id(task)
Пример #6
0
def test_add_to_object_timeline():
    Timeline.objects.all().delete()
    user1 = factories.UserFactory()
    user2 = factories.UserFactory()

    service.register_timeline_implementation(
        "users.user", "test", lambda x, extra_data=None: str(id(x)))

    service._add_to_object_timeline(user1, user2, "test")

    assert Timeline.objects.filter(object_id=user1.id).count() == 1
    assert Timeline.objects.order_by("-id")[0].data == id(user2)
Пример #7
0
def test_filter_timeline_public_project():
    Timeline.objects.all().delete()
    user1 = factories.UserFactory()
    user2 = factories.UserFactory()
    project = factories.ProjectFactory.create(is_private=False)
    task1= factories.TaskFactory()
    task2= factories.TaskFactory.create(project=project)

    service.register_timeline_implementation("tasks.task", "test", lambda x, extra_data=None: str(id(x)))
    service._add_to_object_timeline(user1, task1, "test")
    service._add_to_object_timeline(user1, task2, "test")
    timeline = Timeline.objects.all()
    timeline = service.filter_timeline_for_user(timeline, user2)
    assert timeline.count() == 1
Пример #8
0
def test_filter_timeline_private_project_anon_permissions():
    Timeline.objects.all().delete()
    user1 = factories.UserFactory()
    user2 = factories.UserFactory()
    project = factories.ProjectFactory.create(is_private=True, anon_permissions= ["view_tasks"])
    task1= factories.TaskFactory()
    task2= factories.TaskFactory.create(project=project)

    service.register_timeline_implementation("tasks.task", "test", lambda x, extra_data=None: str(id(x)))
    service._add_to_object_timeline(user1, task1, "test", task1.created_date)
    service._add_to_object_timeline(user1, task2, "test", task2.created_date)
    timeline = Timeline.objects.exclude(event_type="users.user.create")
    timeline = service.filter_timeline_for_user(timeline, user2)
    assert timeline.count() == 1
Пример #9
0
def test_filter_timeline_private_project_anon_permissions():
    Timeline.objects.all().delete()
    user1 = factories.UserFactory()
    user2 = factories.UserFactory()
    project = factories.ProjectFactory.create(is_private=True, anon_permissions= ["view_tasks"])
    task1= factories.TaskFactory()
    task2= factories.TaskFactory.create(project=project)

    service.register_timeline_implementation("tasks.task", "test", lambda x, extra_data=None: str(id(x)))
    service._add_to_object_timeline(user1, task1, "test", task1.created_date)
    service._add_to_object_timeline(user1, task2, "test", task2.created_date)
    timeline = Timeline.objects.exclude(event_type="users.user.create")
    timeline = service.filter_timeline_for_user(timeline, user2)
    assert timeline.count() == 1
Пример #10
0
def test_filter_timeline_private_project_member_admin():
    Timeline.objects.all().delete()
    user1 = factories.UserFactory()
    user2 = factories.UserFactory()
    project = factories.ProjectFactory.create(is_private=True)
    membership = factories.MembershipFactory.create(user=user2, project=project, is_admin=True)
    task1= factories.TaskFactory()
    task2= factories.TaskFactory.create(project=project)

    service.register_timeline_implementation("tasks.task", "test", lambda x, extra_data=None: id(x))
    service._add_to_object_timeline(user1, task1, "test", task1.created_date)
    service._add_to_object_timeline(user1, task2, "test", task2.created_date)
    timeline = Timeline.objects.exclude(event_type="users.user.create")
    timeline = service.filter_timeline_for_user(timeline, user2)
    assert timeline.count() == 3
Пример #11
0
def test_filter_timeline_public_project():
    Timeline.objects.all().delete()
    user1 = factories.UserFactory()
    user2 = factories.UserFactory()
    project = factories.ProjectFactory.create(is_private=False)
    task1 = factories.TaskFactory()
    task2 = factories.TaskFactory.create(project=project)

    service.register_timeline_implementation(
        "tasks.task", "test", lambda x, extra_data=None: str(id(x)))
    service._add_to_object_timeline(user1, task1, "test")
    service._add_to_object_timeline(user1, task2, "test")
    timeline = Timeline.objects.all()
    timeline = service.filter_timeline_for_user(timeline, user2)
    assert timeline.count() == 1
Пример #12
0
def test_filter_timeline_private_project_member_admin():
    Timeline.objects.all().delete()
    user1 = factories.UserFactory()
    user2 = factories.UserFactory()
    project = factories.ProjectFactory.create(is_private=True)
    membership = factories.MembershipFactory.create(user=user2, project=project, is_admin=True)
    task1= factories.TaskFactory()
    task2= factories.TaskFactory.create(project=project)

    service.register_timeline_implementation("tasks.task", "test", lambda x, extra_data=None: id(x))
    service._add_to_object_timeline(user1, task1, "test", task1.created_date)
    service._add_to_object_timeline(user1, task2, "test", task2.created_date)
    timeline = Timeline.objects.exclude(event_type="users.user.create")
    timeline = service.filter_timeline_for_user(timeline, user2)
    assert timeline.count() == 3
Пример #13
0
def test_filter_timeline_private_project_member_permissions():
    Timeline.objects.all().delete()
    user1 = factories.UserFactory()
    user2 = factories.UserFactory()
    project = factories.ProjectFactory.create(is_private=True)
    membership = factories.MembershipFactory.create(user=user2, project=project)
    membership.role.permissions = ["view_tasks"]
    membership.role.save()
    task1= factories.TaskFactory()
    task2= factories.TaskFactory.create(project=project)

    service.register_timeline_implementation("tasks.task", "test", lambda x, extra_data=None: str(id(x)))
    service._add_to_object_timeline(user1, task1, "test")
    service._add_to_object_timeline(user1, task2, "test")
    timeline = Timeline.objects.all()
    timeline = service.filter_timeline_for_user(timeline, user2)
    assert timeline.count() == 1
Пример #14
0
def test_filter_timeline_private_project_member_permissions():
    Timeline.objects.all().delete()
    user1 = factories.UserFactory()
    user2 = factories.UserFactory()
    project = factories.ProjectFactory.create(is_private=True)
    membership = factories.MembershipFactory.create(user=user2,
                                                    project=project)
    membership.role.permissions = ["view_tasks"]
    membership.role.save()
    task1 = factories.TaskFactory()
    task2 = factories.TaskFactory.create(project=project)

    service.register_timeline_implementation(
        "tasks.task", "test", lambda x, extra_data=None: str(id(x)))
    service._add_to_object_timeline(user1, task1, "test")
    service._add_to_object_timeline(user1, task2, "test")
    timeline = Timeline.objects.all()
    timeline = service.filter_timeline_for_user(timeline, user2)
    assert timeline.count() == 1
Пример #15
0
def test_get_timeline():
    Timeline.objects.all().delete()

    user1 = factories.UserFactory()
    user2 = factories.UserFactory()
    user3 = factories.UserFactory()
    user4 = factories.UserFactory()

    service.register_timeline_implementation("users.user", "test", lambda x, extra_data=None: str(id(x)))

    service._add_to_object_timeline(user1, user1, "test")
    service._add_to_object_timeline(user1, user2, "test")
    service._add_to_object_timeline(user1, user3, "test")
    service._add_to_object_timeline(user1, user4, "test")

    service._add_to_object_timeline(user2, user1, "test")

    assert service.get_timeline(user1).count() == 4
    assert service.get_timeline(user2).count() == 1
    assert service.get_timeline(user3).count() == 0
Пример #16
0
def test_get_timeline():
    Timeline.objects.all().delete()

    user1 = factories.UserFactory()
    user2 = factories.UserFactory()
    user3 = factories.UserFactory()
    user4 = factories.UserFactory()

    service.register_timeline_implementation(
        "users.user", "test", lambda x, extra_data=None: str(id(x)))

    service._add_to_object_timeline(user1, user1, "test")
    service._add_to_object_timeline(user1, user2, "test")
    service._add_to_object_timeline(user1, user3, "test")
    service._add_to_object_timeline(user1, user4, "test")

    service._add_to_object_timeline(user2, user1, "test")

    assert service.get_timeline(user1).count() == 4
    assert service.get_timeline(user2).count() == 1
    assert service.get_timeline(user3).count() == 0
Пример #17
0
def test_get_timeline():
    Timeline.objects.all().delete()

    user1 = factories.UserFactory()
    user2 = factories.UserFactory()
    user3 = factories.UserFactory()
    task1= factories.TaskFactory()
    task2= factories.TaskFactory()
    task3= factories.TaskFactory()
    task4= factories.TaskFactory()

    service.register_timeline_implementation("tasks.task", "test", lambda x, extra_data=None: str(id(x)))

    service._add_to_object_timeline(user1, task1, "test", task1.created_date)
    service._add_to_object_timeline(user1, task2, "test", task2.created_date)
    service._add_to_object_timeline(user1, task3, "test", task3.created_date)
    service._add_to_object_timeline(user1, task4, "test", task4.created_date)
    service._add_to_object_timeline(user2, task1, "test", task1.created_date)

    assert Timeline.objects.filter(object_id=user1.id).count() == 5
    assert Timeline.objects.filter(object_id=user2.id).count() == 2
    assert Timeline.objects.filter(object_id=user3.id).count() == 1
Пример #18
0
def test_get_timeline():
    Timeline.objects.all().delete()

    user1 = factories.UserFactory()
    user2 = factories.UserFactory()
    user3 = factories.UserFactory()
    task1= factories.TaskFactory()
    task2= factories.TaskFactory()
    task3= factories.TaskFactory()
    task4= factories.TaskFactory()

    service.register_timeline_implementation("tasks.task", "test", lambda x, extra_data=None: str(id(x)))

    service._add_to_object_timeline(user1, task1, "test", task1.created_date)
    service._add_to_object_timeline(user1, task2, "test", task2.created_date)
    service._add_to_object_timeline(user1, task3, "test", task3.created_date)
    service._add_to_object_timeline(user1, task4, "test", task4.created_date)
    service._add_to_object_timeline(user2, task1, "test", task1.created_date)

    assert Timeline.objects.filter(object_id=user1.id).count() == 5
    assert Timeline.objects.filter(object_id=user2.id).count() == 2
    assert Timeline.objects.filter(object_id=user3.id).count() == 1
Пример #19
0
def test_epic_related_uss():
    Timeline.objects.all().delete()

    # Users
    public_project_owner = factories.UserFactory.create(
        username="******")
    not_qualified_private_project_member = factories.UserFactory.create(
        username="******")
    private_project_owner = factories.UserFactory.create(
        username="******")

    # A public project, containing a public epic which contains a private us from a private project
    public_project = factories.ProjectFactory.create(
        is_private=False,
        owner=public_project_owner,
        anon_permissions=[],
        public_permissions=["view_us"])
    factories.MembershipFactory.create(project=public_project,
                                       user=public_project.owner,
                                       is_admin=True)
    public_epic = factories.EpicFactory.create(project=public_project,
                                               owner=public_project_owner)
    public_us = factories.UserStoryFactory.create(project=public_project,
                                                  owner=public_project_owner)
    related_public_us = factories.RelatedUserStory.create(epic=public_epic,
                                                          user_story=public_us)

    # A private project, containing the private user story related to the public epic from the public project
    private_project = factories.ProjectFactory.create(
        is_private=True,
        owner=private_project_owner,
        anon_permissions=[],
        public_permissions=[])
    not_qualified_role = factories.RoleFactory(project=private_project,
                                               permissions=[])
    qualified_role = factories.RoleFactory(project=private_project,
                                           permissions=["view_us"])
    factories.MembershipFactory.create(
        project=private_project,
        user=not_qualified_private_project_member,
        role=not_qualified_role)
    factories.MembershipFactory.create(project=private_project,
                                       user=private_project_owner,
                                       role=qualified_role)
    private_us = factories.UserStoryFactory.create(project=private_project,
                                                   owner=private_project_owner)
    related_private_us = factories.RelatedUserStory.create(
        epic=public_epic, user_story=private_us)

    service.register_timeline_implementation("epics.relateduserstory",
                                             "test",
                                             lambda x, extra_data=None: id(x))
    project_namespace = build_project_namespace(public_project)
    # Timeline entries regarding the first epic-related public US, for both a user and a project namespace
    service._add_to_object_timeline(public_project, related_public_us,
                                    "create", datetime.now(),
                                    project_namespace)
    service._add_to_object_timeline(public_project_owner, related_public_us,
                                    "create", datetime.now(),
                                    build_user_namespace(public_project_owner))
    # Timeline entries regarding the first epic-related private US, for both a user and a project namespace
    service._add_to_object_timeline(public_project, related_private_us,
                                    "create", datetime.now(),
                                    project_namespace)
    service._add_to_object_timeline(
        private_project_owner, related_private_us, "create", datetime.now(),
        build_user_namespace(private_project_owner))
    """
    # A list of users for the test iterations
    #
    # [index0] An anonymous user, who doesn't even have rights to see neither public nor private related USs.
    # [index1] A public project's owner, who related a public US to an epic from her own public project. She just 
    #   has privileges to see her public related USs, and is a simple registered user regarding the private project.
    # [index2] An unprivileged private member, whose role doesn't have access to the private project's USs, 
    #   but is able to view the related-USs from the public project's.
    # [index3] A private project's owner, who linked her private US to an epic from the public project.
                She has privileges to see any related USs.
    """
    users = [
        AnonymousUser(),  # [index 0]
        public_project_owner,  # [index 1]
        not_qualified_private_project_member,  # [index 2]
        private_project_owner
    ]  # [index 3]

    timeline_counters = _helper_get_timelines_for_accessing_users(
        public_project, users)
    assert timeline_counters['project_timelines'] == [0, 1, 1, 2]
    assert timeline_counters['user_timelines'] == {
        # An anonymous user verifies the number of 'epics.relateduserstory' entries in the other users timelines
        #  She can't any epic related US on neither of [index1], [index2], or [index3] timelines
        0: [0, 0, 0],
        # An [index1] user verifies the number of 'epics.relateduserstory' entries in the other users timelines
        #  She can just see the public epic related USs on her own [index1] timeline
        1: [1, 0, 0],
        # An [index2] user verifies the number of 'epics.relateduserstory' entries in the other users timelines
        #  She can just see the public epic related USs on her own [index1] timeline
        2: [1, 0, 0],
        # An [index3] user verifies the number of 'epics.relateduserstory' entries in the other users timelines
        #  She can see both the public epic related USs in [index1] timeline, and in her own [index3] timeline
        3: [1, 0, 1]
    }