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: 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
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: 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)
Esempio n. 3
0
def test_register_timeline_implementation():
    test_func = lambda x: "test-func-result"
    service.register_timeline_implementation("timeline.timeline", "test",
                                             test_func)
    assert service._timeline_impl_map["timeline.timeline.test"](
        None) == "test-func-result"

    @service.register_timeline_implementation("timeline.timeline",
                                              "test-decorator")
    def decorated_test_function(x):
        return "test-decorated-func-result"

    assert service._timeline_impl_map["timeline.timeline.test-decorator"](
        None) == "test-decorated-func-result"
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: 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
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: 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