openapi-core/tests/unit/templating/test_responses_finders.py

42 lines
1.1 KiB
Python
Raw Normal View History

2021-04-27 21:39:28 +00:00
from __future__ import division
2021-03-31 15:01:03 +00:00
import mock
import pytest
2021-04-23 11:36:27 +00:00
from openapi_core.spec.paths import SpecPath
2021-03-31 15:01:03 +00:00
from openapi_core.templating.responses.finders import ResponseFinder
class TestResponses(object):
@pytest.fixture(scope='class')
2021-04-23 11:36:27 +00:00
def spec(self):
2021-03-31 15:01:03 +00:00
return {
'200': mock.sentinel.response_200,
'299': mock.sentinel.response_299,
'2XX': mock.sentinel.response_2XX,
'default': mock.sentinel.response_default,
}
2021-04-23 11:36:27 +00:00
@pytest.fixture(scope='class')
def responses(self, spec):
return SpecPath.from_spec(spec)
2021-03-31 15:01:03 +00:00
@pytest.fixture(scope='class')
def finder(self, responses):
return ResponseFinder(responses)
def test_default(self, finder, responses):
response = finder.find()
2021-04-23 11:36:27 +00:00
assert response == responses / 'default'
2021-03-31 15:01:03 +00:00
def test_range(self, finder, responses):
response = finder.find('201')
2021-04-23 11:36:27 +00:00
assert response == responses / '2XX'
2021-03-31 15:01:03 +00:00
def test_exact(self, finder, responses):
response = finder.find('200')
2021-04-23 11:36:27 +00:00
assert response == responses / '200'