Skip to main content

pytest-ubersmith

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)

Metadata

Release files for pytest-ubersmith 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-ubersmith 1.0.2
File Size Uploaded Provenance Actions
pytest-ubersmith-1.0.2.tar.gz 4.0 kB Without provenance Details for pytest-ubersmith-1.0.2.tar.gz

Release files / pytest-ubersmith-1.0.2.tar.gz

Download URL pytest-ubersmith-1.0.2.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f7c5080f54df6c987d117d0ce0bed801fe0342c05e90573bd83e55457815c14d
BLAKE2b-256 checksum
How to use checksums
b215094617fd5233be23366f8b6e6caea9f948a3c2b2efc0d4ad59f89793b54d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pytest-ubersmith 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.2 This release

1 release file No provenance

1.0.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page