I have some code that I would like to test, it is a fairly vanilla GET request wrapper, but the implementation of it requests data from the API multiple times with different IDs.
Adding mock JSON responses for the tests is problematic as there are hundreds of calls with these IDs and we want to test against one fixed response.
The target URI looks like https://someurl.com/api/v1/id/1234/data?params
The issue we are having is not wanting to add a line of code for every mock endpoint.
Eg. rather than have
mocker.get('https://someurl.com/api/v1/id/1234/data?params',
json={},
status_code=200)
mocker.get('https://someurl.com/api/v1/id/5678/data?params',
json={},
status_code=200)
I would like to implement some sort of wildcard matching, like this:
mocker.get(re.compile('https://someurl.com/api/v1/id/*/data?params'),
json={},
status_code=200)
This should be possible if I understand the docs correctly but this returns an error:
Failed: [undefined]requests_mock.exceptions.NoMockAddress: No mock address: GET https://someurl.com/api/v1/id/1234/data?params