Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump gidgethub from 4.2.0 to 5.0.1 #326

Merged
merged 2 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ testpaths = tests
filterwarnings =
error
ignore::DeprecationWarning
ignore::pytest.PytestUnraisableExceptionWarning
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ appdirs==1.4.4
async-timeout==3.0.1
cachetools==4.2.2
chardet==4.0.0
gidgethub==4.2.0
gidgethub==5.0.1
multidict==5.1.0
packaging==20.9
py==1.10.0
Expand Down
24 changes: 17 additions & 7 deletions tests/test_backport.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,15 @@ async def test_backport_label_removal_success():
issue_data = getitem_data['https://api.github.com/issue/1234']
assert gh.delete_url == sansio.format_url(issue_data['labels_url'],
{'name': 'needs backport to 3.6'})
post = gh.post_[0]
assert post[0] == issue_data['comments_url']
message = post[1]['body']
assert message == backport.MESSAGE_TEMPLATE.format(branch='3.6', pr='2248')
assert len(gh.post_) > 0
expected_post = None
for post in gh.post_:
if post[0] == issue_data['comments_url']:
expected_post = post
message = post[1]['body']
assert message == backport.MESSAGE_TEMPLATE.format(branch='3.6', pr='2248')

assert expected_post is not None


async def test_backport_label_removal_with_leading_space_in_title():
Expand Down Expand Up @@ -244,9 +249,14 @@ async def test_label_copying():
}
gh = FakeGH(getitem=getitem_data)
await backport.router.dispatch(event, gh)
post = gh.post_[0]
assert post[0] == 'https://api.github.com/issue/1234/labels'
assert {'skip news', 'type-enhancement', 'sprint'} == frozenset(post[1])
assert len(gh.post_) > 0
expected_post = None
for post in gh.post_:
if post[0] == 'https://api.github.com/issue/1234/labels':
assert {'skip news', 'type-enhancement', 'sprint'} == frozenset(post[1])
expected_post = post

assert expected_post is not None


@pytest.mark.parametrize('action', ['opened', 'reopened', 'edited', 'synchronize'])
Expand Down
113 changes: 64 additions & 49 deletions tests/test_bpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,29 @@

class FakeGH:

def __init__(self, *, getitem=None):
def __init__(self, *, getitem=None, post=None, patch=None):
self._getitem_return = getitem
self.patch_url = None
self.patch_data = None
self.data = None
self._post_return = post
self.post_url = []
self.post_data = []
self._patch_return = patch
self.patch_url = []
self.patch_data = []

async def getitem(self, url):
return self._getitem_return

async def post(self, url, data):
self.url = url
self.data = data
async def post(self, url, *, data):
self.post_url.append(url)
self.post_data.append(data)
return self._post_return

async def patch(self, url, data):
self.patch_url = url
self.patch_data = data
async def patch(self, url, *, data):
self.patch_url.append(url)
self.patch_data.append(data)
return self._patch_return


@pytest.mark.asyncio
Expand All @@ -49,7 +56,7 @@ async def test_set_status_failure(action, monkeypatch):
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH(getitem=issue_data)
await bpo.router.dispatch(event, gh, session=None)
status = gh.data
status = gh.post_data[0]
assert status["state"] == "failure"
assert status["target_url"].startswith("https://devguide.python.org")
assert status["context"] == "bedevere/issue-number"
Expand All @@ -70,15 +77,14 @@ async def test_set_status_failure_via_issue_not_found_on_bpo(action):
gh = FakeGH()
async with aiohttp.ClientSession() as session:
await bpo.router.dispatch(event, gh, session=session)
status = gh.data
status = gh.post_data[0]
assert status["state"] == "failure"
assert status["target_url"].startswith("https://bugs.python.org")
assert status["context"] == "bedevere/issue-number"
assert status["description"] == "Issue #123 not found on bugs.python.org"


@pytest.mark.asyncio
@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning")
@pytest.mark.parametrize("action", ["opened", "synchronize", "reopened"])
async def test_set_status_success(action, monkeypatch):
monkeypatch.setattr(bpo, '_validate_issue_number',
Expand All @@ -93,17 +99,16 @@ async def test_set_status_success(action, monkeypatch):
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH()
await bpo.router.dispatch(event, gh, session=None)
status = gh.data
status = gh.post_data[0]
assert status["state"] == "success"
assert status["target_url"].endswith("issue1234")
assert "1234" in status["description"]
assert status["context"] == "bedevere/issue-number"
assert "git-sha" in gh.url
assert "git-sha" in gh.post_url[0]
bpo._validate_issue_number.assert_awaited_with("1234", session=None)


@pytest.mark.asyncio
@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning")
@pytest.mark.parametrize("action", ["opened", "synchronize", "reopened"])
async def test_set_status_success_issue_found_on_bpo(action):
data = {
Expand All @@ -117,16 +122,15 @@ async def test_set_status_success_issue_found_on_bpo(action):
gh = FakeGH()
async with aiohttp.ClientSession() as session:
await bpo.router.dispatch(event, gh, session=session)
status = gh.data
status = gh.post_data[0]
assert status["state"] == "success"
assert status["target_url"].endswith("issue12345")
assert "12345" in status["description"]
assert status["context"] == "bedevere/issue-number"
assert "git-sha" in gh.url
assert "git-sha" in gh.post_url[0]


@pytest.mark.asyncio
@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning")
@pytest.mark.parametrize("action", ["opened", "synchronize", "reopened"])
async def test_set_status_success_via_skip_issue_label(action, monkeypatch):
monkeypatch.setattr(bpo, '_validate_issue_number',
Expand All @@ -147,10 +151,10 @@ async def test_set_status_success_via_skip_issue_label(action, monkeypatch):
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH(getitem=issue_data)
await bpo.router.dispatch(event, gh, session=None)
status = gh.data
status = gh.post_data[0]
assert status["state"] == "success"
assert status["context"] == "bedevere/issue-number"
assert "git-sha" in gh.url
assert "git-sha" in gh.post_url[0]
bpo._validate_issue_number.assert_not_awaited()


Expand All @@ -169,7 +173,7 @@ async def test_edit_title(monkeypatch):
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH()
await bpo.router.dispatch(event, gh, session=None)
assert gh.data is not None
assert len(gh.post_data) == 1
bpo._validate_issue_number.assert_awaited_with("1234", session=None)


Expand All @@ -192,8 +196,8 @@ async def test_no_body_when_edit_title(monkeypatch):
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH()
await bpo.router.dispatch(event, gh, session=None)
assert gh.patch_data is not None
assert gh.patch_data["body"] == "\n\n<!-- issue-number: bpo-32636 -->\nhttps://bugs.python.org/issue32636\n<!-- /issue-number -->\n"
assert len(gh.patch_data) == 1
assert gh.patch_data[0]["body"] == "\n\n<!-- issue-number: bpo-32636 -->\nhttps://bugs.python.org/issue32636\n<!-- /issue-number -->\n"
bpo._validate_issue_number.assert_awaited_with("32636", session=None)


Expand All @@ -212,7 +216,8 @@ async def test_edit_other_than_title(monkeypatch):
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH()
await bpo.router.dispatch(event, gh, session=None)
assert gh.data is None
assert len(gh.patch_data) == 0
assert len(gh.post_data) == 0
bpo._validate_issue_number.assert_not_awaited()


Expand All @@ -229,8 +234,8 @@ async def test_new_label_skip_issue_no_issue():
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH()
await bpo.router.dispatch(event, gh)
assert gh.data["state"] == "success"
assert "git-sha" in gh.url
assert gh.post_data[0]["state"] == "success"
assert "git-sha" in gh.post_url[0]


@pytest.mark.asyncio
Expand All @@ -246,12 +251,12 @@ async def test_new_label_skip_issue_with_issue_number():
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH()
await bpo.router.dispatch(event, gh)
status = gh.data
status = gh.post_data[0]
assert status["state"] == "success"
assert status["target_url"].endswith("issue1234")
assert "1234" in status["description"]
assert status["context"] == "bedevere/issue-number"
assert "git-sha" in gh.url
assert "git-sha" in gh.post_url[0]


@pytest.mark.asyncio
Expand All @@ -266,7 +271,7 @@ async def test_new_label_not_skip_issue():
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH()
await bpo.router.dispatch(event, gh)
assert gh.data is None
assert len(gh.post_data) == 0


@pytest.mark.asyncio
Expand All @@ -286,7 +291,7 @@ async def test_removed_label_from_label_deletion(monkeypatch):
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH()
await bpo.router.dispatch(event, gh, session=None)
assert gh.data is None
assert len(gh.post_data) == 0
bpo._validate_issue_number.assert_not_awaited()


Expand All @@ -305,12 +310,12 @@ async def test_removed_label_skip_issue(monkeypatch):
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH()
await bpo.router.dispatch(event, gh, session=None)
status = gh.data
status = gh.post_data[0]
assert status["state"] == "success"
assert status["target_url"].endswith("issue1234")
assert "1234" in status["description"]
assert status["context"] == "bedevere/issue-number"
assert "git-sha" in gh.url
assert "git-sha" in gh.post_url[0]
bpo._validate_issue_number.assert_awaited_with("1234", session=None)


Expand All @@ -328,7 +333,7 @@ async def test_removed_label_non_skip_issue(monkeypatch):
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH()
await bpo.router.dispatch(event, gh, session=None)
assert gh.data is None
assert len(gh.post_data) == 0
bpo._validate_issue_number.assert_not_awaited()


Expand All @@ -348,9 +353,9 @@ async def test_set_body_success(monkeypatch):
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH()
await bpo.router.dispatch(event, gh, session=None)
status = gh.patch_data
status = gh.patch_data[0]
assert "https://bugs.python.org/issue1234" in status["body"]
assert "1347" in gh.patch_url
assert "1347" in gh.patch_url[0]
bpo._validate_issue_number.assert_awaited_with("1234", session=None)


Expand All @@ -370,8 +375,8 @@ async def test_set_body_failure(monkeypatch):
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH()
await bpo.router.dispatch(event, gh, session=None)
assert gh.patch_data is None
assert gh.patch_url is None
assert len(gh.patch_data) == 0
assert len(gh.patch_url) == 0
bpo._validate_issue_number.assert_awaited_with("1234", session=None)


Expand Down Expand Up @@ -405,10 +410,15 @@ async def set_pull_request_body_success_helper(action, monkeypatch):
event = sansio.Event(data, event="pull_request", delivery_id="123123")
gh = FakeGH()
await bpo.router.dispatch(event, gh, session=None)
body_data = gh.patch_data
assert "[bpo-12345](https://bugs.python.org/issue12345)" in body_data["body"]
assert "123456" in gh.patch_url
assert len(gh.patch_data) > 0
body_patched = False
for body_data in gh.patch_data:
if "[bpo-12345]" in body_data["body"]:
body_patched = True
assert "[bpo-12345](https://bugs.python.org/issue12345)" in body_data["body"]
assert data["pull_request"]["issue_url"] in gh.patch_url

assert body_patched is True

@pytest.mark.asyncio
@pytest.mark.parametrize("event,action", [("issue_comment", "created"),
Expand All @@ -427,9 +437,9 @@ async def test_set_comment_body_success(event, action):
event = sansio.Event(data, event=event, delivery_id="123123")
gh = FakeGH()
await bpo.router.dispatch(event, gh)
body_data = gh.patch_data
body_data = gh.patch_data[0]
assert "[bpo-12345](https://bugs.python.org/issue12345)" in body_data["body"]
assert "123456" in gh.patch_url
assert data["comment"]["url"] in gh.patch_url


@pytest.mark.asyncio
Expand Down Expand Up @@ -474,8 +484,8 @@ async def test_set_comment_body_without_bpo(event, action):
event = sansio.Event(data, event=event, delivery_id="123123")
gh = FakeGH()
await bpo.router.dispatch(event, gh)
assert gh.patch_data is None
assert gh.patch_url is None
assert len(gh.patch_data) == 0
assert len(gh.patch_url) == 0


@pytest.mark.asyncio
Expand Down Expand Up @@ -518,10 +528,15 @@ async def set_pull_request_body_already_hyperlinked_bpo_helper(action, monkeypat
event = sansio.Event(data, event="pull_request", delivery_id="123123")
gh = FakeGH()
await bpo.router.dispatch(event, gh, session=None)
body_data = gh.patch_data
assert body_data["body"].count("[bpo-123](https://bugs.python.org/issue123)") == 2
assert body_data["body"].count("[something about bpo-123](https://bugs.python.org/issue123)") == 1
assert "123456" in gh.patch_url
patched = False
for body_data in gh.patch_data:
if body_data["body"].startswith("[bpo-123]"):
patched = True
assert body_data["body"].count("[bpo-123](https://bugs.python.org/issue123)") == 2
assert body_data["body"].count("[something about bpo-123](https://bugs.python.org/issue123)") == 1
assert data["pull_request"]["issue_url"] in gh.patch_url

assert patched is True


@pytest.mark.asyncio
Expand All @@ -545,7 +560,7 @@ async def test_set_comment_body_already_hyperlinked_bpo(event, action):
event = sansio.Event(data, event=event, delivery_id="123123")
gh = FakeGH()
await bpo.router.dispatch(event, gh)
body_data = gh.patch_data
body_data = gh.patch_data[0]
assert body_data["body"].count("[bpo-123](https://bugs.python.org/issue123)") == 2
assert body_data["body"].count("[something about bpo-123](https://bugs.python.org/issue123)") == 1
assert "123456" in gh.patch_url
assert data["comment"]["url"] in gh.patch_url
1 change: 0 additions & 1 deletion tests/test_filepaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ async def post(self, url, *, data):
GOOD_BASENAME = '2017-06-16-20-32-50.bpo-1234.nonce.rst'


@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning")
async def test_news_only():
filenames = [{'filename': 'README', 'patch': '@@ -31,3 +31,7 @@ # Licensed to PSF under a Contributor Agreement.'},
{'filename': f'Misc/NEWS.d/next/Lib/{GOOD_BASENAME}', 'patch': '@@ -31,3 +31,7 @@ # Licensed to PSF under a Contributor Agreement.'},
Expand Down