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