Use mocks in your test cases, when you use mocks in tests the
request won't hit the actual server(APIs) for the response, instead it
return some data you specified in fixtures, test case it self...
requests-mock provides an external fixture registered with pytest such that it is usable simply by specifying it as a parameter. The following returns text data.
import pytest
import requests
def test_url(requests_mock):
requests_mock.get('http://test.com', text='data')
assert 'data' == requests.get('http://test.com').text
In the above example you are testing 'http://test.com' and data returned is 'data'.
mock.get(url, ...) // the api you testing
adapter.register_uri('GET', 'mock://test.com', text='Success') // the response you expect
Following is testing a 'GET' request to the url 'mock://test.com/1' and the data returned is {'a': 'b'}.
adapter.register_uri('GET', 'mock://test.com/1', json={'a': 'b'}, status_code=200)
resp = session.get('mock://test.com/1')
resp.json()
{'a': 'b'}
In your case replace the urls, methods and the data match to yours.
Refer: https://requests-mock.readthedocs.io/en/latest/response.html