##// 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 44 'target_repo': 'tests/target_repo',
45 45 'source_ref': 'branch:default:initial',
46 46 'target_ref': 'branch:default:new-feature',
47 'title': 'Test PR 1'
48 47 }
49 48 for key in required_data:
50 49 data = required_data.copy()
@@ -95,14 +94,29 b' class TestCreatePullRequestApi(object):'
95 94 assert pull_request.description == ''
96 95
97 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 111 def test_create_with_reviewers_specified_by_names(
99 112 self, backend, no_notifications):
100 113 data = self._prepare_data(backend)
101 114 reviewers = [
102 115 {'username': TEST_USER_REGULAR_LOGIN,
103 'reasons': ['added manually']},
116 'reasons': ['{} added manually'.format(TEST_USER_REGULAR_LOGIN)]},
104 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 121 data['reviewers'] = reviewers
108 122 id_, params = build_data(
@@ -115,12 +129,24 b' class TestCreatePullRequestApi(object):'
115 129 assert result['result']['msg'] == expected_message
116 130 pull_request_id = result['result']['pull_request_id']
117 131 pull_request = PullRequestModel().get(pull_request_id)
118 actual_reviewers = [
119 {'username': r.user.username,
120 'reasons': ['added manually'],
121 } for r in pull_request.reviewers
122 ]
123 assert sorted(actual_reviewers) == sorted(reviewers)
132
133 actual_reviewers = []
134 for rev in pull_request.reviewers:
135 entry = {
136 'username': rev.user.username,
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 151 @pytest.mark.backends("git", "hg")
126 152 def test_create_with_reviewers_specified_by_ids(
@@ -146,12 +172,23 b' class TestCreatePullRequestApi(object):'
146 172 assert result['result']['msg'] == expected_message
147 173 pull_request_id = result['result']['pull_request_id']
148 174 pull_request = PullRequestModel().get(pull_request_id)
149 actual_reviewers = [
150 {'username': r.user.user_id,
151 'reasons': ['added manually'],
152 } for r in pull_request.reviewers
153 ]
154 assert sorted(actual_reviewers) == sorted(reviewers)
175
176 actual_reviewers = []
177 for rev in pull_request.reviewers:
178 entry = {
179 'username': rev.user.user_id,
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 193 @pytest.mark.backends("git", "hg")
157 194 def test_create_fails_when_the_reviewer_is_not_found(self, backend):
@@ -258,9 +295,10 b' class TestCreatePullRequestApi(object):'
258 295 def test_create_fails_when_no_permissions(self, backend):
259 296 data = self._prepare_data(backend)
260 297 RepoModel().revoke_user_permission(
261 self.source.repo_name, User.DEFAULT_USER)
298 self.source.repo_name, self.test_user)
262 299 RepoModel().revoke_user_permission(
263 self.source.repo_name, self.test_user)
300 self.source.repo_name, User.DEFAULT_USER)
301
264 302 id_, params = build_data(
265 303 self.apikey_regular, 'create_pull_request', **data)
266 304 response = api_call(self.app, params)
General Comments 0
You need to be logged in to leave comments. Login now