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

Mock external resources during testing. #931

Open
Sumukh opened this Issue Oct 21, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@Sumukh
Member

Sumukh commented Oct 21, 2016

Good testing practice would have us mock external responses.

For example - in many places we hit the autograder.

Here's a way that should be easy enough to mock the autograder http://stackoverflow.com/a/32140760

Key content:

import mock 
...
   def my_test(self):
        with mock.patch.object(requests, 'get') as get_mock:
            get_mock.return_value = mock_response = mock.Mock()
            mock_response.status_code = 200
            mock_response.content = {'twitter_handle': '@twitter'}
            assert requests.get('http://fakeeeee.com').status_code == 200

We would mock requests.post to return a 200 (or maybe if the point is not to test the autograder, then we could just mock the send_to_ag function)

@Sumukh

This comment has been minimized.

Show comment
Hide comment
@Sumukh

Sumukh Oct 21, 2016

Member

This was surprisingly hard to make work in all cases. Maybe the best approach is to use a library that specializes in mocking requests from requests.

https://github.com/getsentry/responses looks interesting.

Member

Sumukh commented Oct 21, 2016

This was surprisingly hard to make work in all cases. Maybe the best approach is to use a library that specializes in mocking requests from requests.

https://github.com/getsentry/responses looks interesting.

@jezeniel

This comment has been minimized.

Show comment
Hide comment
@jezeniel

jezeniel Oct 17, 2017

Contributor

@Sumukh i could do this one, but it will take time, i'll read the source first.

Contributor

jezeniel commented Oct 17, 2017

@Sumukh i could do this one, but it will take time, i'll read the source first.

@Sumukh

This comment has been minimized.

Show comment
Hide comment
@Sumukh

Sumukh Oct 17, 2017

Member

Cool. Not super mandatory - but good to have so our tests don't hit the production autograder :)

Member

Sumukh commented Oct 17, 2017

Cool. Not super mandatory - but good to have so our tests don't hit the production autograder :)

@jezeniel

This comment has been minimized.

Show comment
Hide comment
@jezeniel

jezeniel Oct 17, 2017

Contributor

You can assign this to me, i'll try to up my local server. This is the updated docs for autograder right? https://okpy.github.io/documentation/autograder.html

Contributor

jezeniel commented Oct 17, 2017

You can assign this to me, i'll try to up my local server. This is the updated docs for autograder right? https://okpy.github.io/documentation/autograder.html

@Sumukh

This comment has been minimized.

Show comment
Hide comment
@Sumukh

Sumukh Oct 17, 2017

Member

@jezeniel Unfortunately I never got around to documenting the OK integration. Autograder.py in this repo should help though.

Member

Sumukh commented Oct 17, 2017

@jezeniel Unfortunately I never got around to documenting the OK integration. Autograder.py in this repo should help though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment