def test_add_to_objects_timeline(): with patch("taiga.timeline.service._add_to_object_timeline") as mock: users = [User(), User(), User()] project = Project() service._add_to_objects_timeline(users, project, "test") assert mock.call_count == 3 assert mock.mock_calls == [ call(users[0], project, "test", "default", {}), call(users[1], project, "test", "default", {}), call(users[2], project, "test", "default", {}), ] with pytest.raises(Exception): service.push_to_timeline(None, project, "test")
def test_push_to_timeline_many_objects(): with patch("taiga.timeline.service._add_to_object_timeline") as mock: users = [get_user_model(), get_user_model(), get_user_model()] project = Project() service.push_to_timeline(users, project, "test", project.created_date) assert mock.call_count == 3 assert mock.mock_calls == [ call(users[0], project, "test", project.created_date, "default", {}), call(users[1], project, "test", project.created_date, "default", {}), call(users[2], project, "test", project.created_date, "default", {}), ] with pytest.raises(Exception): service.push_to_timeline(None, project, "test")
def create_membership_push_to_timeline(sender, instance, **kwargs): if not instance.pk and instance.user: push_to_timeline(instance.project, instance, "create") elif instance.pk: prev_instance = sender.objects.get(pk=instance.pk) if prev_instance.user != prev_instance.user: push_to_timeline(instance.project, instance, "create") elif prev_instance.role != prev_instance.role: extra_data = { "prev_role": { "id": prev_instance.role.pk, "name": prev_instance.role.name, } } push_to_timeline(instance.project, instance, "role-changed", extra_data=extra_data)
def _push_to_timeline(*args, **kwargs): if settings.CELERY_ENABLED: push_to_timeline.delay(*args, **kwargs) else: push_to_timeline(*args, **kwargs)
def delete_membership_push_to_timeline(sender, instance, **kwargs): push_to_timeline(instance.project, instance, "delete")
def create_issue_push_to_timeline(sender, instance, created, **kwargs): if created: push_to_timeline(instance.project, instance, "create")