##// END OF EJS Templates
feat(hide recaptcha secrets): masked sensitive information related to reCaptcha configuration.
feat(hide recaptcha secrets): masked sensitive information related to reCaptcha configuration.

File last commit:

r5608:6d33e504 default
r5641:ad0048eb tip default
Show More
test_get_repo_comments.py
140 lines | 5.6 KiB | text/x-python | PythonLexer
/ rhodecode / api / tests / test_get_repo_comments.py
core: updated copyright to 2024
r5608 # Copyright (C) 2010-2024 RhodeCode GmbH
api: added function to fetch comments for a repository.
r3435 #
# 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
from rhodecode.model.db import User, ChangesetComment
from rhodecode.model.meta import Session
from rhodecode.model.comment import CommentsModel
from rhodecode.api.tests.utils import (
build_data, api_call, assert_error, assert_call_ok)
@pytest.fixture()
def make_repo_comments_factory(request):
dependencies: bumped test libraries.
r3951 class Make(object):
def make_comments(self, repo):
user = User.get_first_super_admin()
commit = repo.scm_instance()[0]
api: added function to fetch comments for a repository.
r3435
dependencies: bumped test libraries.
r3951 commit_id = commit.raw_id
file_0 = commit.affected_files[0]
comments = []
api: added function to fetch comments for a repository.
r3435
dependencies: bumped test libraries.
r3951 # general
api: added get_comment method, and return versions for comments to allow simple edits via API.
r4440 comment = CommentsModel().create(
dependencies: bumped test libraries.
r3951 text='General Comment', repo=repo, user=user, commit_id=commit_id,
comment_type=ChangesetComment.COMMENT_TYPE_NOTE, send_email=False)
api: added get_comment method, and return versions for comments to allow simple edits via API.
r4440 comments.append(comment)
api: added function to fetch comments for a repository.
r3435
dependencies: bumped test libraries.
r3951 # inline
api: added get_comment method, and return versions for comments to allow simple edits via API.
r4440 comment = CommentsModel().create(
dependencies: bumped test libraries.
r3951 text='Inline Comment', repo=repo, user=user, commit_id=commit_id,
f_path=file_0, line_no='n1',
comment_type=ChangesetComment.COMMENT_TYPE_NOTE, send_email=False)
api: added get_comment method, and return versions for comments to allow simple edits via API.
r4440 comments.append(comment)
api: added function to fetch comments for a repository.
r3435
dependencies: bumped test libraries.
r3951 # todo
api: added get_comment method, and return versions for comments to allow simple edits via API.
r4440 comment = CommentsModel().create(
dependencies: bumped test libraries.
r3951 text='INLINE TODO Comment', repo=repo, user=user, commit_id=commit_id,
f_path=file_0, line_no='n1',
comment_type=ChangesetComment.COMMENT_TYPE_TODO, send_email=False)
api: added get_comment method, and return versions for comments to allow simple edits via API.
r4440 comments.append(comment)
api: added function to fetch comments for a repository.
r3435
api: added get_comment method, and return versions for comments to allow simple edits via API.
r4440 return comments
dependencies: bumped test libraries.
r3951 return Make()
api: added function to fetch comments for a repository.
r3435
@pytest.mark.usefixtures("testuser_api", "app")
class TestGetRepo(object):
@pytest.mark.parametrize('filters, expected_count', [
({}, 3),
({'comment_type': ChangesetComment.COMMENT_TYPE_NOTE}, 2),
({'comment_type': ChangesetComment.COMMENT_TYPE_TODO}, 1),
({'commit_id': 'FILLED DYNAMIC'}, 3),
])
def test_api_get_repo_comments(self, backend, user_util,
make_repo_comments_factory, filters, expected_count):
commits = [{'message': 'A'}, {'message': 'B'}]
repo = backend.create_repo(commits=commits)
dependencies: bumped test libraries.
r3951 make_repo_comments_factory.make_comments(repo)
api: added function to fetch comments for a repository.
r3435
api_call_params = {'repoid': repo.repo_name,}
api_call_params.update(filters)
if 'commit_id' in api_call_params:
commit = repo.scm_instance()[0]
commit_id = commit.raw_id
api_call_params['commit_id'] = commit_id
id_, params = build_data(self.apikey, 'get_repo_comments', **api_call_params)
response = api_call(self.app, params)
result = assert_call_ok(id_, given=response.body)
assert len(result) == expected_count
dependencies: bumped test libraries.
r3951 def test_api_get_repo_comments_wrong_comment_type(
self, make_repo_comments_factory, backend_hg):
commits = [{'message': 'A'}, {'message': 'B'}]
repo = backend_hg.create_repo(commits=commits)
make_repo_comments_factory.make_comments(repo)
api: added function to fetch comments for a repository.
r3435
dependencies: bumped test libraries.
r3951 api_call_params = {'repoid': repo.repo_name}
api: added function to fetch comments for a repository.
r3435 api_call_params.update({'comment_type': 'bogus'})
expected = 'comment_type must be one of `{}` got {}'.format(
ChangesetComment.COMMENT_TYPES, 'bogus')
id_, params = build_data(self.apikey, 'get_repo_comments', **api_call_params)
response = api_call(self.app, params)
assert_error(id_, expected, given=response.body)
api: added get_comment method, and return versions for comments to allow simple edits via API.
r4440
def test_api_get_comment(self, make_repo_comments_factory, backend_hg):
commits = [{'message': 'A'}, {'message': 'B'}]
repo = backend_hg.create_repo(commits=commits)
comments = make_repo_comments_factory.make_comments(repo)
comment_ids = [x.comment_id for x in comments]
Session().commit()
for comment_id in comment_ids:
id_, params = build_data(self.apikey, 'get_comment',
**{'comment_id': comment_id})
response = api_call(self.app, params)
result = assert_call_ok(id_, given=response.body)
assert result['comment_id'] == comment_id
def test_api_get_comment_no_access(self, make_repo_comments_factory, backend_hg, user_util):
commits = [{'message': 'A'}, {'message': 'B'}]
repo = backend_hg.create_repo(commits=commits)
comments = make_repo_comments_factory.make_comments(repo)
comment_id = comments[0].comment_id
test_user = user_util.create_user()
user_util.grant_user_permission_to_repo(repo, test_user, 'repository.none')
id_, params = build_data(test_user.api_key, 'get_comment',
**{'comment_id': comment_id})
response = api_call(self.app, params)
assert_error(id_,
expected='comment `{}` does not exist'.format(comment_id),
given=response.body)