-
-
Notifications
You must be signed in to change notification settings - Fork 31k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write more tests and improve coverage (GH-59)
- Loading branch information
Showing
10 changed files
with
667 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
from gidgethub import sansio | ||
|
||
from miss_islington import delete_branch | ||
|
||
|
||
class FakeGH: | ||
|
||
def __init__(self): | ||
self.post_data = None | ||
|
||
async def post(self, url, *, data): | ||
self.post_url = url | ||
self.post_data = data | ||
|
||
async def delete(self, url): | ||
self.delete_url = url | ||
|
||
|
||
async def test_branch_deleted_when_pr_merged(): | ||
data = { | ||
"action": "closed", | ||
"pull_request": { | ||
"number": 5722, | ||
"user": { | ||
"login": "miss-islington", | ||
}, | ||
"merged": True, | ||
"merged_by": { | ||
"login": "miss-islington", | ||
}, | ||
"head": { | ||
"ref": "backport-17ab8f0-3.7", | ||
} | ||
} | ||
} | ||
event = sansio.Event(data, event='pull_request', | ||
delivery_id='1') | ||
|
||
gh = FakeGH() | ||
await delete_branch.router.dispatch(event, gh) | ||
assert len(gh.post_data["body"]) is not None # leaves a comment | ||
assert gh.delete_url == f"/repos/miss-islington/cpython/git/refs/heads/{data['pull_request']['head']['ref']}" | ||
|
||
|
||
async def test_branch_deleted_and_thank_committer(): | ||
data = { | ||
"action": "closed", | ||
"pull_request": { | ||
"number": 5722, | ||
"user": { | ||
"login": "miss-islington", | ||
}, | ||
"merged": True, | ||
"merged_by": { | ||
"login": "Mariatta", | ||
}, | ||
"head": { | ||
"ref": "backport-17ab8f0-3.7", | ||
} | ||
} | ||
} | ||
event = sansio.Event(data, event='pull_request', | ||
delivery_id='1') | ||
|
||
gh = FakeGH() | ||
await delete_branch.router.dispatch(event, gh) | ||
assert gh.post_data["body"] == 'Thanks, @Mariatta!' # leaves a comment | ||
assert gh.delete_url == f"/repos/miss-islington/cpython/git/refs/heads/{data['pull_request']['head']['ref']}" | ||
|
||
|
||
async def test_branch_deleted_and_thanks(): | ||
data = { | ||
"action": "closed", | ||
"pull_request": { | ||
"number": 5722, | ||
"user": { | ||
"login": "miss-islington", | ||
}, | ||
"merged": True, | ||
"merged_by": { | ||
"login": "miss-islington", | ||
}, | ||
"head": { | ||
"ref": "backport-17ab8f0-3.7", | ||
} | ||
} | ||
} | ||
event = sansio.Event(data, event='pull_request', | ||
delivery_id='1') | ||
|
||
gh = FakeGH() | ||
await delete_branch.router.dispatch(event, gh) | ||
assert gh.post_data["body"] == "Thanks!" # leaves a comment | ||
assert gh.delete_url == f"/repos/miss-islington/cpython/git/refs/heads/{data['pull_request']['head']['ref']}" | ||
|
||
|
||
async def test_branch_deleted_when_pr_closed(): | ||
data = { | ||
"action": "closed", | ||
"pull_request": { | ||
"number": 5722, | ||
"user": { | ||
"login": "miss-islington", | ||
}, | ||
"merged": False, | ||
"merged_by": { | ||
"login": None, | ||
}, | ||
"head": { | ||
"ref": "backport-17ab8f0-3.7", | ||
} | ||
} | ||
} | ||
event = sansio.Event(data, event='pull_request', | ||
delivery_id='1') | ||
|
||
gh = FakeGH() | ||
await delete_branch.router.dispatch(event, gh) | ||
assert gh.post_data is None # does not leave a comment | ||
assert gh.delete_url == f"/repos/miss-islington/cpython/git/refs/heads/{data['pull_request']['head']['ref']}" | ||
|
||
|
||
async def test_ignore_non_miss_islingtons_prs(): | ||
data = { | ||
"action": "closed", | ||
"pull_request": { | ||
"number": 5722, | ||
"user": { | ||
"login": "Mariatta", | ||
}, | ||
"merged": True, | ||
"merged_by": { | ||
"login": "Mariatta", | ||
}, | ||
"head": { | ||
"ref": "backport-17ab8f0-3.7", | ||
} | ||
} | ||
} | ||
event = sansio.Event(data, event='pull_request', | ||
delivery_id='1') | ||
gh = FakeGH() | ||
await delete_branch.router.dispatch(event, gh) | ||
assert gh.post_data is None # does not leave a comment | ||
assert not hasattr(gh, 'delete_url') |
Oops, something went wrong.