This repository has been archived by the owner on Aug 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow no content responses from GitHub (#937)
* Replace top level Variable.get calls with template renders This also fixes an issue where the dry run variable could never be set to "false" locally since it was not JSON decoded. * Add GitHubAPI tests, pook testing library * Don't attempt to decode nothing, remove inaccurate return type
- Loading branch information
1 parent
12c3f20
commit 63cd4e3
Showing
4 changed files
with
67 additions
and
6 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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
flaky==3.7.0 | ||
ipython | ||
pook==1.0.2 | ||
pytest-mock==3.10.0 | ||
pytest-raises==0.11 | ||
pytest-socket==0.5.1 | ||
|
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,56 @@ | ||
import pook | ||
import pytest | ||
from common.github import GitHubAPI | ||
from requests import HTTPError | ||
|
||
|
||
SAMPLE_PAT = "foobar" | ||
|
||
|
||
@pytest.fixture | ||
def github(): | ||
return GitHubAPI(pat=SAMPLE_PAT) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"method, resource, status_code, response_text, expected", | ||
[ | ||
# Standard replies | ||
("get", "repos/WordPress/openverse/pulls", 200, "[]", []), | ||
( | ||
"put", | ||
"repos/WordPress/openverse/pull", | ||
200, | ||
'{"key":"value","a":2}', | ||
{"key": "value", "a": 2}, | ||
), | ||
# 204 No Content reply | ||
("delete", "repos/WordPress/openverse/comment/555", 204, "", None), | ||
# Failure replies | ||
pytest.param( | ||
"get", | ||
"repos/WordPress/openverse/pulls", | ||
400, | ||
"[]", | ||
[], | ||
marks=pytest.mark.raises(exception=HTTPError), | ||
), | ||
pytest.param( | ||
"get", | ||
"repos/WordPress/openverse/pulls", | ||
500, | ||
"[]", | ||
[], | ||
marks=pytest.mark.raises(exception=HTTPError), | ||
), | ||
], | ||
) | ||
@pook.on | ||
def test_github_make_request( | ||
method, resource, status_code, response_text, expected, github | ||
): | ||
pook_func = getattr(pook, method.lower()) | ||
pook_func(f"https://api.github.com/{resource}").reply(status_code).body( | ||
response_text | ||
) | ||
assert github._make_request(method, resource) == expected |