Skip to content

Commit f1267ac

Browse files
committed
urllib handler tests
1 parent 0499fd7 commit f1267ac

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

tests/integration/test_shortcuts.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import pytest
22

3-
from openapi_spec_validator import validate_spec, validate_spec_url
4-
from openapi_spec_validator import validate_v2_spec, validate_v2_spec_url
3+
from openapi_spec_validator import (
4+
validate_spec, validate_spec_url,
5+
validate_v2_spec, validate_v2_spec_url,
6+
validate_spec_url_factory,
7+
openapi_v2_spec_validator, openapi_v3_spec_validator,
8+
)
59
from openapi_spec_validator.exceptions import OpenAPIValidationError
10+
from openapi_spec_validator.handlers.urllib import UrllibHandler
611

712

813
class BaseTestValidValidteV2Spec:
@@ -31,11 +36,32 @@ def test_failed(self, spec):
3136
validate_spec(spec)
3237

3338

34-
class BaseTestValidValidteV2SpecUrl:
39+
class BaseTestValidValidateSpecUrl:
40+
41+
@pytest.fixture
42+
def urllib_handlers(self):
43+
all_urls_handler = UrllibHandler('http', 'https', 'file')
44+
return {
45+
'<all_urls>': all_urls_handler,
46+
'http': UrllibHandler('http'),
47+
'https': UrllibHandler('https'),
48+
'file': UrllibHandler('file'),
49+
}
50+
51+
52+
class BaseTestValidValidateV2SpecUrl(BaseTestValidValidateSpecUrl):
53+
54+
@pytest.fixture
55+
def validate_spec_url_callable(self, urllib_handlers):
56+
return validate_spec_url_factory(
57+
openapi_v2_spec_validator.validate, urllib_handlers)
3558

3659
def test_valid(self, spec_url):
3760
validate_v2_spec_url(spec_url)
3861

62+
def test_urllib_valid(self, validate_spec_url_callable, spec_url):
63+
validate_spec_url_callable(spec_url)
64+
3965

4066
class BaseTestFaliedValidateV2SpecUrl:
4167

@@ -44,11 +70,19 @@ def test_failed(self, spec_url):
4470
validate_v2_spec_url(spec_url)
4571

4672

47-
class BaseTestValidValidteSpecUrl:
73+
class BaseTestValidValidateV3SpecUrl(BaseTestValidValidateSpecUrl):
4874

49-
def test_valid(self, spec_url):
75+
@pytest.fixture
76+
def validate_spec_url_callable(self, urllib_handlers):
77+
return validate_spec_url_factory(
78+
openapi_v3_spec_validator.validate, urllib_handlers)
79+
80+
def test_default_valid(self, spec_url):
5081
validate_spec_url(spec_url)
5182

83+
def test_urllib_valid(self, validate_spec_url_callable, spec_url):
84+
validate_spec_url_callable(spec_url)
85+
5286

5387
class BaseTestFaliedValidateSpecUrl:
5488

@@ -78,7 +112,7 @@ def spec(self, factory):
78112
return factory.spec_from_file("data/v3.0/petstore.yaml")
79113

80114

81-
class TestPetstoreV2Example(BaseTestValidValidteV2SpecUrl):
115+
class TestPetstoreV2Example(BaseTestValidValidateV2SpecUrl):
82116

83117
@pytest.fixture
84118
def spec_url(self):
@@ -89,7 +123,7 @@ def spec_url(self):
89123
)
90124

91125

92-
class TestApiV2WithExampe(BaseTestValidValidteV2SpecUrl):
126+
class TestApiV2WithExampe(BaseTestValidValidateV2SpecUrl):
93127

94128
@pytest.fixture
95129
def spec_url(self):
@@ -100,7 +134,7 @@ def spec_url(self):
100134
)
101135

102136

103-
class TestPetstoreV2ExpandedExample(BaseTestValidValidteV2SpecUrl):
137+
class TestPetstoreV2ExpandedExample(BaseTestValidValidateV2SpecUrl):
104138

105139
@pytest.fixture
106140
def spec_url(self):
@@ -111,7 +145,7 @@ def spec_url(self):
111145
)
112146

113147

114-
class TestPetstoreExample(BaseTestValidValidteSpecUrl):
148+
class TestPetstoreExample(BaseTestValidValidateV3SpecUrl):
115149

116150
@pytest.fixture
117151
def spec_url(self):
@@ -122,7 +156,7 @@ def spec_url(self):
122156
)
123157

124158

125-
class TestApiWithExampe(BaseTestValidValidteSpecUrl):
159+
class TestApiWithExampe(BaseTestValidValidateV3SpecUrl):
126160

127161
@pytest.fixture
128162
def spec_url(self):
@@ -133,7 +167,7 @@ def spec_url(self):
133167
)
134168

135169

136-
class TestPetstoreExpandedExample(BaseTestValidValidteSpecUrl):
170+
class TestPetstoreExpandedExample(BaseTestValidValidateV3SpecUrl):
137171

138172
@pytest.fixture
139173
def spec_url(self):

0 commit comments

Comments
 (0)