openapi-core/tests/unit/deserializing/test_deserialize.py
2020-02-03 13:05:44 +00:00

43 lines
1.2 KiB
Python

import pytest
from openapi_core.deserializing.parameters.factories import (
ParameterDeserializersFactory,
)
from openapi_core.deserializing.parameters.exceptions import (
EmptyParameterValue,
)
from openapi_core.schema.parameters.models import Parameter
@pytest.fixture
def deserializer_factory():
def create_deserializer(param):
return ParameterDeserializersFactory().create(param)
return create_deserializer
class TestParameterDeserialise(object):
def test_deprecated(self, deserializer_factory):
param = Parameter('param', 'query', deprecated=True)
value = 'test'
with pytest.warns(DeprecationWarning):
result = deserializer_factory(param)(value)
assert result == value
def test_query_empty(self, deserializer_factory):
param = Parameter('param', 'query')
value = ''
with pytest.raises(EmptyParameterValue):
deserializer_factory(param)(value)
def test_query_valid(self, deserializer_factory):
param = Parameter('param', 'query')
value = 'test'
result = deserializer_factory(param)(value)
assert result == value