##// END OF EJS Templates
tests: Add shadow clone url to expected api return value.
Martin Bornhold -
r908:e816bfab default
parent child Browse files
Show More
@@ -1,122 +1,128 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2016 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21
22 22 import mock
23 23 import pytest
24 24 import urlobject
25 25 from pylons import url
26 26
27 27 from rhodecode.api.tests.utils import (
28 28 build_data, api_call, assert_error, assert_ok)
29 29
30 30 pytestmark = pytest.mark.backends("git", "hg")
31 31
32 32
33 33 @pytest.mark.usefixtures("testuser_api", "app")
34 34 class TestGetPullRequest(object):
35 35
36 36 def test_api_get_pull_request(self, pr_util):
37 from rhodecode.model.pull_request import PullRequestModel
37 38 pull_request = pr_util.create_pull_request(mergeable=True)
38 39 id_, params = build_data(
39 40 self.apikey, 'get_pull_request',
40 41 repoid=pull_request.target_repo.repo_name,
41 42 pullrequestid=pull_request.pull_request_id)
42 43
43 44 response = api_call(self.app, params)
44 45
45 46 assert response.status == '200 OK'
46 47
47 48 url_obj = urlobject.URLObject(
48 49 url(
49 50 'pullrequest_show',
50 51 repo_name=pull_request.target_repo.repo_name,
51 52 pull_request_id=pull_request.pull_request_id, qualified=True))
52 53 pr_url = unicode(
53 54 url_obj.with_netloc('test.example.com:80'))
54 55 source_url = unicode(
55 56 pull_request.source_repo.clone_url()
56 57 .with_netloc('test.example.com:80'))
57 58 target_url = unicode(
58 59 pull_request.target_repo.clone_url()
59 60 .with_netloc('test.example.com:80'))
61 shadow_url = unicode(
62 PullRequestModel().get_shadow_clone_url(pull_request))
60 63 expected = {
61 64 'pull_request_id': pull_request.pull_request_id,
62 65 'url': pr_url,
63 66 'title': pull_request.title,
64 67 'description': pull_request.description,
65 68 'status': pull_request.status,
66 69 'created_on': pull_request.created_on,
67 70 'updated_on': pull_request.updated_on,
68 71 'commit_ids': pull_request.revisions,
69 72 'review_status': pull_request.calculated_review_status(),
70 73 'mergeable': {
71 74 'status': True,
72 75 'message': 'This pull request can be automatically merged.',
73 76 },
74 77 'source': {
75 78 'clone_url': source_url,
76 79 'repository': pull_request.source_repo.repo_name,
77 80 'reference': {
78 81 'name': pull_request.source_ref_parts.name,
79 82 'type': pull_request.source_ref_parts.type,
80 83 'commit_id': pull_request.source_ref_parts.commit_id,
81 84 },
82 85 },
83 86 'target': {
84 87 'clone_url': target_url,
85 88 'repository': pull_request.target_repo.repo_name,
86 89 'reference': {
87 90 'name': pull_request.target_ref_parts.name,
88 91 'type': pull_request.target_ref_parts.type,
89 92 'commit_id': pull_request.target_ref_parts.commit_id,
90 93 },
91 94 },
95 'shadow': {
96 'clone_url': shadow_url,
97 },
92 98 'author': pull_request.author.get_api_data(include_secrets=False,
93 99 details='basic'),
94 100 'reviewers': [
95 101 {
96 102 'user': reviewer.get_api_data(include_secrets=False,
97 103 details='basic'),
98 104 'reasons': reasons,
99 105 'review_status': st[0][1].status if st else 'not_reviewed',
100 106 }
101 107 for reviewer, reasons, st in pull_request.reviewers_statuses()
102 108 ]
103 109 }
104 110 assert_ok(id_, expected, response.body)
105 111
106 112 def test_api_get_pull_request_repo_error(self):
107 113 id_, params = build_data(
108 114 self.apikey, 'get_pull_request',
109 115 repoid=666, pullrequestid=1)
110 116 response = api_call(self.app, params)
111 117
112 118 expected = 'repository `666` does not exist'
113 119 assert_error(id_, expected, given=response.body)
114 120
115 121 def test_api_get_pull_request_pull_request_error(self):
116 122 id_, params = build_data(
117 123 self.apikey, 'get_pull_request',
118 124 repoid=1, pullrequestid=666)
119 125 response = api_call(self.app, params)
120 126
121 127 expected = 'pull request `666` does not exist'
122 128 assert_error(id_, expected, given=response.body)
General Comments 0
You need to be logged in to leave comments. Login now