Skip to content

Commit dc7f900

Browse files
author
Mike Taylor
authored
Merge pull request #3452 from /issues/3445/1
Fixes #3445 - Add 2 more moderation milestones
2 parents b503153 + 5cf7bba commit dc7f900

8 files changed

+372
-225
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"action": "milestoned",
3+
"issue": {
4+
"title": "www.netflix.com - test private issue accepted",
5+
"repository_url": "https://api.github.com/repos/webcompat/webcompat-tests-private",
6+
"number": 600,
7+
"body": "<!-- @browser: Firefox 55.0 -->\n<!-- @ua_header: Mozilla/5.0 (X11; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0 -->\n<!-- @reported_with: web -->\n<!-- @public_url: https://github.com/webcompat/webcompat-tests/issues/1 -->\n\n**URL**: https://www.netflix.com/",
8+
"labels": [
9+
{
10+
"id": 1788251357,
11+
"node_id": "MDU6TGFiZWwxNzg4MjUxMzU3",
12+
"url": "https://api.github.com/repos/webcompat/webcompat-tests/labels/action-needsmoderation",
13+
"name": "action-needsmoderation",
14+
"color": "d36200",
15+
"default": false,
16+
"description": "issue in the process of being moderated"
17+
}
18+
],
19+
"state": "open",
20+
"milestone": {
21+
"url": "https://api.github.com/repos/webcompat/webcompat-tests-private/milestones/2",
22+
"html_url": "https://github.com/webcompat/webcompat-tests-private/milestone/2",
23+
"labels_url": "https://api.github.com/repos/webcompat/webcompat-tests-private/milestones/2/labels",
24+
"id": 5092463,
25+
"node_id": "MDk6TWlsZXN0b25lNTA5MjQ2Mw==",
26+
"number": 2,
27+
"title": "accepted: incomplete",
28+
"description": "This is when a bug has been accepted for moderation",
29+
"open_issues": 0,
30+
"closed_issues": 2,
31+
"state": "open",
32+
"created_at": "2020-02-11T00:37:18Z",
33+
"updated_at": "2020-02-11T18:34:04Z",
34+
"due_on": null,
35+
"closed_at": null
36+
}
37+
},
38+
"milestone": {
39+
"title": "accepted: incomplete"
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"action": "milestoned",
3+
"issue": {
4+
"title": "www.netflix.com - test private issue accepted",
5+
"repository_url": "https://api.github.com/repos/webcompat/webcompat-tests-private",
6+
"number": 600,
7+
"body": "<!-- @browser: Firefox 55.0 -->\n<!-- @ua_header: Mozilla/5.0 (X11; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0 -->\n<!-- @reported_with: web -->\n<!-- @public_url: https://github.com/webcompat/webcompat-tests/issues/1 -->\n\n**URL**: https://www.netflix.com/",
8+
"labels": [
9+
{
10+
"id": 1788251357,
11+
"node_id": "MDU6TGFiZWwxNzg4MjUxMzU3",
12+
"url": "https://api.github.com/repos/webcompat/webcompat-tests/labels/action-needsmoderation",
13+
"name": "action-needsmoderation",
14+
"color": "d36200",
15+
"default": false,
16+
"description": "issue in the process of being moderated"
17+
}
18+
],
19+
"state": "open",
20+
"milestone": {
21+
"url": "https://api.github.com/repos/webcompat/webcompat-tests-private/milestones/2",
22+
"html_url": "https://github.com/webcompat/webcompat-tests-private/milestone/2",
23+
"labels_url": "https://api.github.com/repos/webcompat/webcompat-tests-private/milestones/2/labels",
24+
"id": 5092463,
25+
"node_id": "MDk6TWlsZXN0b25lNTA5MjQ2Mw==",
26+
"number": 2,
27+
"title": "accepted: invalid",
28+
"description": "This is when a bug has been accepted for moderation",
29+
"open_issues": 0,
30+
"closed_issues": 2,
31+
"state": "open",
32+
"created_at": "2020-02-11T00:37:18Z",
33+
"updated_at": "2020-02-11T18:34:04Z",
34+
"due_on": null,
35+
"closed_at": null
36+
}
37+
},
38+
"milestone": {
39+
"title": "accepted: invalid"
40+
}
41+
}

tests/unit/test_webhook.py

+26-138
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"""Tests for our webhooks: HTTP handling and helper methods."""
88

99
import json
10-
import logging
1110
import os
1211
import unittest
1312
from unittest.mock import patch
@@ -21,23 +20,13 @@
2120
from webcompat.db import Site
2221
from webcompat.helpers import to_bytes
2322
from webcompat.webhooks import helpers
24-
from webcompat.webhooks.helpers import process_issue_action
2523
from webcompat.webhooks.model import WebHookIssue
2624

2725

2826
# The key is being used for testing and computing the signature.
2927
# The key needs to be a bytes object
3028
key = to_bytes(webcompat.app.config['HOOK_SECRET_KEY'])
3129

32-
# Some expected responses as tuples
33-
accepted = ('Moderated issue accepted', 200, {'Content-Type': 'text/plain'})
34-
rejected = ('Moderated issue rejected', 200, {'Content-Type': 'text/plain'})
35-
boring = ('Not an interesting hook', 403, {'Content-Type': 'text/plain'})
36-
gracias = ('gracias, amigo.', 200, {'Content-Type': 'text/plain'})
37-
wrong_repo = ('Wrong repository', 403, {'Content-Type': 'text/plain'})
38-
oops = ('oops', 400, {'Content-Type': 'text/plain'})
39-
comment_added = ('public url added', 200, {'Content-Type': 'text/plain'})
40-
4130

4231
# Some machinery for opening our test files
4332
def event_data(filename):
@@ -422,6 +411,32 @@ def test_repo_scope_unknown(self):
422411
actual = helpers.repo_scope(url)
423412
self.assertEqual(expected, actual)
424413

414+
def test_prepare_incomplete_issue(self):
415+
"""Test we prepare the right payload for the incomplete issue."""
416+
expected = {'body': '<p>Thanks for the report. Unfortunately without any\ndetail about the issue you experienced, we cannot help with this bug.\nPlease leave a comment with more detail, or file a new report and we will\ngladly investigate this further.</p>', # noqa
417+
'milestone': 7,
418+
'state': 'closed',
419+
'title': 'Test incomplete title!'}
420+
actual = helpers.prepare_incomplete_issue('Test incomplete title!')
421+
self.assertEqual(type(actual), dict)
422+
self.assertEqual(actual, expected)
423+
424+
def test_prepare_invalid_issue(self):
425+
"""Test we prepare the right payload for the invalid issue."""
426+
expected = {'body': '<p>Thanks for the report, but this is not a Compatibility\nissue.</p><p>For this project we try to focus our effort on layouts, features\nor content that works as expected in one browser but not in another.\nClosing the issue as Invalid.</p>', # noqa
427+
'milestone': 8,
428+
'state': 'closed',
429+
'title': 'Test invalid title!'}
430+
actual = helpers.prepare_invalid_issue('Test invalid title!')
431+
self.assertEqual(type(actual), dict)
432+
self.assertEqual(actual, expected)
433+
434+
def test_prepare_issue_no_title(self):
435+
"""Test we raise for missing title arguements."""
436+
with pytest.raises(ValueError) as excinfo:
437+
helpers.prepare_invalid_issue()
438+
helpers.prepare_incomplete_issue()
439+
425440
def test_prepare_rejected_issue(self):
426441
"""Test we prepare the right payload for the rejected issue."""
427442
expected = {'body': "<p>The content of this issue doesn't meet our\n"
@@ -436,132 +451,5 @@ def test_prepare_rejected_issue(self):
436451
self.assertEqual(actual, expected)
437452

438453

439-
@patch('webcompat.webhooks.model.make_request')
440-
def test_process_issue_action_right_repo(mock_mr):
441-
"""Test that repository_url matches the CONFIG for public repo."""
442-
mock_mr.return_value.status_code == 200
443-
json_event, signature = event_data('new_event_valid.json')
444-
payload = json.loads(json_event)
445-
issue = WebHookIssue.from_dict(payload)
446-
with webcompat.app.test_request_context():
447-
rv = process_issue_action(issue)
448-
assert rv == gracias
449-
450-
451-
def test_process_issue_action_wrong_repo():
452-
"""Test when repository_url differs from the CONFIG for public repo."""
453-
json_event, signature = event_data('wrong_repo.json')
454-
payload = json.loads(json_event)
455-
issue = WebHookIssue.from_dict(payload)
456-
with webcompat.app.test_request_context():
457-
rv = process_issue_action(issue)
458-
assert rv == wrong_repo
459-
460-
461-
def test_process_issue_action_wrong_repo():
462-
"""Test for issues in the wrong repo."""
463-
json_event, signature = event_data(
464-
'private_milestone_accepted_wrong_repo.json')
465-
payload = json.loads(json_event)
466-
issue = WebHookIssue.from_dict(payload)
467-
with webcompat.app.test_request_context():
468-
rv = process_issue_action(issue)
469-
assert rv == wrong_repo
470-
471-
472-
@patch('webcompat.webhooks.model.make_request')
473-
def test_process_issue_action_acceptable_issue(mock_mr):
474-
"""Test for acceptable issues from private repo."""
475-
mock_mr.return_value.status_code == 200
476-
json_event, signature = event_data('private_milestone_accepted.json')
477-
payload = json.loads(json_event)
478-
issue = WebHookIssue.from_dict(payload)
479-
with webcompat.app.test_request_context():
480-
rv = process_issue_action(issue)
481-
assert rv == accepted
482-
483-
484-
@patch('webcompat.webhooks.model.make_request')
485-
def test_process_issue_action_private_issue_moderated_ok(mock_mr):
486-
"""Test for private issue successfully moderated."""
487-
mock_mr.return_value.status_code == 200
488-
json_event, signature = event_data('private_milestone_accepted.json')
489-
payload = json.loads(json_event)
490-
issue = WebHookIssue.from_dict(payload)
491-
with webcompat.app.test_request_context():
492-
rv = process_issue_action(issue)
493-
assert rv == accepted
494-
495-
496-
@patch('webcompat.webhooks.model.make_request')
497-
def test_process_issue_action_reject_issue(mock_mr):
498-
"""Test for rejected issues from private repo."""
499-
mock_mr.return_value.status_code == 200
500-
json_event, signature = event_data('private_milestone_closed.json')
501-
payload = json.loads(json_event)
502-
issue = WebHookIssue.from_dict(payload)
503-
with webcompat.app.test_request_context():
504-
rv = process_issue_action(issue)
505-
assert rv == rejected
506-
507-
508-
@patch('webcompat.webhooks.model.make_request')
509-
def test_process_issue_action_acceptable_issue_closed(mock_mr):
510-
"""Test for accepted issues being closed."""
511-
mock_mr.return_value.status_code == 200
512-
json_event, signature = event_data(
513-
'private_milestone_accepted_closed.json')
514-
payload = json.loads(json_event)
515-
issue = WebHookIssue.from_dict(payload)
516-
with webcompat.app.test_request_context():
517-
rv = process_issue_action(issue)
518-
assert rv == boring
519-
520-
521-
@patch('webcompat.webhooks.model.make_request')
522-
def test_process_issue_action_comment_public_uri(mock_mr):
523-
"""Test we are getting the right message on public uri comment."""
524-
mock_mr.return_value.status_code == 200
525-
json_event, signature = event_data('private_issue_opened.json')
526-
payload = json.loads(json_event)
527-
issue = WebHookIssue.from_dict(payload)
528-
with webcompat.app.test_request_context():
529-
rv = process_issue_action(issue)
530-
assert rv == comment_added
531-
532-
533-
@patch('webcompat.webhooks.model.make_request')
534-
def test_process_issue_action_github_api_exception(mock_mr, caplog):
535-
"""Test GitHub API exception handling.
536-
537-
Each of the test scenarios have the following:
538-
issue_payload, expected_log, method
539-
method is unused in the test, but is meant to provide context to
540-
the reader for where the exception is happening.
541-
"""
542-
caplog.set_level(logging.INFO)
543-
mock_mr.side_effect = HTTPError()
544-
mock_mr.status_code = 400
545-
scenarios = [
546-
('private_milestone_accepted.json',
547-
'private:moving to public failed', 'moderate_private_issue'),
548-
('private_issue_no_source.json', 'comment failed',
549-
'comment_public_uri'),
550-
('new_event_valid.json', 'public:opened labels failed',
551-
'tag_as_public'),
552-
('private_milestone_closed.json',
553-
'public rejection failed', 'reject_private_issue')
554-
]
555-
for scenario in scenarios:
556-
issue_payload, expected_log, method = scenario
557-
json_event, signature = event_data(issue_payload)
558-
payload = json.loads(json_event)
559-
issue = WebHookIssue.from_dict(payload)
560-
with webcompat.app.test_request_context():
561-
rv = process_issue_action(issue)
562-
assert rv == oops
563-
assert expected_log in caplog.text
564-
565-
566454
if __name__ == '__main__':
567455
unittest.main()

0 commit comments

Comments
 (0)