-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): improve API and docs. update docs. add examples
- Loading branch information
Showing
25 changed files
with
556 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[run] | ||
branch = True | ||
|
||
[report] | ||
exclude_lines = | ||
@abc.abstractmethod | ||
@abc.abstractproperty |
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,7 +1,7 @@ | ||
History | ||
======= | ||
|
||
0.1.0 (2016-11-25) | ||
0.1.0 (2016-11-27) | ||
----------------- | ||
|
||
- First version. | ||
- First version (beta) |
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 +1,7 @@ | ||
include README.rst LICENSE History.rst requirements-dev.txt | ||
include README.rst LICENSE History.rst | ||
|
||
include requirements.txt | ||
include requirements-dev.txt | ||
|
||
prune docs/_build | ||
prune tasks |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pook | ||
import requests | ||
|
||
|
||
@pook.get('http://httpbin.org/status/500', reply=204) | ||
@pook.get('http://httpbin.org/status/400', reply=200) | ||
def fetch(url): | ||
return requests.get(url) | ||
|
||
res = fetch('http://httpbin.org/status/400') | ||
print('#1 status:', res.status_code) | ||
|
||
res = fetch('http://httpbin.org/status/500') | ||
print('#2 status:', res.status_code) | ||
|
||
print('Is done:', pook.isdone()) | ||
print('Pending mocks:', pook.pending_mocks()) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pook | ||
import requests | ||
|
||
|
||
def on_match(request, mock): | ||
print('On match:', request, mock) | ||
|
||
|
||
with pook.use(): | ||
pook.get('httpbin.org/ip', | ||
reply=403, response_type='json', | ||
response_headers={'pepe': 'lopez'}, | ||
response_json={'error': 'not found'}, | ||
callback=on_match) | ||
|
||
res = requests.get('http://httpbin.org/ip') | ||
print('Status:', res.status_code) | ||
print('Headers:', res.headers) | ||
print('Body:', res.json()) | ||
|
||
print('Is done:', pook.isdone()) | ||
print('Pending mocks:', pook.pending_mocks()) | ||
print('Unmatched requests:', pook.unmatched_requests()) |
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,14 @@ | ||
import pook | ||
import requests | ||
|
||
# Simulated error exception | ||
error = Exception('simulated error') | ||
|
||
with pook.use(): | ||
# Define mock to intercept | ||
pook.get('httpbin.org/status/500', error=error) | ||
|
||
try: | ||
requests.get('http://httpbin.org/status/500') | ||
except Exception as err: | ||
print('Error:', err) |
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,17 @@ | ||
import pook | ||
import urllib3 | ||
|
||
|
||
# Mock HTTP traffic only in the given context | ||
with pook.use(): | ||
pook.get('http://httpbin.org/status/404').reply(204) | ||
|
||
# Intercept request | ||
http = urllib3.PoolManager() | ||
r = http.request('GET', 'http://httpbin.org/status/404') | ||
print('#1 status:', r.status) | ||
|
||
# Real request outside of the context manager | ||
http = urllib3.PoolManager() | ||
r = http.request('GET', 'http://httpbin.org/status/404') | ||
print('#2 status:', r.status) |
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
Oops, something went wrong.