def test_proxy_schema(app_dev): view = "api.schema_proxy" testapp = app_dev.test_client() bypass = { app_dev.config.LIMITER.BYPASS_KEY: app_dev.config.LIMITER.BYPASS_VALUE } _ = h.api_tester( testapp, h.url_for(view, filepath="pippo"), status=h.httpcode.NOT_FOUND, headers=bypass, ) res = h.api_tester(testapp, h.url_for(view, filepath="jsonrpc/request.json")) h.Asserter.assert_equals(res.json, app_dev.config.SCHEMAS.JSONRPC.REQUEST) res = h.api_tester(testapp, h.url_for(view, filepath="api_problem")) h.Asserter.assert_equals(res.json, app_dev.config.SCHEMAS.API_PROBLEM)
def test_healthcheck(testapp): res = h.api_tester( testapp, url=testapp.application.config.HEALTHCHECK_PATH, status=h.httpcode.SERVICE_UNAVAILABLE, schema=schemas.SCHEMAS.HEALTHCHECK, ) h.Asserter.assert_content_type(res, h.CTS.json_health) h.Asserter.assert_allin( res.json.checks.keys(), ("mongo", "redis", "sqlalchemy", "system", "services"))
def test_api_cors(testapp): client = TestHttpApi(testapp) client.perform( request={"url": h.url_for("api.resource_api")}, response={ "status": { "code": h.httpcode.TOO_MANY_REQUESTS }, "headers": { "Access-Control-Allow-Origin": { "value": "*" }, "Content-Type": { "value": h.CTS.json_problem }, }, }, ) headers = testapp.application.config.CORS_EXPOSE_HEADERS res = h.api_tester(testapp, url="/") h.Asserter.assert_header(res, "Access-Control-Allow-Origin", "*") h.Asserter.assert_allin( res.headers["Access-Control-Expose-Headers"].split(", "), headers)
def test_cors_headers(test_client): headers = test_client.application.config.CORS_EXPOSE_HEADERS res = h.api_tester(test_client, url="/", status=h.httpcode.NOT_FOUND) h.Asserter.assert_header(res, "Access-Control-Allow-Origin", "*") h.Asserter.assert_allin( res.headers["Access-Control-Expose-Headers"].split(", "), headers)
def test_app_runs(test_client): h.api_tester(test_client, "/", status=h.httpcode.NOT_FOUND)