##// END OF EJS Templates
release: Finish preparation for 4.19.0
release: Finish preparation for 4.19.0

File last commit:

r4306:09801de9 default
r4360:ddef396a v4.19.0 stable
Show More
test_comment_commit.py
116 lines | 4.8 KiB | text/x-python | PythonLexer
/ rhodecode / api / tests / test_comment_commit.py
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
code: update copyrights to 2020
r4306 # Copyright (C) 2010-2020 RhodeCode GmbH
project: added all source files and assets
r1 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import pytest
api: allow extra recipients for pr/commit comments api methods...
r4049 from rhodecode.model.db import ChangesetStatus, User
project: added all source files and assets
r1 from rhodecode.api.tests.utils import (
build_data, api_call, assert_error, assert_ok)
@pytest.mark.usefixtures("testuser_api", "app")
class TestCommentCommit(object):
def test_api_comment_commit_on_empty_repo(self, backend):
repo = backend.create_repo()
id_, params = build_data(
self.apikey, 'comment_commit', repoid=repo.repo_name,
commit_id='tip', message='message', status_change=None)
response = api_call(self.app, params)
api: validate commit_id when using commit_comment API
r1416 expected = 'There are no commits yet'
project: added all source files and assets
r1 assert_error(id_, expected, given=response.body)
api: validate commit_id when using commit_comment API
r1416 @pytest.mark.parametrize("commit_id, expected_err", [
tests: fixing tests for pull-requests and changelog(commits)
r3772 ('abcabca', {'hg': 'Commit {commit} does not exist for `{repo}`',
'git': 'Commit {commit} does not exist for `{repo}`',
api: validate commit_id when using commit_comment API
r1416 'svn': 'Commit id {commit} not understood.'}),
tests: fixing tests for pull-requests and changelog(commits)
r3772 ('idontexist', {'hg': 'Commit {commit} does not exist for `{repo}`',
'git': 'Commit {commit} does not exist for `{repo}`',
api: validate commit_id when using commit_comment API
r1416 'svn': 'Commit id {commit} not understood.'}),
])
def test_api_comment_commit_wrong_hash(self, backend, commit_id, expected_err):
repo_name = backend.repo.repo_name
id_, params = build_data(
self.apikey, 'comment_commit', repoid=repo_name,
commit_id=commit_id, message='message', status_change=None)
response = api_call(self.app, params)
expected_err = expected_err[backend.alias]
expected_err = expected_err.format(
tests: fixing tests for pull-requests and changelog(commits)
r3772 repo=backend.repo.scm_instance().name, commit=commit_id)
api: validate commit_id when using commit_comment API
r1416 assert_error(id_, expected_err, given=response.body)
project: added all source files and assets
r1 @pytest.mark.parametrize("status_change, message, commit_id", [
(None, 'Hallo', 'tip'),
(ChangesetStatus.STATUS_APPROVED, 'Approved', 'tip'),
(ChangesetStatus.STATUS_REJECTED, 'Rejected', 'tip'),
])
def test_api_comment_commit(
self, backend, status_change, message, commit_id,
no_notifications):
api: validate commit_id when using commit_comment API
r1416
dan
vcs: don't use deprecated get_changeset[s] methods.
r3112 commit_id = backend.repo.scm_instance().get_commit(commit_id).raw_id
api: validate commit_id when using commit_comment API
r1416
project: added all source files and assets
r1 id_, params = build_data(
self.apikey, 'comment_commit', repoid=backend.repo_name,
commit_id=commit_id, message=message, status=status_change)
response = api_call(self.app, params)
repo = backend.repo.scm_instance()
expected = {
'msg': 'Commented on commit `%s` for repository `%s`' % (
dan
vcs: don't use deprecated get_changeset[s] methods.
r3112 repo.get_commit().raw_id, backend.repo_name),
project: added all source files and assets
r1 'status_change': status_change,
'success': True
}
assert_ok(id_, expected, given=response.body)
api: allow extra recipients for pr/commit comments api methods...
r4049
def test_api_comment_commit_with_extra_recipients(self, backend, user_util):
commit_id = backend.repo.scm_instance().get_commit('tip').raw_id
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_commit', repoid=backend.repo_name,
commit_id=commit_id,
message='abracadabra',
extra_recipients=[user1.user_id, user2.username])
response = api_call(self.app, params)
repo = backend.repo.scm_instance()
expected = {
'msg': 'Commented on commit `%s` for repository `%s`' % (
repo.get_commit().raw_id, backend.repo_name),
'status_change': None,
'success': True
}
assert_ok(id_, expected, given=response.body)
# check user1/user2 inbox for notification
user1 = User.get(user1_id)
assert 1 == len(user1.notifications)
assert 'abracadabra' in user1.notifications[0].notification.body
user2 = User.get(user2_id)
assert 1 == len(user2.notifications)
assert 'abracadabra' in user2.notifications[0].notification.body