jj mocks validator for openapi specs
Project description
Usage
- Decorate your mocked function with
@validate_spec()
, providing a link to a YAML or JSON OpenAPI spec.
import jj
from jj.mock import mocked
from jj_spec_validator import validate_spec
@validate_spec(spec_link="http://example.com/api/users/spec.yml")
async def your_mocked_function():
matcher = jj.match("GET", "/users")
response = jj.Response(status=200, json=[])
mock = await mocked(matcher, response)
-
is_strict
key allows choosing between strict and non-strict comparison. Non-strict comparison allows you to mock only some fields from the spec.False
(= non-strict) by default. -
Use the
prefix
key to specify a prefix that should be removed from the paths in the mock function before matching them against the OpenAPI spec.
from jj_spec_validator import validate_spec
@validate_spec(spec_link="http://example.com/api/users/spec.yml", prefix='/__mocked_api__') # Goes to validate `/users` instead of `/__mocked_api__/users`
async def your_mocked_function():
matcher = jj.match("GET", "/__mocked_api__/users")
...
-
is_raise_error
key allows raising an error when a mismatch occurs.False
by default. -
force_strict
key allows enforcing strict validation against the downloaded spec. This is useful when the spec is occasionally have all dicts relaxed.False
by default.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file jj_spec_validator-0.1.13.tar.gz
.
File metadata
- Download URL: jj_spec_validator-0.1.13.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddcedc6594c97f8aa30939863aa61b7468d35a54987e7a6c8e33014fe195d938 |
|
MD5 | e52d837c35f409ded83ec21d356fdce2 |
|
BLAKE2b-256 | e164e2e1095c64c0522551e4706df0f08e1b2925936cba334506341ffc0ad74b |
File details
Details for the file jj_spec_validator-0.1.13-py3-none-any.whl
.
File metadata
- Download URL: jj_spec_validator-0.1.13-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db990b41d8894e60286ac6ac99738febaa635b9156088d95d8a6150acb59d6a1 |
|
MD5 | 4fb4ea7d5a834fff0c7149900c0c9f5b |
|
BLAKE2b-256 | fe24eb0a38722b078571eba1d0030d482499350ccf7246619a8b0525b176fd9b |