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)
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
def test_schema(db_info): populated_db, _ = db_info # Flask provides a way to test your application by exposing the Werkzeug test Client # and handling the context locals for you. flWrapper = FlaskWrapper(rdb_url=populated_db, blob_url=populated_db) # Establish an application context before running the tests. ctx = flWrapper.app.app_context() ctx.push() yield schemathesis.from_wsgi("/schema.json", flWrapper.app) ctx.pop()
def test_hidden_failure_app(request, factory_name, open_api_3): factory = request.getfixturevalue(factory_name) app = factory(operations=("create_user", "get_user", "update_user"), version=open_api_3) if factory_name == "asgi_app_factory": schema = schemathesis.from_asgi("/openapi.json", app=app) schema.add_link( source=schema["/users/"]["POST"], target=schema["/users/{user_id}"]["GET"], status_code="201", parameters={ "path.user_id": "$response.body#/id", "query.uid": "$response.body#/id", }, ) schema.add_link( source=schema["/users/"]["POST"], target=schema["/users/{user_id}"]["PATCH"], status_code="201", parameters={"user_id": "$response.body#/id"}, ) schema.add_link( source=schema["/users/{user_id}"]["GET"], target="#/paths/~1users~1{user_id}/patch", status_code="200", parameters={"user_id": "$response.body#/id"}, request_body={ "first_name": "foo", "last_name": "bar" }, ) else: schema = schemathesis.from_wsgi("/schema.yaml", app=app) state_machine = schema.as_state_machine() with pytest.raises(CheckFailed, match="Received a response with 5xx status code: 500"): run_state_machine_as_test( state_machine, settings=settings( max_examples=1000, deadline=None, suppress_health_check=HealthCheck.all(), stateful_step_count=3, ), )
def schema(flask_app): return schemathesis.from_wsgi("/swagger.yaml", flask_app)
def api_schema(request, openapi_version): if request.param == "aiohttp": schema_url = request.getfixturevalue("schema_url") return schemathesis.from_uri(schema_url) app = request.getfixturevalue("flask_app") return schemathesis.from_wsgi("/schema.yaml", app=app)
import schemathesis from hypothesis import settings from test_server import test_server schema = schemathesis.from_wsgi("/static/schema.json", test_server) @schema.parametrize() # @settings(max_examples=5) def test_no_server_errors(case): response = case.call_wsgi() print(f"case.body: {case.body}") print(f"response.status_code: {response.status_code}") print(f"response: {response}") if response.status_code == 400: pass # assert response.text == "blah" else: assert response.status_code in [200, 201]
import schemathesis from tests import BaseTestCase app = BaseTestCase().create_app() schema = schemathesis.from_wsgi("/store/v1/openapi.yaml", app) schemathesis_config = dict(endpoint="/store/v1/items", method="POST") @schema.parametrize(**schemathesis_config) def test_no_server_errors(case): response = case.call_wsgi() assert response.status_code < 500
def schema_fixture(self, app): _schema = schemathesis.from_wsgi('/click_restful.json', app) return _schema
def schema_fixture(app): schema = schemathesis.from_wsgi('/api/flagging_api.json', app) return schema