-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
switched direct requests call to use of session instance #3
switched direct requests call to use of session instance #3
Conversation
This patch is necessary for unit tests of guyzmo/git-repo, as the betamax library hijacks a requests session to record and replay HTTP calls. Basically, what is needed is to be able to use and extract:
A cleaner approach (to avoid exposing private API), would be to change the entry point object:
but first way (which I currently implemented so it's frictionless) is good enough. |
@@ -11,8 +11,9 @@ class RelativeHttpRequestor(object): | |||
A thin wrapper around the requests module that allows for endpoint paths | |||
to be given relative to a fixed base URL | |||
""" | |||
def __init__(self, base_url): | |||
def __init__(self, base_url, session=requests.Session()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be safer to have session=None
, and then check if session is None
inside the constructor. If for some reason I created two GogsApi
obects (each using the default session), they would be sharing the same request.Session()
object.
In general, having mutable default arguments is risky business in Python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually that's on purpose, because it's more likely you'd want to keep the same shared session object even between instances. And BTW, it's matching the original behaviour where you were using the global requests
context 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyway, fixed it to your liking 👌
@guyzmo I like the suggestion; I'm a big fan of injection! However, in order to expose the |
9a8f012
to
7a6378d
Compare
Signed-off-by: Guyzmo <guyzmo+github@m0g.net>
7a6378d
to
c88f317
Compare
LGTM. Thanks for the contribution! |
No description provided.