-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dmitry Dygalo <dmitry@dygalo.dev>
- Loading branch information
1 parent
1161847
commit 11633f1
Showing
6 changed files
with
128 additions
and
35 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,49 @@ | ||
import pytest | ||
|
||
import schemathesis | ||
from schemathesis.specs.openapi.references import resolve_pointer | ||
|
||
|
||
@pytest.mark.benchmark | ||
def test_schema_resolution(): | ||
raw_schema = { | ||
"openapi": "3.0.0", | ||
"info": {"title": "Example API", "description": "An API to test Schemathesis", "version": "1.0.0"}, | ||
"components": { | ||
"schemas": { | ||
"Node": { | ||
"type": "object", | ||
"required": ["child"], | ||
"properties": {"child": {"$ref": "#/components/schemas/Node"}}, | ||
} | ||
RECURSIVE_SCHEMA = { | ||
"openapi": "3.0.0", | ||
"info": {"title": "Example API", "description": "An API to test Schemathesis", "version": "1.0.0"}, | ||
"components": { | ||
"schemas": { | ||
"Node": { | ||
"type": "object", | ||
"required": ["child"], | ||
"properties": {"child": {"$ref": "#/components/schemas/Node"}}, | ||
} | ||
}, | ||
"paths": { | ||
"/foo": { | ||
"post": { | ||
"summary": "Test", | ||
"description": "", | ||
"requestBody": { | ||
"required": True, | ||
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Node"}}}, | ||
}, | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"content": {}, | ||
} | ||
}, | ||
} | ||
} | ||
}, | ||
"paths": { | ||
"/foo": { | ||
"post": { | ||
"summary": "Test", | ||
"description": "", | ||
"requestBody": { | ||
"required": True, | ||
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Node"}}}, | ||
}, | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"content": {}, | ||
} | ||
}, | ||
} | ||
}, | ||
} | ||
} | ||
}, | ||
} | ||
|
||
schema = schemathesis.from_dict(raw_schema) | ||
|
||
@pytest.mark.benchmark | ||
def test_inlining_during_resolution(): | ||
schema = schemathesis.from_dict(RECURSIVE_SCHEMA) | ||
schema.resolver.resolve_all( | ||
raw_schema["paths"]["/foo"]["post"]["requestBody"]["content"]["application/json"]["schema"] | ||
RECURSIVE_SCHEMA["paths"]["/foo"]["post"]["requestBody"]["content"]["application/json"]["schema"] | ||
) | ||
|
||
|
||
@pytest.mark.benchmark | ||
def test_resolve_pointer(): | ||
resolve_pointer(RECURSIVE_SCHEMA, "/paths/~1foo/post/requestBody/content/application~1json/schema") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import json | ||
import pathlib | ||
|
||
import pytest | ||
|
||
import schemathesis | ||
import hypothesis | ||
from hypothesis import HealthCheck, Phase, Verbosity | ||
from schemathesis.runner import from_schema | ||
|
||
CURRENT_DIR = pathlib.Path(__file__).parent.absolute() | ||
CATALOG_DIR = CURRENT_DIR / "data" | ||
|
||
|
||
def read_from_catalog(path: str): | ||
with (CATALOG_DIR / path).open() as fd: | ||
return json.load(fd) | ||
|
||
|
||
# Small size (~2k lines in YAML) | ||
BBCI = read_from_catalog("bbci.json") | ||
BBCI_SCHEMA = schemathesis.from_dict(BBCI) | ||
BBCI_OPERATIONS = list(BBCI_SCHEMA.get_all_operations()) | ||
# Medium size (~8k lines in YAML) | ||
VMWARE = read_from_catalog("vmware.json") | ||
VMWARE_SCHEMA = schemathesis.from_dict(VMWARE) | ||
VMWARE_OPERATIONS = list(VMWARE_SCHEMA.get_all_operations()) | ||
# Large size (~92k lines in YAML) | ||
STRIPE = read_from_catalog("stripe.json") | ||
STRIPE_SCHEMA = schemathesis.from_dict(STRIPE) | ||
|
||
|
||
@pytest.mark.benchmark | ||
@pytest.mark.parametrize("raw_schema", [BBCI, VMWARE], ids=("bbci", "vmware")) | ||
def test_get_all_operations(raw_schema): | ||
schema = schemathesis.from_dict(raw_schema) | ||
|
||
for _ in schema.get_all_operations(): | ||
pass | ||
|
||
|
||
@pytest.mark.benchmark | ||
@pytest.mark.parametrize("operations", [BBCI_OPERATIONS, VMWARE_OPERATIONS], ids=("bbci", "vmware")) | ||
def test_as_json_schema(operations): | ||
for operation in operations: | ||
for parameter in operation.ok().iter_parameters(): | ||
_ = parameter.as_json_schema(operation) | ||
|
||
|
||
@pytest.mark.benchmark | ||
def test_events(): | ||
runner = from_schema( | ||
BBCI_SCHEMA, | ||
checks=(), | ||
count_operations=False, | ||
count_links=False, | ||
hypothesis_settings=hypothesis.settings( | ||
deadline=None, | ||
database=None, | ||
max_examples=1, | ||
derandomize=True, | ||
suppress_health_check=list(HealthCheck), | ||
phases=[Phase.explicit, Phase.generate], | ||
verbosity=Verbosity.quiet, | ||
), | ||
) | ||
for _ in runner.execute(): | ||
pass | ||
|
||
|
||
@pytest.mark.benchmark | ||
@pytest.mark.parametrize("raw_schema", [BBCI, VMWARE, STRIPE], ids=("bbci", "vmware", "stripe")) | ||
def test_rewritten_components(raw_schema): | ||
schema = schemathesis.from_dict(raw_schema) | ||
|
||
_ = schema.rewritten_components | ||
|
||
|
||
@pytest.mark.benchmark | ||
@pytest.mark.parametrize("raw_schema", [BBCI, VMWARE, STRIPE], ids=("bbci", "vmware", "stripe")) | ||
def test_links_count(raw_schema): | ||
schema = schemathesis.from_dict(raw_schema) | ||
|
||
_ = schema.links_count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters