-
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.
- Loading branch information
Showing
10 changed files
with
113 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,7 @@ class PookNoMatches(Exception): | |
|
||
class PookExpiredMock(Exception): | ||
pass | ||
|
||
|
||
class PookInvalidArgument(Exception): | ||
pass |
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,22 @@ | ||
class BaseInterceptor(object): | ||
""" | ||
BaseInterceptor provides a base class for HTTP traffic | ||
interceptors implementations. | ||
""" | ||
def __init__(self, engine): | ||
self.patchers = [] | ||
self.engine = engine | ||
|
||
def activate(self): | ||
""" | ||
Activates the traffic interceptor. | ||
This method must be implemented by any interceptor. | ||
""" | ||
raise NotImplemented('not implemented yet') | ||
|
||
def disable(self): | ||
""" | ||
Disables the traffic interceptor. | ||
This method must be implemented by any interceptor. | ||
""" | ||
raise NotImplemented('not implemented yet') |
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,13 +1,16 @@ | ||
from .headers import HTTPHeaderDict | ||
from .utils import trigger_methods | ||
|
||
|
||
class Request(object): | ||
""" | ||
Request object represents. | ||
Request object representing the mock request expectation. | ||
""" | ||
def __init__(self, method='GET'): | ||
def __init__(self, method='GET', **args): | ||
self.method = method | ||
self.headers = HTTPHeaderDict() | ||
self.url = '' | ||
self.params = '' | ||
self.body = None | ||
# Call methods | ||
trigger_methods(self, args) |
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,13 @@ | ||
from inspect import isfunction | ||
from .exceptions import PookInvalidArgument | ||
|
||
def trigger_methods(instance, args): | ||
"""" | ||
Triggers the required class methods using simple reflection | ||
based on the given arguments dictionary. | ||
""" | ||
for key, arg in args.items(): | ||
method = getattr(instance, key, None) | ||
if isfunction(method): | ||
raise PookInvalidArgument('Unsupported argument: {}'.format(key)) | ||
method(arg) |