def test_app(): client = TestClient(app) spec = openapi.load_specification(app) validate_v2_spec(spec) assert client.get(openapi.config["specification_url"]).json() == spec assert client.get(openapi.config["swagger_url"]).status_code == 200 assert client.get(openapi.config["redoc_url"]).status_code == 200 # -- with pytest.raises(Exception): client.get("/cat/1/") with pytest.raises(Exception): client.get("/cat/1/?test_param2=test") assert ( client.get( "/cat/1/?test_param2=test", headers={"test_param1": "test"} ).status_code == 200 ) # -- with pytest.raises(Exception): client.post("/cats/", json={"name": "test", "id": 3}) assert ( client.post("/cats/", json={"name": "test", "id": 3, "age": 4}).status_code == 200 )
def _validate_openapi_spec_validator(self, spec_version): # pragma: nocover from openapi_spec_validator import validate_v2_spec, validate_v3_spec from jsonschema.exceptions import ValidationError as JSEValidationError from jsonschema.exceptions import RefResolutionError # Validate according to detected version. Unsupported versions are # already caught outside of this function. from .util.exceptions import raise_from if spec_version[0] == 3: # Set the version independently of whether validation succeeds self.__set_version(BaseParser.SPEC_VERSION_3_PREFIX, spec_version) try: validate_v3_spec(self.specification) except TypeError as type_ex: # pragma: nocover raise_from(ValidationError, type_ex) except JSEValidationError as v3_ex: raise_from(ValidationError, v3_ex) except RefResolutionError as ref_ex: raise_from(ValidationError, ref_ex) elif spec_version[0] == 2: # Set the version independently of whether validation succeeds self.__set_version(BaseParser.SPEC_VERSION_2_PREFIX, spec_version) try: validate_v2_spec(self.specification) except TypeError as type_ex: # pragma: nocover raise_from(ValidationError, type_ex) except JSEValidationError as v2_ex: raise_from(ValidationError, v2_ex) except RefResolutionError as ref_ex: raise_from(ValidationError, ref_ex)
def _validate_openapi_spec_validator(self, spec_version): # pragma: nocover from openapi_spec_validator import validate_v2_spec, validate_v3_spec from jsonschema.exceptions import ValidationError as JSEValidationError from jsonschema.exceptions import RefResolutionError # Try v3 first, then fall back to v2 from .util.exceptions import raise_from try: try: validate_v3_spec(self.specification) self.__set_version(BaseParser.SPEC_VERSION_3_PREFIX, spec_version) except TypeError as type_ex: # pragma: nocover raise_from(ValidationError, type_ex) except JSEValidationError as v3_ex: try: validate_v2_spec(self.specification) self.__set_version(BaseParser.SPEC_VERSION_2_PREFIX, spec_version) except TypeError as type_ex: # pragma: nocover raise_from(ValidationError, type_ex) except RefResolutionError as ref_ex: raise_from(ValidationError, ref_ex)
def test_documentation_errors(self): port = self.service_port(9500, 'calld') api_url = 'https://localhost:{port}/1.0/api/api.yml'.format(port=port) api = requests.get(api_url, verify=False) validate_v2_spec(yaml.safe_load(api.text))
def test_documentation_errors(self): port = APIAssetLaunchingTestCase.service_port(9304, 'chatd') api_url = f'http://127.0.0.1:{port}/1.0/api/api.yml' api = requests.get(api_url) validate_v2_spec(yaml.safe_load(api.text))
def test_documentation_errors(self): port = self.service_port(9500, 'calld') api_url = 'http://127.0.0.1:{port}/1.0/api/api.yml'.format(port=port) api = requests.get(api_url) validate_v2_spec(yaml.safe_load(api.text))
def test_failed(self, spec): with pytest.raises(ValidationError): validate_v2_spec(spec)
def test_valid(self, spec): validate_v2_spec(spec)
def test_documentation_errors(self): confd_port = BaseIntegrationTest.service_port(9486, 'confd') api_url = 'https://localhost:{port}/1.1/api/api.yml'.format( port=confd_port) api = requests.get(api_url, verify=False) validate_v2_spec(yaml.safe_load(api.text))
def test_documentation_errors(self): api_url = f'http://{self.auth_host}:{self.auth_port}/0.1/api/api.yml' api = requests.get(api_url) validate_v2_spec(yaml.safe_load(api.text))
def test_documentation_errors(self): port = self.service_port(9497, 'auth') api_url = 'http://localhost:{port}/0.1/api/api.yml'.format(port=port) api = requests.get(api_url) validate_v2_spec(yaml.safe_load(api.text))
def test_documentation_errors(self): port = self.service_port(9499, 'phoned') api_url = 'https://127.0.0.1:{port}/{version}/api/api.yml'.format( port=port, version=VERSION) api = requests.get(api_url, verify=False) validate_v2_spec(yaml.safe_load(api.text))
def test_documentation_errors(self): port = self.service_port(9489, 'dird') api_url = 'http://127.0.0.1:{port}/0.1/api/api.yml'.format(port=port) api = requests.get(api_url) api.raise_for_status() validate_v2_spec(yaml.safe_load(api.text))