|
22 | 22 | # Some expected responses as tuples
|
23 | 23 | accepted = ('Moderated issue accepted', 200, {'Content-Type': 'text/plain'})
|
24 | 24 | rejected = ('Moderated issue rejected', 200, {'Content-Type': 'text/plain'})
|
| 25 | +incomplete = ('Moderated issue closed as incomplete', |
| 26 | + 200, {'Content-Type': 'text/plain'}) |
| 27 | +invalid = ('Moderated issue closed as invalid', |
| 28 | + 200, {'Content-Type': 'text/plain'}) |
25 | 29 | boring = ('Not an interesting hook', 403, {'Content-Type': 'text/plain'})
|
26 | 30 | gracias = ('gracias, amigo.', 200, {'Content-Type': 'text/plain'})
|
27 | 31 | wrong_repo = ('Wrong repository', 403, {'Content-Type': 'text/plain'})
|
@@ -208,97 +212,27 @@ def test_prepare_accepted_issue(mock_priority):
|
208 | 212 |
|
209 | 213 |
|
210 | 214 | @patch('webcompat.webhooks.model.make_request')
|
211 |
| -def test_process_issue_action_right_repo(mock_mr): |
212 |
| - """Test that repository_url matches the CONFIG for public repo.""" |
213 |
| - mock_mr.return_value.status_code == 200 |
214 |
| - json_event, signature = event_data('new_event_valid.json') |
215 |
| - payload = json.loads(json_event) |
216 |
| - issue = WebHookIssue.from_dict(payload) |
217 |
| - with webcompat.app.test_request_context(): |
218 |
| - rv = issue.process_issue_action() |
219 |
| - assert rv == gracias |
220 |
| - |
221 |
| - |
222 |
| -def test_process_issue_action_wrong_repo(): |
223 |
| - """Test when repository_url differs from the CONFIG for public repo.""" |
224 |
| - json_event, signature = event_data('wrong_repo.json') |
225 |
| - payload = json.loads(json_event) |
226 |
| - issue = WebHookIssue.from_dict(payload) |
227 |
| - with webcompat.app.test_request_context(): |
228 |
| - rv = issue.process_issue_action() |
229 |
| - assert rv == wrong_repo |
230 |
| - |
231 |
| - |
232 |
| -def test_process_issue_action_wrong_repo(): |
233 |
| - """Test for issues in the wrong repo.""" |
234 |
| - json_event, signature = event_data( |
235 |
| - 'private_milestone_accepted_wrong_repo.json') |
236 |
| - payload = json.loads(json_event) |
237 |
| - issue = WebHookIssue.from_dict(payload) |
238 |
| - with webcompat.app.test_request_context(): |
239 |
| - rv = issue.process_issue_action() |
240 |
| - assert rv == wrong_repo |
241 |
| - |
242 |
| - |
243 |
| -@patch('webcompat.webhooks.model.make_request') |
244 |
| -def test_process_issue_action_acceptable_issue(mock_mr): |
245 |
| - """Test for acceptable issues from private repo.""" |
246 |
| - mock_mr.return_value.status_code == 200 |
247 |
| - json_event, signature = event_data('private_milestone_accepted.json') |
248 |
| - payload = json.loads(json_event) |
249 |
| - issue = WebHookIssue.from_dict(payload) |
250 |
| - with webcompat.app.test_request_context(): |
251 |
| - rv = issue.process_issue_action() |
252 |
| - assert rv == accepted |
253 |
| - |
254 |
| - |
255 |
| -@patch('webcompat.webhooks.model.make_request') |
256 |
| -def test_process_issue_action_private_issue_moderated_ok(mock_mr): |
257 |
| - """Test for private issue successfully moderated.""" |
258 |
| - mock_mr.return_value.status_code == 200 |
259 |
| - json_event, signature = event_data('private_milestone_accepted.json') |
260 |
| - payload = json.loads(json_event) |
261 |
| - issue = WebHookIssue.from_dict(payload) |
262 |
| - with webcompat.app.test_request_context(): |
263 |
| - rv = issue.process_issue_action() |
264 |
| - assert rv == accepted |
265 |
| - |
266 |
| - |
267 |
| -@patch('webcompat.webhooks.model.make_request') |
268 |
| -def test_process_issue_action_reject_issue(mock_mr): |
269 |
| - """Test for rejected issues from private repo.""" |
270 |
| - mock_mr.return_value.status_code == 200 |
271 |
| - json_event, signature = event_data('private_milestone_closed.json') |
272 |
| - payload = json.loads(json_event) |
273 |
| - issue = WebHookIssue.from_dict(payload) |
274 |
| - with webcompat.app.test_request_context(): |
275 |
| - rv = issue.process_issue_action() |
276 |
| - assert rv == rejected |
277 |
| - |
278 |
| - |
279 |
| -@patch('webcompat.webhooks.model.make_request') |
280 |
| -def test_process_issue_action_acceptable_issue_closed(mock_mr): |
281 |
| - """Test for accepted issues being closed.""" |
282 |
| - mock_mr.return_value.status_code == 200 |
283 |
| - json_event, signature = event_data( |
284 |
| - 'private_milestone_accepted_closed.json') |
285 |
| - payload = json.loads(json_event) |
286 |
| - issue = WebHookIssue.from_dict(payload) |
287 |
| - with webcompat.app.test_request_context(): |
288 |
| - rv = issue.process_issue_action() |
289 |
| - assert rv == boring |
290 |
| - |
291 |
| - |
292 |
| -@patch('webcompat.webhooks.model.make_request') |
293 |
| -def test_process_issue_action_comment_public_uri(mock_mr): |
294 |
| - """Test we are getting the right message on public uri comment.""" |
| 215 | +def test_process_issue_action_scenarios(mock_mr): |
| 216 | + """Test we are getting the right response for each scenario.""" |
| 217 | + test_data = [ |
| 218 | + ('new_event_valid.json', gracias), |
| 219 | + ('wrong_repo.json', wrong_repo), |
| 220 | + ('private_milestone_accepted_wrong_repo.json', wrong_repo), |
| 221 | + ('private_milestone_accepted.json', accepted), |
| 222 | + ('private_milestone_closed.json', rejected), |
| 223 | + ('private_milestone_accepted_incomplete.json', incomplete), |
| 224 | + ('private_milestone_accepted_invalid.json', invalid), |
| 225 | + ('private_milestone_accepted_closed.json', boring), |
| 226 | + ('private_issue_opened.json', comment_added) |
| 227 | + ] |
295 | 228 | mock_mr.return_value.status_code == 200
|
296 |
| - json_event, signature = event_data('private_issue_opened.json') |
297 |
| - payload = json.loads(json_event) |
298 |
| - issue = WebHookIssue.from_dict(payload) |
299 |
| - with webcompat.app.test_request_context(): |
300 |
| - rv = issue.process_issue_action() |
301 |
| - assert rv == comment_added |
| 229 | + for issue_event, expected_rv in test_data: |
| 230 | + json_event, signature = event_data(issue_event) |
| 231 | + payload = json.loads(json_event) |
| 232 | + issue = WebHookIssue.from_dict(payload) |
| 233 | + with webcompat.app.test_request_context(): |
| 234 | + rv = issue.process_issue_action() |
| 235 | + assert rv == expected_rv |
302 | 236 |
|
303 | 237 |
|
304 | 238 | @patch('webcompat.webhooks.model.make_request')
|
|
0 commit comments