-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add monkey patching for botocore.httpsession (#321)
* Add monkey patching for botocore.httpsession Closes #319 * Rmove AWSResponse, don't need it * Add monkey patching test * Add mock filter to test * Make monkey patching python2.7 compatible
- Loading branch information
Showing
3 changed files
with
107 additions
and
21 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from botocore.httpsession import URLLib3Session as BotocoreSession | ||
from botocore.vendored.requests.sessions import Session as BotocoreVendoredSession | ||
from requests.sessions import Session as RequestsSession | ||
|
||
from iopipe.contrib.trace.auto_http import patch_requests, restore_requests | ||
|
||
|
||
def test_monkey_patching(mock_context): | ||
assert not hasattr(RequestsSession, "__monkey_patched") | ||
assert not hasattr(BotocoreSession, "__monkey_patched") | ||
assert not hasattr(BotocoreVendoredSession, "__monkey_patched") | ||
|
||
def mock_filter(http_response): | ||
return http_response | ||
|
||
patch_requests(mock_context, mock_filter) | ||
|
||
assert hasattr(RequestsSession, "__monkey_patched") | ||
assert hasattr(BotocoreSession, "__monkey_patched") | ||
assert hasattr(BotocoreVendoredSession, "__monkey_patched") | ||
|
||
restore_requests() | ||
|
||
assert not hasattr(RequestsSession, "__monkey_patched") | ||
assert not hasattr(BotocoreSession, "__monkey_patched") | ||
assert not hasattr(BotocoreVendoredSession, "__monkey_patched") |