def test_issues_event_bad_comment(client): issue = f.IssueFactory.create(external_reference=["bitbucket", "10"]) take_snapshot(issue, user=issue.owner) payload = { "actor": { "user": { "uuid": "{ce1054cd-3f43-49dc-8aea-d3085ee7ec9b}", "username": "******", "links": {"html": {"href": "http://bitbucket.com/test-user"}} } }, "issue": { "id": "10", "title": "test-title", "links": {"html": {"href": "http://bitbucket.com/site/master/issue/10"}}, "content": {"raw": "test-content"} }, "comment": { }, "repository": { "links": {"html": {"href": "http://bitbucket.com/test-user/test-project"}} } } ev_hook = event_hooks.IssueCommentEventHook(issue.project, payload) mail.outbox = [] with pytest.raises(ActionSyntaxException) as excinfo: ev_hook.process_event() assert str(excinfo.value) == "Invalid issue comment information" assert Issue.objects.count() == 1 assert len(mail.outbox) == 0
def test_issue_comment_event_on_existing_issue_task_and_us(client): project = f.ProjectFactory() role = f.RoleFactory(project=project, permissions=["view_tasks", "view_issues", "view_us"]) f.MembershipFactory(project=project, role=role, user=project.owner) user = f.UserFactory() issue = f.IssueFactory.create(external_reference=["bitbucket", "http://bitbucket.com/site/master/issue/11"], owner=project.owner, project=project) take_snapshot(issue, user=user) task = f.TaskFactory.create(external_reference=["bitbucket", "http://bitbucket.com/site/master/issue/11"], owner=project.owner, project=project) take_snapshot(task, user=user) us = f.UserStoryFactory.create(external_reference=["bitbucket", "http://bitbucket.com/site/master/issue/11"], owner=project.owner, project=project) take_snapshot(us, user=user) payload = { "actor": { "user": { "uuid": "{ce1054cd-3f43-49dc-8aea-d3085ee7ec9b}", "username": "******", "links": {"html": {"href": "http://bitbucket.com/test-user"}} } }, "issue": { "id": "11", "title": "test-title", "links": {"html": {"href": "http://bitbucket.com/site/master/issue/11"}}, "content": {"raw": "test-content"} }, "comment": { "content": {"raw": "Test body"}, }, "repository": { "links": {"html": {"href": "http://bitbucket.com/test-user/test-project"}} } } mail.outbox = [] assert get_history_queryset_by_model_instance(issue).count() == 0 assert get_history_queryset_by_model_instance(task).count() == 0 assert get_history_queryset_by_model_instance(us).count() == 0 ev_hook = event_hooks.IssueCommentEventHook(issue.project, payload) ev_hook.process_event() issue_history = get_history_queryset_by_model_instance(issue) assert issue_history.count() == 1 assert "Test body" in issue_history[0].comment task_history = get_history_queryset_by_model_instance(task) assert task_history.count() == 1 assert "Test body" in issue_history[0].comment us_history = get_history_queryset_by_model_instance(us) assert us_history.count() == 1 assert "Test body" in issue_history[0].comment assert len(mail.outbox) == 3
def test_issue_comment_event_on_not_existing_issue_task_and_us(client): issue = f.IssueFactory.create(external_reference=["bitbucket", "10"]) take_snapshot(issue, user=issue.owner) task = f.TaskFactory.create(project=issue.project, external_reference=["bitbucket", "10"]) take_snapshot(task, user=task.owner) us = f.UserStoryFactory.create(project=issue.project, external_reference=["bitbucket", "10"]) take_snapshot(us, user=us.owner) payload = { "actor": { "user": { "uuid": "{ce1054cd-3f43-49dc-8aea-d3085ee7ec9b}", "username": "******", "links": {"html": {"href": "http://bitbucket.com/test-user"}} } }, "issue": { "id": "10", "title": "test-title", "links": {"html": {"href": "http://bitbucket.com/site/master/issue/10"}}, "content": {"raw": "test-content"} }, "comment": { "content": {"raw": "Test body"}, }, "repository": { "links": {"html": {"href": "http://bitbucket.com/test-user/test-project"}} } } mail.outbox = [] assert get_history_queryset_by_model_instance(issue).count() == 0 assert get_history_queryset_by_model_instance(task).count() == 0 assert get_history_queryset_by_model_instance(us).count() == 0 ev_hook = event_hooks.IssueCommentEventHook(issue.project, payload) ev_hook.process_event() assert get_history_queryset_by_model_instance(issue).count() == 0 assert get_history_queryset_by_model_instance(task).count() == 0 assert get_history_queryset_by_model_instance(us).count() == 0 assert len(mail.outbox) == 0