##// END OF EJS Templates
tests: fixed pull_reques API tests
marcink -
r2862:260b7e82 stable
parent child Browse files
Show More
@@ -44,7 +44,6 b' class TestCreatePullRequestApi(object):'
44 'target_repo': 'tests/target_repo',
44 'target_repo': 'tests/target_repo',
45 'source_ref': 'branch:default:initial',
45 'source_ref': 'branch:default:initial',
46 'target_ref': 'branch:default:new-feature',
46 'target_ref': 'branch:default:new-feature',
47 'title': 'Test PR 1'
48 }
47 }
49 for key in required_data:
48 for key in required_data:
50 data = required_data.copy()
49 data = required_data.copy()
@@ -95,14 +94,29 b' class TestCreatePullRequestApi(object):'
95 assert pull_request.description == ''
94 assert pull_request.description == ''
96
95
97 @pytest.mark.backends("git", "hg")
96 @pytest.mark.backends("git", "hg")
97 def test_create_with_empty_title(self, backend):
98 data = self._prepare_data(backend)
99 data.pop('title')
100 id_, params = build_data(
101 self.apikey_regular, 'create_pull_request', **data)
102 response = api_call(self.app, params)
103 result = response.json
104 pull_request_id = result['result']['pull_request_id']
105 pull_request = PullRequestModel().get(pull_request_id)
106 data['ref'] = backend.default_branch_name
107 title = '{source_repo}#{ref} to {target_repo}'.format(**data)
108 assert pull_request.title == title
109
110 @pytest.mark.backends("git", "hg")
98 def test_create_with_reviewers_specified_by_names(
111 def test_create_with_reviewers_specified_by_names(
99 self, backend, no_notifications):
112 self, backend, no_notifications):
100 data = self._prepare_data(backend)
113 data = self._prepare_data(backend)
101 reviewers = [
114 reviewers = [
102 {'username': TEST_USER_REGULAR_LOGIN,
115 {'username': TEST_USER_REGULAR_LOGIN,
103 'reasons': ['added manually']},
116 'reasons': ['{} added manually'.format(TEST_USER_REGULAR_LOGIN)]},
104 {'username': TEST_USER_ADMIN_LOGIN,
117 {'username': TEST_USER_ADMIN_LOGIN,
105 'reasons': ['added manually']},
118 'reasons': ['{} added manually'.format(TEST_USER_ADMIN_LOGIN)],
119 'mandatory': True},
106 ]
120 ]
107 data['reviewers'] = reviewers
121 data['reviewers'] = reviewers
108 id_, params = build_data(
122 id_, params = build_data(
@@ -115,12 +129,24 b' class TestCreatePullRequestApi(object):'
115 assert result['result']['msg'] == expected_message
129 assert result['result']['msg'] == expected_message
116 pull_request_id = result['result']['pull_request_id']
130 pull_request_id = result['result']['pull_request_id']
117 pull_request = PullRequestModel().get(pull_request_id)
131 pull_request = PullRequestModel().get(pull_request_id)
118 actual_reviewers = [
132
119 {'username': r.user.username,
133 actual_reviewers = []
120 'reasons': ['added manually'],
134 for rev in pull_request.reviewers:
121 } for r in pull_request.reviewers
135 entry = {
122 ]
136 'username': rev.user.username,
123 assert sorted(actual_reviewers) == sorted(reviewers)
137 'reasons': rev.reasons,
138 }
139 if rev.mandatory:
140 entry['mandatory'] = rev.mandatory
141 actual_reviewers.append(entry)
142
143 # default reviewer will be added who is an owner of the repo
144 reviewers.append(
145 {'username': pull_request.author.username,
146 'reasons': [u'Default reviewer', u'Repository owner']},
147 )
148 assert sorted(actual_reviewers, key=lambda e: e['username']) \
149 == sorted(reviewers, key=lambda e: e['username'])
124
150
125 @pytest.mark.backends("git", "hg")
151 @pytest.mark.backends("git", "hg")
126 def test_create_with_reviewers_specified_by_ids(
152 def test_create_with_reviewers_specified_by_ids(
@@ -146,12 +172,23 b' class TestCreatePullRequestApi(object):'
146 assert result['result']['msg'] == expected_message
172 assert result['result']['msg'] == expected_message
147 pull_request_id = result['result']['pull_request_id']
173 pull_request_id = result['result']['pull_request_id']
148 pull_request = PullRequestModel().get(pull_request_id)
174 pull_request = PullRequestModel().get(pull_request_id)
149 actual_reviewers = [
175
150 {'username': r.user.user_id,
176 actual_reviewers = []
151 'reasons': ['added manually'],
177 for rev in pull_request.reviewers:
152 } for r in pull_request.reviewers
178 entry = {
153 ]
179 'username': rev.user.user_id,
154 assert sorted(actual_reviewers) == sorted(reviewers)
180 'reasons': rev.reasons,
181 }
182 if rev.mandatory:
183 entry['mandatory'] = rev.mandatory
184 actual_reviewers.append(entry)
185 # default reviewer will be added who is an owner of the repo
186 reviewers.append(
187 {'username': pull_request.author.user_id,
188 'reasons': [u'Default reviewer', u'Repository owner']},
189 )
190 assert sorted(actual_reviewers, key=lambda e: e['username']) \
191 == sorted(reviewers, key=lambda e: e['username'])
155
192
156 @pytest.mark.backends("git", "hg")
193 @pytest.mark.backends("git", "hg")
157 def test_create_fails_when_the_reviewer_is_not_found(self, backend):
194 def test_create_fails_when_the_reviewer_is_not_found(self, backend):
@@ -258,9 +295,10 b' class TestCreatePullRequestApi(object):'
258 def test_create_fails_when_no_permissions(self, backend):
295 def test_create_fails_when_no_permissions(self, backend):
259 data = self._prepare_data(backend)
296 data = self._prepare_data(backend)
260 RepoModel().revoke_user_permission(
297 RepoModel().revoke_user_permission(
261 self.source.repo_name, User.DEFAULT_USER)
298 self.source.repo_name, self.test_user)
262 RepoModel().revoke_user_permission(
299 RepoModel().revoke_user_permission(
263 self.source.repo_name, self.test_user)
300 self.source.repo_name, User.DEFAULT_USER)
301
264 id_, params = build_data(
302 id_, params = build_data(
265 self.apikey_regular, 'create_pull_request', **data)
303 self.apikey_regular, 'create_pull_request', **data)
266 response = api_call(self.app, params)
304 response = api_call(self.app, params)
General Comments 0
You need to be logged in to leave comments. Login now