-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from funnel-io/add-request-to-response
Add request to response
- Loading branch information
Showing
7 changed files
with
97 additions
and
33 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 |
---|---|---|
@@ -1,50 +1,50 @@ | ||
from functools import partial | ||
from requests import Session | ||
from requtests.fake_adapter import FakeAdapter | ||
from requtests.fake_response import fake_response | ||
|
||
|
||
def fake_delete(*responses): | ||
return partial(fake_request(*responses), "delete") | ||
def fake_delete(*responses, assertions=None): | ||
return partial(fake_request(*responses, assertions=assertions), "delete") | ||
|
||
|
||
def fake_get(*responses): | ||
return partial(fake_request(*responses), "get") | ||
def fake_get(*responses, assertions=None): | ||
return partial(fake_request(*responses, assertions=assertions), "get") | ||
|
||
|
||
def fake_head(*responses): | ||
return partial(fake_request(*responses), "head") | ||
def fake_head(*responses, assertions=None): | ||
return partial(fake_request(*responses, assertions=assertions), "head") | ||
|
||
|
||
def fake_options(*responses): | ||
return partial(fake_request(*responses), "options") | ||
def fake_options(*responses, assertions=None): | ||
return partial(fake_request(*responses, assertions=assertions), "options") | ||
|
||
|
||
def fake_patch(*responses): | ||
return partial(fake_request(*responses), "patch") | ||
def fake_patch(*responses, assertions=None): | ||
return partial(fake_request(*responses, assertions=assertions), "patch") | ||
|
||
|
||
def fake_post(*responses): | ||
return partial(fake_request(*responses), "post") | ||
def fake_post(*responses, assertions=None): | ||
return partial(fake_request(*responses, assertions=assertions), "post") | ||
|
||
|
||
def fake_put(*responses): | ||
return partial(fake_request(*responses), "put") | ||
def fake_put(*responses, assertions=None): | ||
return partial(fake_request(*responses, assertions=assertions), "put") | ||
|
||
|
||
def fake_request_with_response(**response_config): | ||
def fake_request_with_response(assertions=None, **response_config): | ||
""" | ||
Creates a request function that returns a response given the response_config. | ||
""" | ||
return fake_request(fake_response(**response_config)) | ||
return fake_request(fake_response(**response_config), assertions=assertions) | ||
|
||
|
||
def fake_request(*responses): | ||
def fake_request(*responses, assertions=None): | ||
""" | ||
Creates a request function that returns the supplied responses, one at a time. | ||
Making a new request after the last response has been returned results in a StopIteration error. | ||
""" | ||
iterator = (response for response in responses) | ||
|
||
def request(method, url, **kwargs): | ||
return next(iterator) | ||
|
||
return request | ||
adapter = FakeAdapter(*responses, assertions=assertions) | ||
session = Session() | ||
session.get_adapter = lambda url: adapter | ||
return session.request |
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