Testing utilities
This library comes with some tools that ease testing in downstream projects.
- class vng_api_common.tests.JWTAuthMixin
Configure the local auth cache.
Creates the local auth objects for permission checks, as if you’re talking to a real AC behind the scenes.
- vng_api_common.tests.generate_jwt_auth(client_id, secret, user_id='test_user_id', user_representation='Test User')
Generate a JWT suitable for the second version of the AC-based auth.
- vng_api_common.tests.get_operation_url(operation: str, spec_path: str = '/home/docs/checkouts/readthedocs.org/user_builds/vng-api-common/checkouts/latest/src/openapi.yaml', **kwargs)
Look up the url of an operation from the API spec.
- vng_api_common.tests.get_validation_errors(response, field, index=0)
Extra the validation error for
field
from the response.Assumes there’s only one validation error for the field.
- vng_api_common.tests.reverse(*args, **kwargs)
Determine the path for a named URL, instance or model.
There’s some ‘magic’ behaviour depending on the first arg provided:
if a model instance is provided, a detail URL is reversed
if a model class is provided, a list URL is reversed
It is assumed that objects have a
uuid
field and the url kwarg is nameduuid
. For nested routes, you need to provide the remaining parameters as kwargs. Other Djangoreverse
params are passed down.
- vng_api_common.tests.reverse_lazy(*args, **kwargs)
Determine the path for a named URL, instance or model, lazily.
There’s some ‘magic’ behaviour depending on the first arg provided:
if a model instance is provided, a detail URL is reversed
if a model class is provided, a list URL is reversed
It is assumed that objects have a
uuid
field and the url kwarg is nameduuid
. For nested routes, you need to provide the remaining parameters as kwargs. Other Djangoreverse_lazy
params are passed down.