def test_push_event_task_mention(client): creation_status = f.TaskStatusFactory() role = f.RoleFactory(project=creation_status.project, permissions=["view_tasks"]) f.MembershipFactory(project=creation_status.project, role=role, user=creation_status.project.owner) task = f.TaskFactory.create(status=creation_status, project=creation_status.project, owner=creation_status.project.owner) take_snapshot(task, user=creation_status.project.owner) payload = { "commits": [ { "message": """test message test TG-%s ok bye! """ % (task.ref) }, ] } mail.outbox = [] ev_hook = event_hooks.PushEventHook(task.project, payload) ev_hook.process_event() task_history = get_history_queryset_by_model_instance(task) assert task_history.count() == 1 assert task_history[0].comment.startswith( "This task has been mentioned by") assert len(mail.outbox) == 1
def test_push_event_user_story_mention(client): creation_status = f.UserStoryStatusFactory() role = f.RoleFactory(project=creation_status.project, permissions=["view_us"]) f.MembershipFactory(project=creation_status.project, role=role, user=creation_status.project.owner) user_story = f.UserStoryFactory.create(status=creation_status, project=creation_status.project, owner=creation_status.project.owner) take_snapshot(user_story, user=creation_status.project.owner) payload = { "commits": [{ "message": """test message test TG-%s ok bye! """ % (user_story.ref), "author": { "username": "******", }, }], "repository": { "html_url": "http://test-url/test/project" } } mail.outbox = [] ev_hook = event_hooks.PushEventHook(user_story.project, payload) ev_hook.process_event() us_history = get_history_queryset_by_model_instance(user_story) assert us_history.count() == 1 assert us_history[0].comment.startswith( "This user story has been mentioned by") assert len(mail.outbox) == 1
def get_history(self, obj): history_qs = history_service.get_history_queryset_by_model_instance( obj, types=(history_models.HistoryType.change, history_models.HistoryType.create,) ) return HistoryExportSerializer(history_qs, many=True, statuses_queryset=self.statuses_queryset(obj.project)).data
def test_issue_comment_event_on_not_existing_issue_task_and_us(client): issue = f.IssueFactory.create(external_reference=["gitlab", "10"]) take_snapshot(issue, user=issue.owner) task = f.TaskFactory.create(project=issue.project, external_reference=["gitlab", "10"]) take_snapshot(task, user=task.owner) us = f.UserStoryFactory.create(project=issue.project, external_reference=["gitlab", "10"]) take_snapshot(us, user=us.owner) payload = deepcopy(issue_comment_base_payload) payload["user"]["username"] = "******" payload["issue"]["iid"] = "99999" payload["issue"]["title"] = "test-title" payload["object_attributes"]["noteable_type"] = "Issue" payload["object_attributes"]["note"] = "test comment" payload["repository"]["homepage"] = "test" 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
def test_push_event_user_story_mention(client): creation_status = f.UserStoryStatusFactory() role = f.RoleFactory(project=creation_status.project, permissions=["view_us"]) f.MembershipFactory(project=creation_status.project, role=role, user=creation_status.project.owner) user_story = f.UserStoryFactory.create(status=creation_status, project=creation_status.project, owner=creation_status.project.owner) take_snapshot(user_story, user=creation_status.project.owner) payload = { "actor": { "user": { "uuid": "{ce1054cd-3f43-49dc-8aea-d3085ee7ec9b}", "username": "******", "links": { "html": { "href": "http://bitbucket.com/test-user" } } } }, "push": { "changes": [{ "commits": [{ "message": "test message test TG-%s ok bye!" % (user_story.ref) }] }] } } mail.outbox = [] ev_hook = event_hooks.PushEventHook(user_story.project, payload) ev_hook.process_event() us_history = get_history_queryset_by_model_instance(user_story) assert us_history.count() == 1 assert us_history[0].comment.startswith( "This user story has been mentioned by") assert len(mail.outbox) == 1
def test_push_event_task_mention(client): creation_status = f.TaskStatusFactory() role = f.RoleFactory(project=creation_status.project, permissions=["view_tasks"]) f.MembershipFactory(project=creation_status.project, role=role, user=creation_status.project.owner) task = f.TaskFactory.create(status=creation_status, project=creation_status.project, owner=creation_status.project.owner) take_snapshot(task, user=creation_status.project.owner) payload = deepcopy(push_base_payload) payload["commits"] = [{ "message": """test message test TG-%s ok bye! """ % (task.ref), "id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", "url": "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", }] mail.outbox = [] ev_hook = event_hooks.PushEventHook(task.project, payload) ev_hook.process_event() task_history = get_history_queryset_by_model_instance(task) assert task_history.count() == 1 assert task_history[0].comment.startswith("This task has been mentioned by") assert len(mail.outbox) == 1
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=["gitlab", "http://gitlab.com/test/project/issues/11"], owner=project.owner, project=project) take_snapshot(issue, user=user) task = f.TaskFactory.create(external_reference=["gitlab", "http://gitlab.com/test/project/issues/11"], owner=project.owner, project=project) take_snapshot(task, user=user) us = f.UserStoryFactory.create(external_reference=["gitlab", "http://gitlab.com/test/project/issues/11"], owner=project.owner, project=project) take_snapshot(us, user=user) payload = deepcopy(issue_comment_base_payload) payload["user"]["username"] = "******" payload["issue"]["iid"] = "11" payload["issue"]["title"] = "test-title" payload["object_attributes"]["noteable_type"] = "Issue" payload["object_attributes"]["note"] = "Test body" payload["repository"]["homepage"] = "http://gitlab.com/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=["github", "10"]) take_snapshot(issue, user=issue.owner) task = f.TaskFactory.create(project=issue.project, external_reference=["github", "10"]) take_snapshot(task, user=task.owner) us = f.UserStoryFactory.create(project=issue.project, external_reference=["github", "10"]) take_snapshot(us, user=us.owner) payload = { "action": "created", "issue": { "html_url": "http://github.com/test/project/issues/11", }, "comment": { "body": "Test body", }, "repository": { "html_url": "test", }, } 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
def handle(self, *args, **options): locale = options.get('locale') email_address = options.get('email') # Register email context = { "lang": locale, "user": get_user_model().objects.all().order_by("?").first(), "cancel_token": "cancel-token" } email = mail_builder.registered_user(email_address, context) email.send() # Membership invitation membership = Membership.objects.order_by("?").filter( user__isnull=True).first() membership.invited_by = get_user_model().objects.all().order_by( "?").first() membership.invitation_extra_text = "Text example, Text example,\nText example,\n\nText example" context = {"lang": locale, "membership": membership} email = mail_builder.membership_invitation(email_address, context) email.send() # Membership notification context = { "lang": locale, "membership": Membership.objects.order_by("?").filter( user__isnull=False).first() } email = mail_builder.membership_notification(email_address, context) email.send() # Feedback context = { "lang": locale, "feedback_entry": { "full_name": "Test full name", "email": "*****@*****.**", "comment": "Test comment", }, "extra": { "key1": "value1", "key2": "value2", }, } email = mail_builder.feedback_notification(email_address, context) email.send() # Password recovery context = { "lang": locale, "user": get_user_model().objects.all().order_by("?").first() } email = mail_builder.password_recovery(email_address, context) email.send() # Change email context = { "lang": locale, "user": get_user_model().objects.all().order_by("?").first() } email = mail_builder.change_email(email_address, context) email.send() # Export/Import emails context = { "lang": locale, "user": get_user_model().objects.all().order_by("?").first(), "project": Project.objects.all().order_by("?").first(), "error_subject": "Error generating project dump", "error_message": "Error generating project dump", } email = mail_builder.export_error(email_address, context) email.send() context = { "lang": locale, "user": get_user_model().objects.all().order_by("?").first(), "error_subject": "Error importing project dump", "error_message": "Error importing project dump", } email = mail_builder.import_error(email_address, context) email.send() deletion_date = timezone.now() + datetime.timedelta(seconds=60 * 60 * 24) context = { "lang": locale, "url": "http://dummyurl.com", "user": get_user_model().objects.all().order_by("?").first(), "project": Project.objects.all().order_by("?").first(), "deletion_date": deletion_date, } email = mail_builder.dump_project(email_address, context) email.send() context = { "lang": locale, "user": get_user_model().objects.all().order_by("?").first(), "project": Project.objects.all().order_by("?").first(), } email = mail_builder.load_dump(email_address, context) email.send() # Notification emails notification_emails = [ ("issues.Issue", "issues/issue-change"), ("issues.Issue", "issues/issue-create"), ("issues.Issue", "issues/issue-delete"), ("tasks.Task", "tasks/task-change"), ("tasks.Task", "tasks/task-create"), ("tasks.Task", "tasks/task-delete"), ("userstories.UserStory", "userstories/userstory-change"), ("userstories.UserStory", "userstories/userstory-create"), ("userstories.UserStory", "userstories/userstory-delete"), ("milestones.Milestone", "milestones/milestone-change"), ("milestones.Milestone", "milestones/milestone-create"), ("milestones.Milestone", "milestones/milestone-delete"), ("wiki.WikiPage", "wiki/wikipage-change"), ("wiki.WikiPage", "wiki/wikipage-create"), ("wiki.WikiPage", "wiki/wikipage-delete"), ] context = { "lang": locale, "project": Project.objects.all().order_by("?").first(), "changer": get_user_model().objects.all().order_by("?").first(), "history_entries": HistoryEntry.objects.all().order_by("?")[0:5], "user": get_user_model().objects.all().order_by("?").first(), } for notification_email in notification_emails: model = apps.get_model(*notification_email[0].split(".")) snapshot = { "subject": "Tests subject", "ref": 123123, "name": "Tests name", "slug": "test-slug" } queryset = model.objects.all().order_by("?") for obj in queryset: end = False entries = get_history_queryset_by_model_instance(obj).filter( is_snapshot=True).order_by("?") for entry in entries: if entry.snapshot: snapshot = entry.snapshot end = True break if end: break context["snapshot"] = snapshot cls = type("InlineCSSTemplateMail", (InlineCSSTemplateMail, ), {"name": notification_email[1]}) email = cls() email.send(email_address, context) # Transfer Emails context = { "project": Project.objects.all().order_by("?").first(), "requester": get_user_model().objects.all().order_by("?").first(), } email = mail_builder.transfer_request(email_address, context) email.send() context = { "project": Project.objects.all().order_by("?").first(), "receiver": get_user_model().objects.all().order_by("?").first(), "token": "test-token", "reason": "Test reason" } email = mail_builder.transfer_start(email_address, context) email.send() context = { "project": Project.objects.all().order_by("?").first(), "old_owner": get_user_model().objects.all().order_by("?").first(), "new_owner": get_user_model().objects.all().order_by("?").first(), "reason": "Test reason" } email = mail_builder.transfer_accept(email_address, context) email.send() context = { "project": Project.objects.all().order_by("?").first(), "rejecter": get_user_model().objects.all().order_by("?").first(), "reason": "Test reason" } email = mail_builder.transfer_reject(email_address, context) email.send() # Contact with project admins email project = Project.objects.all().order_by("?").first() user = get_user_model().objects.all().order_by("?").first() context = { "full_name": user.get_full_name(), "project_name": project.name, "photo_url": get_user_photo_url(user), "user_profile_url": resolve_front_url("user", user.username), "project_settings_url": resolve_front_url("project-admin", project.slug), "comment": "Test comment notification." } email = mail_builder.contact_notification(email_address, context) email.send() # GitHub importer email context = { "project": Project.objects.all().order_by("?").first(), "user": get_user_model().objects.all().order_by("?").first() } email = mail_builder.github_import_success(email_address, context) email.send() # Jira importer email context = { "project": Project.objects.all().order_by("?").first(), "user": get_user_model().objects.all().order_by("?").first() } email = mail_builder.jira_import_success(email_address, context) email.send() # Trello importer email context = { "project": Project.objects.all().order_by("?").first(), "user": get_user_model().objects.all().order_by("?").first() } email = mail_builder.trello_import_success(email_address, context) email.send() # Asana importer email context = { "project": Project.objects.all().order_by("?").first(), "user": get_user_model().objects.all().order_by("?").first() } email = mail_builder.asana_import_success(email_address, context) email.send() # Error importer email context = { "user": get_user_model().objects.all().order_by("?").first(), "error_subject": "Error importing GitHub project", "error_message": "Error importing GitHub project", "project": 1234, "exception": "Exception message" } email = mail_builder.importer_import_error(email_address, context) email.send()
def get_editions(self, obj): return history_service.get_history_queryset_by_model_instance( obj).count() + 1 # +1 for creation
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
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=[ "github", "http://github.com/test/project/issues/11" ], owner=project.owner, project=project) take_snapshot(issue, user=user) task = f.TaskFactory.create(external_reference=[ "github", "http://github.com/test/project/issues/11" ], owner=project.owner, project=project) take_snapshot(task, user=user) us = f.UserStoryFactory.create(external_reference=[ "github", "http://github.com/test/project/issues/11" ], owner=project.owner, project=project) take_snapshot(us, user=user) payload = { "action": "created", "issue": { "html_url": "http://github.com/test/project/issues/11", }, "comment": { "body": "Test body", }, "repository": { "html_url": "test", }, } 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