Skip to content

Commit

Permalink
Improve the test coverage for util.py (#114)
Browse files Browse the repository at this point in the history
Add requests-mock dependency.
  • Loading branch information
Mariatta authored Jun 30, 2018
1 parent 7e0cfb8 commit 8497868
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
pytest==3.6.2
pytest-asyncio==0.8.0
pytest-aiohttp==0.3.0
requests-mock==1.5.0
2 changes: 2 additions & 0 deletions miss_islington/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def comment_on_pr(issue_number, message):
else:
print(response.status_code)
print(response.text)
return response


def assign_pr_to_core_dev(issue_number, coredev_login):
Expand All @@ -44,6 +45,7 @@ def assign_pr_to_core_dev(issue_number, coredev_login):
else:
print(response.status_code)
print(response.text)
return response


async def leave_comment(gh, pr_number, message):
Expand Down
47 changes: 47 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,50 @@ def test_pr_is_awaiting_merge():
def test_pr_is_not_awaiting_merge():
labels = [{"name": "CLA Signed", "name": "skip issue", "name": "awaiting review"}]
assert util.pr_is_awaiting_merge(labels) is False


def test_comment_on_pr_success(requests_mock):
issue_number = 100
message = "Thanks for the PR!"
post_url = (
f"https://api.github.com/repos/python/cpython/issues/{issue_number}/comments"
)
requests_mock.post(
post_url,
json={
"html_url": "https://github.com/python/cpython/pull/{issue_number}#issuecomment-401309376"
},
status_code=201,
)
response = util.comment_on_pr(issue_number, message)
assert response.status_code == 201


def test_comment_on_pr_failure(requests_mock):
issue_number = 100
message = "Thanks for the PR!"
post_url = (
f"https://api.github.com/repos/python/cpython/issues/{issue_number}/comments"
)
requests_mock.post(post_url, status_code=400)
response = util.comment_on_pr(issue_number, message)
assert response.status_code == 400


def test_assign_pr_to_coredev_success(requests_mock):

issue_number = 100
coredev_login = "Mariatta"
patch_url = f"https://api.github.com/repos/python/cpython/issues/{issue_number}"
requests_mock.patch(patch_url, status_code=201)
response = util.assign_pr_to_core_dev(issue_number, coredev_login)
assert response.status_code == 201


def test_assign_pr_to_coredev_failed(requests_mock):
issue_number = 100
coredev_login = "Mariatta"
patch_url = f"https://api.github.com/repos/python/cpython/issues/{issue_number}"
requests_mock.patch(patch_url, status_code=400)
response = util.assign_pr_to_core_dev(issue_number, coredev_login)
assert response.status_code == 400

0 comments on commit 8497868

Please sign in to comment.