import pytest import schemathesis @pytest.fixture(scope="session") def schema_app(app): from example_app.openapi import OAS_PATH return schemathesis.from_path(OAS_PATH, app=app) schema = schemathesis.from_pytest_fixture("schema_app") @schema.parametrize(method="GET") def test_get(case): response = case.call_wsgi(headers=[]) case.validate_response(response)
from ert_shared.storage import ERT_STORAGE from ert_shared.storage.http_server import FlaskWrapper from tests.storage import db_api, populated_database, initialize_databases @pytest.fixture def test_schema(db_api): # Flask provides a way to test your application by exposing the Werkzeug test Client # and handling the context locals for you. flWrapper = FlaskWrapper(secure=False, url=ERT_STORAGE.SQLALCHEMY_URL) # Establish an application context before running the tests. with flWrapper.app.app_context(): yield schemathesis.from_wsgi("/schema.json", flWrapper.app) schema = schemathesis.from_pytest_fixture("test_schema") @schema.parametrize() @hypothesis.settings( deadline=timedelta(milliseconds=1500), derandomize=True, suppress_health_check=[ hypothesis.HealthCheck.filter_too_much, hypothesis.HealthCheck.too_slow, ], ) def test_no_server_errors(case): response = case.call_wsgi() case.validate_response(response)
"""This file tests that the schema of the API is valid. The schemas are defined in the YAML files, and they in turn define how the API is supposed to work. """ import pytest import schemathesis @pytest.fixture def schema_fixture(app): schema = schemathesis.from_wsgi('/api/flagging_api.json', app) # Skip the model input data endpoint for test purposes. # We do not plan on maintaining this schema. # The following line removes the model_input_data from the schema: schema.raw_schema['paths'].pop('/api/v1/model_input_data', None) return schema schema = schemathesis.from_pytest_fixture('schema_fixture') @schema.parametrize() def test_api(case): """Test the API against the OpenAPI specification.""" response = case.call_wsgi() case.validate_response(response)