mirror of
https://github.com/correl/openapi-core.git
synced 2024-12-29 11:09:25 +00:00
content_type renamed to mimetype
This commit is contained in:
parent
fc28729eea
commit
6e07b0a040
5 changed files with 20 additions and 20 deletions
|
@ -5,8 +5,8 @@ from six import iteritems
|
|||
class MediaType(object):
|
||||
"""Represents an OpenAPI MediaType."""
|
||||
|
||||
def __init__(self, content_type, schema=None):
|
||||
self.content_type = content_type
|
||||
def __init__(self, mimetype, schema=None):
|
||||
self.mimetype = mimetype
|
||||
self.schema = schema
|
||||
|
||||
def unmarshal(self, value):
|
||||
|
@ -23,11 +23,11 @@ class MediaTypeGenerator(object):
|
|||
self.schemas_registry = schemas_registry
|
||||
|
||||
def generate(self, content):
|
||||
for content_type, media_type in iteritems(content):
|
||||
for mimetype, media_type in iteritems(content):
|
||||
schema_spec = media_type.get('schema')
|
||||
|
||||
schema = None
|
||||
if schema_spec:
|
||||
schema, _ = self.schemas_registry.get_or_create(schema_spec)
|
||||
|
||||
yield content_type, MediaType(content_type, schema)
|
||||
yield mimetype, MediaType(mimetype, schema)
|
||||
|
|
|
@ -11,8 +11,8 @@ class RequestBody(object):
|
|||
self.content = dict(content)
|
||||
self.required = required
|
||||
|
||||
def __getitem__(self, content_type):
|
||||
return self.content[content_type]
|
||||
def __getitem__(self, mimetype):
|
||||
return self.content[mimetype]
|
||||
|
||||
|
||||
class RequestBodyFactory(object):
|
||||
|
|
|
@ -95,10 +95,10 @@ class RequestBodyFactory(BaseRequestFactory):
|
|||
return None
|
||||
|
||||
try:
|
||||
media_type = operation.request_body[request.content_type]
|
||||
media_type = operation.request_body[request.mimetype]
|
||||
except KeyError:
|
||||
raise InvalidContentTypeError(
|
||||
"Invalid Content-Type `{0}`".format(request.content_type))
|
||||
"Invalid media type `{0}`".format(request.mimetype))
|
||||
|
||||
return media_type.unmarshal(request.data)
|
||||
|
||||
|
@ -117,7 +117,7 @@ class BaseOpenAPIRequest(object):
|
|||
|
||||
data = NotImplemented
|
||||
|
||||
content_type = NotImplemented
|
||||
mimetype = NotImplemented
|
||||
|
||||
@property
|
||||
def full_url_pattern(self):
|
||||
|
|
|
@ -21,7 +21,7 @@ class RequestMock(BaseOpenAPIRequest):
|
|||
def __init__(
|
||||
self, host_url, method, path, path_pattern=None, args=None,
|
||||
view_args=None, headers=None, cookies=None, data=None,
|
||||
content_type='application/json'):
|
||||
mimetype='application/json'):
|
||||
self.host_url = host_url
|
||||
self.path = path
|
||||
self.path_pattern = path_pattern or path
|
||||
|
@ -33,7 +33,7 @@ class RequestMock(BaseOpenAPIRequest):
|
|||
self.cookies = cookies or {}
|
||||
self.data = data or ''
|
||||
|
||||
self.content_type = content_type
|
||||
self.mimetype = mimetype
|
||||
|
||||
|
||||
class TestPetstore(object):
|
||||
|
@ -89,12 +89,12 @@ class TestPetstore(object):
|
|||
assert bool(operation.request_body.required) ==\
|
||||
request_body_spec.get('required', False)
|
||||
|
||||
for content_type, media_type in iteritems(
|
||||
for mimetype, media_type in iteritems(
|
||||
operation.request_body.content):
|
||||
assert type(media_type) == MediaType
|
||||
assert media_type.content_type == content_type
|
||||
assert media_type.mimetype == mimetype
|
||||
|
||||
content_spec = request_body_spec['content'][content_type]
|
||||
content_spec = request_body_spec['content'][mimetype]
|
||||
schema_spec = content_spec.get('schema')
|
||||
assert bool(schema_spec) == bool(media_type.schema)
|
||||
|
||||
|
@ -351,7 +351,7 @@ class TestPetstore(object):
|
|||
with pytest.raises(InvalidValueType):
|
||||
request.get_body(spec)
|
||||
|
||||
def test_post_pets_raises_invalid_content_type(self, spec):
|
||||
def test_post_pets_raises_invalid_mimetype(self, spec):
|
||||
host_url = 'http://petstore.swagger.io/v1'
|
||||
path_pattern = '/v1/pets'
|
||||
data_json = {
|
||||
|
@ -362,7 +362,7 @@ class TestPetstore(object):
|
|||
|
||||
request = RequestMock(
|
||||
host_url, 'POST', '/pets',
|
||||
path_pattern=path_pattern, data=data, content_type='text/html',
|
||||
path_pattern=path_pattern, data=data, mimetype='text/html',
|
||||
)
|
||||
|
||||
parameters = request.get_parameters(spec)
|
||||
|
@ -383,7 +383,7 @@ class TestPetstore(object):
|
|||
|
||||
request = RequestMock(
|
||||
host_url, 'POST', '/pets',
|
||||
path_pattern=path_pattern, data=data, content_type='text/html',
|
||||
path_pattern=path_pattern, data=data, mimetype='text/html',
|
||||
)
|
||||
|
||||
with pytest.raises(InvalidServerError):
|
||||
|
|
|
@ -16,6 +16,6 @@ class TestRequestBodies(object):
|
|||
|
||||
@property
|
||||
def test_iteritems(self, request_body):
|
||||
for content_type in request_body.content.keys():
|
||||
assert request_body[content_type] ==\
|
||||
request_body.content[content_type]
|
||||
for mimetype in request_body.content.keys():
|
||||
assert request_body[mimetype] ==\
|
||||
request_body.content[mimetype]
|
||||
|
|
Loading…
Reference in a new issue