Skip to content
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

Dependency Injection for http_client #32

Closed
wants to merge 2 commits into from

Conversation

psilva261
Copy link

Hey, as proposed in the discussion, dependency injection for http_client. So one can easily write unit tests for the image fetcher. Let me know if it's fine or if you want changes.

Cheers, Philip

@dzen
Copy link

dzen commented Aug 8, 2013

IMHO, you're modifying too deeply the Apis.
Dependency injection is great, but here, you're passing a instnce from class to class. I doubt it's powerful.

If it's for tests purposes, mock is the module to use

@grangier
Copy link
Owner

grangier commented Aug 8, 2013

I do agree with @dzen .Mocking the urllib2 would be the perfect solution for Image module unit tests. The extractor module does't use Mock at all, it kind of fake it. Id' rather write some unittest first for the existing image module and the go ahead with the download less solution proposed on #31 . I'll have some time next week to improve this.

@psilva261
Copy link
Author

@dzen

Yeah in fact I also dislike changing APIs too much. Although I think existing application code shouldn't be affected. I was wondering whether it would make sense to put such stuff directly into the config...

@grangier

Hmm ok... The thing is this: I would like to improve the image extractor. I see that sometimes it fetches the wrong image. (E.g. here http://www.timeforkids.com/news/gaga-goo-goo-clusters/54591 it fetches the author's picture instead of the Article's main image) To implement this, some unit testing is needed in order to prevent destroying cases that work fine today. I.e. specifying HTML as usual and additionally sizes of all referenced images.

@grangier
Copy link
Owner

grangier commented Aug 8, 2013

I've pushed a work in progress branch. Basic idea here is to Mock urllib2 for testing https://github.com/grangier/python-goose/compare/mocked

I'll like to update tests based on this classes before going forward on changing the existing code

@grangier
Copy link
Owner

grangier commented Aug 8, 2013

@psilva261 I know sometime the image extractor picks up the wrong image. It needs improvement

@psilva261
Copy link
Author

@grangier Thanks for the preview. Looking forward to work with that

@psilva261 psilva261 closed this Aug 9, 2013
@grangier
Copy link
Owner

grangier commented Aug 9, 2013

@psilva261 I really advice to wait before hacking the mocked branch. It's not working as expected right now

@psilva261
Copy link
Author

@grangier Ok ok

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