Skip to content

Conversation

LordAro
Copy link
Member

@LordAro LordAro commented Sep 30, 2016

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.

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.
@coveralls
Copy link

coveralls commented Sep 30, 2016

Coverage Status

Coverage remained the same at 69.459% when pulling 8cfb028 on LordAro:fix-imgur-test into 2fb243e on HackSoc:master.

@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:
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member

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):
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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.

@alanbriolat alanbriolat merged commit a12925a into HackSoc:master Oct 30, 2016
@LordAro LordAro deleted the fix-imgur-test branch November 1, 2016 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants