From 6e07b0a0401a426404eeb4393e5d9d54cf995af9 Mon Sep 17 00:00:00 2001 From: Artur Maciag Date: Mon, 9 Oct 2017 15:57:07 +0100 Subject: [PATCH] content_type renamed to mimetype --- openapi_core/media_types.py | 8 ++++---- openapi_core/request_bodies.py | 4 ++-- openapi_core/wrappers.py | 6 +++--- tests/integration/test_petstore.py | 16 ++++++++-------- tests/unit/test_request_bodies.py | 6 +++--- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/openapi_core/media_types.py b/openapi_core/media_types.py index cb0fd85..d64e639 100644 --- a/openapi_core/media_types.py +++ b/openapi_core/media_types.py @@ -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) diff --git a/openapi_core/request_bodies.py b/openapi_core/request_bodies.py index 0e94c52..66be133 100644 --- a/openapi_core/request_bodies.py +++ b/openapi_core/request_bodies.py @@ -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): diff --git a/openapi_core/wrappers.py b/openapi_core/wrappers.py index 28dfb96..d6320c6 100644 --- a/openapi_core/wrappers.py +++ b/openapi_core/wrappers.py @@ -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): diff --git a/tests/integration/test_petstore.py b/tests/integration/test_petstore.py index 2a177de..9ad7ea0 100644 --- a/tests/integration/test_petstore.py +++ b/tests/integration/test_petstore.py @@ -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): diff --git a/tests/unit/test_request_bodies.py b/tests/unit/test_request_bodies.py index cfb97fc..6f1da31 100644 --- a/tests/unit/test_request_bodies.py +++ b/tests/unit/test_request_bodies.py @@ -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]