Mock out calls to the python-ubersmith library
Usage
pytest-ubersmith makes it really easy to mock out API calls:
import ubersmith.client
def test_add_client(ubermock):
client_id = 1234
ubermock.client.add = client_id
assert ubersmith.client.add(login='test') == 1234
To have python-ubersmith raise a ResponseError, return an ubermock.ResponseError:
import ubersmith.client
import ubersmith.exceptions
def test_unknown_client(ubermock):
ubermock.client.get = ubermock.ResponseError('Invalid client!', 1)
with pytest.raises(ubersmith.exceptions.ResponseError):
ubersmith.client.get(client_id=1234)
If you need complete control over the response, you can return the whole Ubersmith JSON response:
import pytest
import ubersmith.client
import ubersmith.exceptions
def test_unknown_client_raw(ubermock):
ubermock.client.get.raw_response = {
'status': False,
'data': '',
'error_message': 'Invalid client',
'error_code': 1,
}
with pytest.raises(ubersmith.exceptions.ResponseError):
ubersmith.client.get(client_id=1234)
You can even pass a callable for dynamic responses:
import pytest
import ubersmith.client
import ubersmith.exceptions
def test_dynamic_client(ubermock):
def get_client(method, params, request, context):
# params is a MultiDict
if params['client_id'][0] == '1':
return {'client_id': 1}
else:
raise ubermock.ResponseError('Invalid client!', 1)
ubermock.client.get.response = get_client
assert ubersmith.client.get(client_id=1) == {'client_id': 1}
with pytest.raises(ubersmith.exceptions.ResponseError):
ubersmith.client.get(client_id=2)
Release files for pytest-ubersmith 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest-ubersmith-1.0.1.tar.gz | 4.0 kB | Details |
Release files / pytest-ubersmith-1.0.1.tar.gz
| Download URL | pytest-ubersmith-1.0.1.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ad4e7fbcb84332fda7247debe06477cccd7e8423b8bfff32634e33cc9ba2d215
|
|
BLAKE2b-256 checksum How to use checksums |
bfdd366528f7c2f8555a32b2dcec34084d2d8638a13f197feb49ee9fb9fbd0e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |