test_get_pull_request.py
142 lines
| 5.7 KiB
| text/x-python
|
PythonLexer
r5608 | # Copyright (C) 2010-2024 RhodeCode GmbH | |||
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) | ||||
r1974 | from rhodecode.lib import helpers as h | |||
r5048 | from rhodecode.lib.str_utils import safe_str | |||
r1 | ||||
pytestmark = pytest.mark.backends("git", "hg") | ||||
@pytest.mark.usefixtures("testuser_api", "app") | ||||
class TestGetPullRequest(object): | ||||
r1807 | def test_api_get_pull_request(self, pr_util, http_host_only_stub): | |||
Martin Bornhold
|
r908 | from rhodecode.model.pull_request import PullRequestModel | ||
r1 | pull_request = pr_util.create_pull_request(mergeable=True) | |||
id_, params = build_data( | ||||
self.apikey, 'get_pull_request', | ||||
r3829 | pullrequestid=pull_request.pull_request_id, merge_state=True) | |||
r1 | ||||
response = api_call(self.app, params) | ||||
assert response.status == '200 OK' | ||||
url_obj = urlobject.URLObject( | ||||
r1974 | h.route_url( | |||
r1 | 'pullrequest_show', | |||
repo_name=pull_request.target_repo.repo_name, | ||||
r1974 | pull_request_id=pull_request.pull_request_id)) | |||
r1774 | ||||
r5048 | pr_url = safe_str( | |||
r1807 | url_obj.with_netloc(http_host_only_stub)) | |||
r5048 | source_url = safe_str( | |||
r1774 | pull_request.source_repo.clone_url().with_netloc(http_host_only_stub)) | |||
r5048 | target_url = safe_str( | |||
r1774 | pull_request.target_repo.clone_url().with_netloc(http_host_only_stub)) | |||
r5048 | shadow_url = safe_str( | |||
Martin Bornhold
|
r908 | PullRequestModel().get_shadow_clone_url(pull_request)) | ||
r1774 | ||||
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, | ||||
r3371 | 'state': pull_request.pull_request_state, | |||
r1 | '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
|
r1056 | 'merge': { | ||
Martin Bornhold
|
r908 | 'clone_url': shadow_url, | ||
Martin Bornhold
|
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
|
r908 | }, | ||
r1 | 'author': pull_request.author.get_api_data(include_secrets=False, | |||
details='basic'), | ||||
'reviewers': [ | ||||
{ | ||||
'user': reviewer.get_api_data(include_secrets=False, | ||||
details='basic'), | ||||
r873 | 'reasons': reasons, | |||
r1 | 'review_status': st[0][1].status if st else 'not_reviewed', | |||
} | ||||
r2484 | for obj, reviewer, reasons, mandatory, st in | |||
r1769 | pull_request.reviewers_statuses() | |||
r1 | ] | |||
} | ||||
assert_ok(id_, expected, response.body) | ||||
r2395 | def test_api_get_pull_request_repo_error(self, pr_util): | |||
pull_request = pr_util.create_pull_request() | ||||
r1 | id_, params = build_data( | |||
self.apikey, 'get_pull_request', | ||||
r2395 | repoid=666, pullrequestid=pull_request.pull_request_id) | |||
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( | ||||
r2395 | self.apikey, 'get_pull_request', pullrequestid=666) | |||
r1 | response = api_call(self.app, params) | |||
expected = 'pull request `666` does not exist' | ||||
assert_error(id_, expected, given=response.body) | ||||
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) | ||||