11import pytest
2- from jsonschema_spec .handlers import default_handlers
32
43from openapi_spec_validator import (
4+ validate_spec , validate_spec_url ,
55 validate_v2_spec , validate_v2_spec_url ,
66 validate_spec_factory , validate_spec_url_factory ,
77 openapi_v2_spec_validator , openapi_v30_spec_validator ,
88 validate_v30_spec_url , validate_v30_spec ,
99)
10+ from openapi_spec_validator .exceptions import ValidatorDetectError
1011from openapi_spec_validator .validation .exceptions import OpenAPIValidationError
1112
1213
13- class TestLocalOpenAPIv20Validator :
14+ class TestValidateSpec :
15+
16+ def test_spec_schema_version_not_detected (self ):
17+ spec = {}
18+
19+ with pytest .raises (ValidatorDetectError ):
20+ validate_spec (spec )
21+
22+
23+ class TestValidateSpecUrl :
24+
25+ def test_spec_schema_version_not_detected (self , factory ):
26+ spec_path = "data/empty.yaml"
27+ spec_url = factory .spec_file_url (spec_path )
28+
29+ with pytest .raises (ValidatorDetectError ):
30+ validate_spec_url (spec_url )
31+
32+
33+ class TestValidatev2Spec :
1434
1535 LOCAL_SOURCE_DIRECTORY = "data/v2.0/"
1636
@@ -25,10 +45,11 @@ def test_valid(self, factory, spec_file):
2545 spec = factory .spec_from_file (spec_path )
2646 spec_url = factory .spec_file_url (spec_path )
2747
48+ validate_spec (spec )
2849 validate_v2_spec (spec )
2950
3051 validate_spec_factory (
31- openapi_v2_spec_validator . validate )(spec , spec_url )
52+ openapi_v2_spec_validator )(spec , spec_url )
3253
3354 @pytest .mark .parametrize ('spec_file' , [
3455 "empty.yaml" ,
@@ -41,7 +62,7 @@ def test_falied(self, factory, spec_file):
4162 validate_v2_spec (spec )
4263
4364
44- class TestLocalOpenAPIv30Validator :
65+ class TestValidatev30Spec :
4566
4667 LOCAL_SOURCE_DIRECTORY = "data/v3.0/"
4768
@@ -56,10 +77,11 @@ def test_valid(self, factory, spec_file):
5677 spec = factory .spec_from_file (spec_path )
5778 spec_url = factory .spec_file_url (spec_path )
5879
80+ validate_spec (spec )
5981 validate_v30_spec (spec )
6082
6183 validate_spec_factory (
62- openapi_v30_spec_validator . validate )(spec , spec_url )
84+ openapi_v30_spec_validator )(spec , spec_url )
6385
6486 @pytest .mark .parametrize ('spec_file' , [
6587 "empty.yaml" ,
@@ -72,7 +94,7 @@ def test_falied(self, factory, spec_file):
7294 validate_v30_spec (spec )
7395
7496
75- class TestRemoteValidateV20 :
97+ class TestValidatev2SpecUrl :
7698
7799 REMOTE_SOURCE_URL = (
78100 "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/"
@@ -92,13 +114,14 @@ def remote_test_suite_file_path(self, test_file):
92114 def test_valid (self , spec_file ):
93115 spec_url = self .remote_test_suite_file_path (spec_file )
94116
117+ validate_spec_url (spec_url )
95118 validate_v2_spec_url (spec_url )
96119
97120 validate_spec_url_factory (
98- openapi_v2_spec_validator . validate , default_handlers )(spec_url )
121+ openapi_v2_spec_validator )(spec_url )
99122
100123
101- class TestRemoteValidateV30 :
124+ class TestValidatev30SpecUrl :
102125
103126 REMOTE_SOURCE_URL = (
104127 "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/"
@@ -118,7 +141,8 @@ def remote_test_suite_file_path(self, test_file):
118141 def test_valid (self , spec_file ):
119142 spec_url = self .remote_test_suite_file_path (spec_file )
120143
144+ validate_spec_url (spec_url )
121145 validate_v30_spec_url (spec_url )
122146
123147 validate_spec_url_factory (
124- openapi_v30_spec_validator . validate , default_handlers )(spec_url )
148+ openapi_v30_spec_validator )(spec_url )
0 commit comments