##// END OF EJS Templates
ops: add better name for anonymous ops/ping calls.
ops: add better name for anonymous ops/ping calls.

File last commit:

r2487:fcee5614 default
r3340:bd620f63 default
Show More
test_get_pull_request.py
142 lines | 5.7 KiB | text/x-python | PythonLexer
/ rhodecode / api / tests / test_get_pull_request.py
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
release: update copyright year to 2018
r2487 # Copyright (C) 2010-2018 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
import urlobject
from rhodecode.api.tests.utils import (
build_data, api_call, assert_error, assert_ok)
pull-requests: migrated code from pylons to pyramid
r1974 from rhodecode.lib import helpers as h
home: moved home and repo group views into pyramid....
r1774 from rhodecode.lib.utils2 import safe_unicode
project: added all source files and assets
r1
pytestmark = pytest.mark.backends("git", "hg")
@pytest.mark.usefixtures("testuser_api", "app")
class TestGetPullRequest(object):
audit-logs: implemented pull request and comment events.
r1807 def test_api_get_pull_request(self, pr_util, http_host_only_stub):
Martin Bornhold
tests: Add shadow clone url to expected api return value.
r908 from rhodecode.model.pull_request import PullRequestModel
project: added all source files and assets
r1 pull_request = pr_util.create_pull_request(mergeable=True)
id_, params = build_data(
self.apikey, 'get_pull_request',
pullrequestid=pull_request.pull_request_id)
response = api_call(self.app, params)
assert response.status == '200 OK'
url_obj = urlobject.URLObject(
pull-requests: migrated code from pylons to pyramid
r1974 h.route_url(
project: added all source files and assets
r1 'pullrequest_show',
repo_name=pull_request.target_repo.repo_name,
pull-requests: migrated code from pylons to pyramid
r1974 pull_request_id=pull_request.pull_request_id))
home: moved home and repo group views into pyramid....
r1774
pr_url = safe_unicode(
audit-logs: implemented pull request and comment events.
r1807 url_obj.with_netloc(http_host_only_stub))
home: moved home and repo group views into pyramid....
r1774 source_url = safe_unicode(
pull_request.source_repo.clone_url().with_netloc(http_host_only_stub))
target_url = safe_unicode(
pull_request.target_repo.clone_url().with_netloc(http_host_only_stub))
shadow_url = safe_unicode(
Martin Bornhold
tests: Add shadow clone url to expected api return value.
r908 PullRequestModel().get_shadow_clone_url(pull_request))
home: moved home and repo group views into pyramid....
r1774
project: added all source files and assets
r1 expected = {
'pull_request_id': pull_request.pull_request_id,
'url': pr_url,
'title': pull_request.title,
'description': pull_request.description,
'status': pull_request.status,
'created_on': pull_request.created_on,
'updated_on': pull_request.updated_on,
'commit_ids': pull_request.revisions,
'review_status': pull_request.calculated_review_status(),
'mergeable': {
'status': True,
'message': 'This pull request can be automatically merged.',
},
'source': {
'clone_url': source_url,
'repository': pull_request.source_repo.repo_name,
'reference': {
'name': pull_request.source_ref_parts.name,
'type': pull_request.source_ref_parts.type,
'commit_id': pull_request.source_ref_parts.commit_id,
},
},
'target': {
'clone_url': target_url,
'repository': pull_request.target_repo.repo_name,
'reference': {
'name': pull_request.target_ref_parts.name,
'type': pull_request.target_ref_parts.type,
'commit_id': pull_request.target_ref_parts.commit_id,
},
},
Martin Bornhold
tests: Update expected data from api call.
r1056 'merge': {
Martin Bornhold
tests: Add shadow clone url to expected api return value.
r908 'clone_url': shadow_url,
Martin Bornhold
tests: Update expected data from api call.
r1056 'reference': {
'name': pull_request.shadow_merge_ref.name,
'type': pull_request.shadow_merge_ref.type,
'commit_id': pull_request.shadow_merge_ref.commit_id,
},
Martin Bornhold
tests: Add shadow clone url to expected api return value.
r908 },
project: added all source files and assets
r1 'author': pull_request.author.get_api_data(include_secrets=False,
details='basic'),
'reviewers': [
{
'user': reviewer.get_api_data(include_secrets=False,
details='basic'),
dan
reviewers: store reviewer reasons to database, fixes #4238
r873 'reasons': reasons,
project: added all source files and assets
r1 'review_status': st[0][1].status if st else 'not_reviewed',
}
default-reviewers: introduce new voting rule logic that allows...
r2484 for obj, reviewer, reasons, mandatory, st in
pull-request: extended default reviewers functionality....
r1769 pull_request.reviewers_statuses()
project: added all source files and assets
r1 ]
}
assert_ok(id_, expected, response.body)
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 def test_api_get_pull_request_repo_error(self, pr_util):
pull_request = pr_util.create_pull_request()
project: added all source files and assets
r1 id_, params = build_data(
self.apikey, 'get_pull_request',
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 repoid=666, pullrequestid=pull_request.pull_request_id)
project: added all source files and assets
r1 response = api_call(self.app, params)
expected = 'repository `666` does not exist'
assert_error(id_, expected, given=response.body)
def test_api_get_pull_request_pull_request_error(self):
id_, params = build_data(
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 self.apikey, 'get_pull_request', pullrequestid=666)
project: added all source files and assets
r1 response = api_call(self.app, params)
expected = 'pull request `666` does not exist'
assert_error(id_, expected, given=response.body)
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395
def test_api_get_pull_request_pull_request_error_just_pr_id(self):
id_, params = build_data(
self.apikey, 'get_pull_request',
pullrequestid=666)
response = api_call(self.app, params)
expected = 'pull request `666` does not exist'
assert_error(id_, expected, given=response.body)