Skip to content

Commit

Permalink
urllib handler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
p1c2u committed Feb 18, 2021
1 parent 0499fd7 commit f1267ac
Showing 1 changed file with 45 additions and 11 deletions.
56 changes: 45 additions & 11 deletions tests/integration/test_shortcuts.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import pytest

from openapi_spec_validator import validate_spec, validate_spec_url
from openapi_spec_validator import validate_v2_spec, validate_v2_spec_url
from openapi_spec_validator import (
validate_spec, validate_spec_url,
validate_v2_spec, validate_v2_spec_url,
validate_spec_url_factory,
openapi_v2_spec_validator, openapi_v3_spec_validator,
)
from openapi_spec_validator.exceptions import OpenAPIValidationError
from openapi_spec_validator.handlers.urllib import UrllibHandler


class BaseTestValidValidteV2Spec:
Expand Down Expand Up @@ -31,11 +36,32 @@ def test_failed(self, spec):
validate_spec(spec)


class BaseTestValidValidteV2SpecUrl:
class BaseTestValidValidateSpecUrl:

@pytest.fixture
def urllib_handlers(self):
all_urls_handler = UrllibHandler('http', 'https', 'file')
return {
'<all_urls>': all_urls_handler,
'http': UrllibHandler('http'),
'https': UrllibHandler('https'),
'file': UrllibHandler('file'),
}


class BaseTestValidValidateV2SpecUrl(BaseTestValidValidateSpecUrl):

@pytest.fixture
def validate_spec_url_callable(self, urllib_handlers):
return validate_spec_url_factory(
openapi_v2_spec_validator.validate, urllib_handlers)

def test_valid(self, spec_url):
validate_v2_spec_url(spec_url)

def test_urllib_valid(self, validate_spec_url_callable, spec_url):
validate_spec_url_callable(spec_url)


class BaseTestFaliedValidateV2SpecUrl:

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


class BaseTestValidValidteSpecUrl:
class BaseTestValidValidateV3SpecUrl(BaseTestValidValidateSpecUrl):

def test_valid(self, spec_url):
@pytest.fixture
def validate_spec_url_callable(self, urllib_handlers):
return validate_spec_url_factory(
openapi_v3_spec_validator.validate, urllib_handlers)

def test_default_valid(self, spec_url):
validate_spec_url(spec_url)

def test_urllib_valid(self, validate_spec_url_callable, spec_url):
validate_spec_url_callable(spec_url)


class BaseTestFaliedValidateSpecUrl:

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


class TestPetstoreV2Example(BaseTestValidValidteV2SpecUrl):
class TestPetstoreV2Example(BaseTestValidValidateV2SpecUrl):

@pytest.fixture
def spec_url(self):
Expand All @@ -89,7 +123,7 @@ def spec_url(self):
)


class TestApiV2WithExampe(BaseTestValidValidteV2SpecUrl):
class TestApiV2WithExampe(BaseTestValidValidateV2SpecUrl):

@pytest.fixture
def spec_url(self):
Expand All @@ -100,7 +134,7 @@ def spec_url(self):
)


class TestPetstoreV2ExpandedExample(BaseTestValidValidteV2SpecUrl):
class TestPetstoreV2ExpandedExample(BaseTestValidValidateV2SpecUrl):

@pytest.fixture
def spec_url(self):
Expand All @@ -111,7 +145,7 @@ def spec_url(self):
)


class TestPetstoreExample(BaseTestValidValidteSpecUrl):
class TestPetstoreExample(BaseTestValidValidateV3SpecUrl):

@pytest.fixture
def spec_url(self):
Expand All @@ -122,7 +156,7 @@ def spec_url(self):
)


class TestApiWithExampe(BaseTestValidValidteSpecUrl):
class TestApiWithExampe(BaseTestValidValidateV3SpecUrl):

@pytest.fixture
def spec_url(self):
Expand All @@ -133,7 +167,7 @@ def spec_url(self):
)


class TestPetstoreExpandedExample(BaseTestValidValidteSpecUrl):
class TestPetstoreExpandedExample(BaseTestValidValidateV3SpecUrl):

@pytest.fixture
def spec_url(self):
Expand Down

0 comments on commit f1267ac

Please sign in to comment.