-
Notifications
You must be signed in to change notification settings - Fork 16
Fix imgur tests by adding extra responses call #114
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
Conversation
imgurpython 1.1.3+ calls out to https://api.imgur.com/3/credits to get its initial ratelimit settings. Therefore when the test object was initialised (calling imgurpython __init__), things broke. Mocking that call fixes the issue, and I've also modified the tests a bit to use @responses.activate decorator (like the xkcd plugin) rather than creating a new responses object for each function.
@responses.activate | ||
def test_integration(self): | ||
for url, api_url, status, content_type, fixture, title in test_cases: | ||
with self.subTest(url=url), responses.RequestsMock() as rsps: |
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 I preferred the isolation of the explicit RequestsMock
object, instead of adding all URLs to the global default mock, but since everything else is just using @requests.activate
, I guess this can too. It definitely makes life easier when we have setup to do.
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 switched it out because I thought the same "global" object was needed via setUp[Class]
, but as you say, it's not strictly necessary for testing anyway, and it does reduce the indent :)
|
||
PLUGINS = ['linkinfo', 'imgur'] | ||
|
||
@responses.activate |
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.
No need to @responses.activate
here, since that just enables the patching of requests
, and we're not making any requests.
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.
Yup, I misunderstood here, the request is being made during test bot setup. 👍
PLUGINS = ['linkinfo', 'imgur'] | ||
|
||
@responses.activate | ||
def setUp(self): |
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.
This should be setUpClass
, otherwise the mock ends up with as many copies of the fixture as there are tests to run; setUp
and tearDown
bracket each test method, setUpClass
and tearDownClass
bracket the entire TestCase
.
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.
This doesn't appear to work, for some reason. setUpClass is getting called, but then all of the test methods fail with the same get_client error that I'm trying to solve
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.
My misunderstanding here. The way you have it set up only applies the mock during test bot setup, which is when the plugin makes that request. Had to read a bit of the responses source code to understand how @responses.activate
works.
imgurpython 1.1.3+ (commit) calls out to https://api.imgur.com/3/credits to get
its initial ratelimit settings. Therefore when the test object was
initialised (calling imgurpython init), things broke.
Mocking that call fixes the issue, and I've also modified the tests a
bit to use @responses.activate decorator (like the xkcd plugin) rather
than creating a new responses object for each function.