api: allow extra recipients for pr/commit comments api methods

- adds some sort of CC functionality for notification
- allows sending emails with notifications to people who are not commit messages, or pr reviewers e.g project manager etc.
This commit is contained in:
Marcin Kuzminski 2019-11-07 22:29:39 +01:00
parent bd7a7f7bc1
commit 697ce81998
7 changed files with 101 additions and 7 deletions

View file

@ -21,7 +21,7 @@
import pytest
from rhodecode.model.comment import CommentsModel
from rhodecode.model.db import UserLog
from rhodecode.model.db import UserLog, User
from rhodecode.model.pull_request import PullRequestModel
from rhodecode.tests import TEST_USER_ADMIN_LOGIN
from rhodecode.api.tests.utils import (
@ -69,6 +69,43 @@ class TestCommentPullRequest(object):
.all()
assert journal[-1].action == 'repo.pull_request.comment.create'
@pytest.mark.backends("git", "hg")
def test_api_comment_pull_request_with_extra_recipients(self, pr_util, user_util):
pull_request = pr_util.create_pull_request()
user1 = user_util.create_user()
user1_id = user1.user_id
user2 = user_util.create_user()
user2_id = user2.user_id
id_, params = build_data(
self.apikey, 'comment_pull_request',
repoid=pull_request.target_repo.repo_name,
pullrequestid=pull_request.pull_request_id,
message='test message',
extra_recipients=[user1.user_id, user2.username]
)
response = api_call(self.app, params)
pull_request = PullRequestModel().get(pull_request.pull_request_id)
comments = CommentsModel().get_comments(
pull_request.target_repo.repo_id, pull_request=pull_request)
expected = {
'pull_request_id': pull_request.pull_request_id,
'comment_id': comments[-1].comment_id,
'status': {'given': None, 'was_changed': None}
}
assert_ok(id_, expected, response.body)
# check user1/user2 inbox for notification
user1 = User.get(user1_id)
assert 1 == len(user1.notifications)
assert 'test message' in user1.notifications[0].notification.body
user2 = User.get(user2_id)
assert 1 == len(user2.notifications)
assert 'test message' in user2.notifications[0].notification.body
@pytest.mark.backends("git", "hg")
def test_api_comment_pull_request_change_status(
self, pr_util, no_notifications):