-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test the plugin for
pook
separately (#256)
* Test the plugin for `pook` separately. * Better Makefile.
- Loading branch information
1 parent
e7e8172
commit 17fd151
Showing
6 changed files
with
47 additions
and
52 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
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 |
---|---|---|
@@ -1,29 +1,31 @@ | ||
import pook | ||
import requests | ||
import contextlib | ||
|
||
from mocket.plugins.pook_mock_engine import MocketEngine | ||
with contextlib.suppress(ModuleNotFoundError): | ||
import pook | ||
import requests | ||
|
||
pook.set_mock_engine(MocketEngine) | ||
from mocket.plugins.pook_mock_engine import MocketEngine | ||
|
||
pook.set_mock_engine(MocketEngine) | ||
|
||
@pook.on | ||
def test_pook_engine(): | ||
url = "http://twitter.com/api/1/foobar" | ||
status = 404 | ||
response_json = {"error": "foo"} | ||
@pook.on | ||
def test_pook_engine(): | ||
url = "http://twitter.com/api/1/foobar" | ||
status = 404 | ||
response_json = {"error": "foo"} | ||
|
||
mock = pook.get( | ||
url, | ||
headers={"content-type": "application/json"}, | ||
reply=status, | ||
response_json=response_json, | ||
) | ||
mock.persist() | ||
mock = pook.get( | ||
url, | ||
headers={"content-type": "application/json"}, | ||
reply=status, | ||
response_json=response_json, | ||
) | ||
mock.persist() | ||
|
||
requests.get(url) | ||
assert mock.calls == 1 | ||
requests.get(url) | ||
assert mock.calls == 1 | ||
|
||
resp = requests.get(url) | ||
assert resp.status_code == status | ||
assert resp.json() == response_json | ||
assert mock.calls == 2 | ||
resp = requests.get(url) | ||
assert resp.status_code == status | ||
assert resp.json() == response_json | ||
assert mock.calls == 2 |