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

assert_json_requests_mock() helper #159

Open
jedie opened this issue Feb 12, 2021 · 0 comments
Open

assert_json_requests_mock() helper #159

jedie opened this issue Feb 12, 2021 · 0 comments

Comments

@jedie
Copy link

jedie commented Feb 12, 2021

I need a way to check JSON data in requests made in views. I didn't find something in requests-mock. So i implement a simple function to check the mock.request_history

Usage looks like this:

with requests_mock.mock() as m:
    m.post('http://test.tld', text='resp')
    requests.post('http://test.tld', json={'foo': 'bar'}) # maybe this is made deeper e.g.: in a view

assert_json_requests_mock(mock=m, data=[{
    'request': 'POST http://test.tld/',
    'json': {'foo': 'bar'},
}])

The code is here: https://github.com/boxine/bx_py_utils/blob/master/bx_py_utils/test_utils/requests_mock_assertion.py

More examples are here: https://github.com/boxine/bx_py_utils/blob/master/bx_py_utils_tests/tests/test_requests_mock_assertion.py

Maybe this is useful for other users? Any interests to include this into requests-mock? Then i can try to create a pull request.

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

No branches or pull requests

1 participant