Skip to content

Commit d99c7e4

Browse files
committed
Replace response mimetype with content_type
1 parent 519dafd commit d99c7e4

File tree

16 files changed

+36
-30
lines changed

16 files changed

+36
-30
lines changed

Diff for: openapi_core/contrib/aiohttp/responses.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def status_code(self) -> int:
2626
return self.response.status
2727

2828
@property
29-
def mimetype(self) -> str:
29+
def content_type(self) -> str:
3030
return self.response.content_type or ""
3131

3232
@property

Diff for: openapi_core/contrib/django/responses.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def headers(self) -> Headers:
2626
return Headers(self.response.headers.items())
2727

2828
@property
29-
def mimetype(self) -> str:
29+
def content_type(self) -> str:
3030
content_type = self.response.get("Content-Type", "")
3131
assert isinstance(content_type, str)
3232
return content_type

Diff for: openapi_core/contrib/falcon/responses.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def status_code(self) -> int:
2121
return int(self.response.status[:3])
2222

2323
@property
24-
def mimetype(self) -> str:
25-
mimetype = ""
24+
def content_type(self) -> str:
25+
content_type = ""
2626
if self.response.content_type:
27-
mimetype = self.response.content_type.partition(";")[0]
27+
content_type = self.response.content_type
2828
else:
29-
mimetype = self.response.options.default_media_type
30-
return mimetype
29+
content_type = self.response.options.default_media_type
30+
return content_type
3131

3232
@property
3333
def headers(self) -> Headers:

Diff for: openapi_core/contrib/requests/responses.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def status_code(self) -> int:
1919
return int(self.response.status_code)
2020

2121
@property
22-
def mimetype(self) -> str:
22+
def content_type(self) -> str:
2323
return str(self.response.headers.get("Content-Type", ""))
2424

2525
@property

Diff for: openapi_core/contrib/starlette/responses.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def status_code(self) -> int:
2121
return self.response.status_code
2222

2323
@property
24-
def mimetype(self) -> str:
25-
return self.response.media_type or ""
24+
def content_type(self) -> str:
25+
return self.response.headers.get("Content-Type") or ""
2626

2727
@property
2828
def headers(self) -> Headers:

Diff for: openapi_core/contrib/werkzeug/responses.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def status_code(self) -> int:
1818
return self.response._status_code
1919

2020
@property
21-
def mimetype(self) -> str:
21+
def content_type(self) -> str:
2222
return str(self.response.mimetype)
2323

2424
@property

Diff for: openapi_core/protocols.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ class Response(Protocol):
115115
The status code as integer.
116116
headers
117117
Response headers as Headers.
118-
mimetype
119-
Lowercase content type without charset.
118+
content_type
119+
The content type with parameters and always lowercase.
120120
"""
121121

122122
@property
@@ -128,7 +128,7 @@ def status_code(self) -> int:
128128
...
129129

130130
@property
131-
def mimetype(self) -> str:
131+
def content_type(self) -> str:
132132
...
133133

134134
@property

Diff for: openapi_core/testing/responses.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def __init__(
1212
data: str,
1313
status_code: int = 200,
1414
headers: Optional[Dict[str, Any]] = None,
15-
mimetype: str = "application/json",
15+
content_type: str = "application/json",
1616
):
1717
self.data = data
1818
self.status_code = status_code
1919
self.headers = Headers(headers or {})
20-
self.mimetype = mimetype
20+
self.content_type = content_type

Diff for: openapi_core/unmarshalling/response/unmarshallers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _unmarshal(
6666

6767
try:
6868
validated_data = self._get_data(
69-
response.data, response.mimetype, operation_response
69+
response.data, response.content_type, operation_response
7070
)
7171
except DataValidationError as exc:
7272
validated_data = None
@@ -106,7 +106,7 @@ def _unmarshal_data(
106106

107107
try:
108108
validated = self._get_data(
109-
response.data, response.mimetype, operation_response
109+
response.data, response.content_type, operation_response
110110
)
111111
except DataValidationError as exc:
112112
validated = None

Diff for: openapi_core/validation/response/validators.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,10 @@ def iter_errors(
234234
return
235235

236236
yield from self._iter_data_errors(
237-
response.status_code, response.data, response.mimetype, operation
237+
response.status_code,
238+
response.data,
239+
response.content_type,
240+
operation,
238241
)
239242

240243

@@ -273,7 +276,7 @@ def iter_errors(
273276
response.status_code,
274277
response.data,
275278
response.headers,
276-
response.mimetype,
279+
response.content_type,
277280
operation,
278281
)
279282

@@ -292,7 +295,10 @@ def iter_errors(
292295
return
293296

294297
yield from self._iter_data_errors(
295-
response.status_code, response.data, response.mimetype, operation
298+
response.status_code,
299+
response.data,
300+
response.content_type,
301+
operation,
296302
)
297303

298304

@@ -331,7 +337,7 @@ def iter_errors(
331337
response.status_code,
332338
response.data,
333339
response.headers,
334-
response.mimetype,
340+
response.content_type,
335341
operation,
336342
)
337343

Diff for: tests/integration/test_petstore.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def test_get_pets_response_no_schema(self, spec):
232232

233233
data = b"<html></html>"
234234
response = MockResponse(
235-
data, status_code=404, mimetype="text/html; charset=utf-8"
235+
data, status_code=404, content_type="text/html; charset=utf-8"
236236
)
237237

238238
response_result = unmarshal_response(request, response, spec=spec)
@@ -1372,7 +1372,7 @@ def test_get_pet_wildcard(self, spec):
13721372
assert result.body is None
13731373

13741374
data = b"imagedata"
1375-
response = MockResponse(data, mimetype="image/png")
1375+
response = MockResponse(data, content_type="image/png")
13761376

13771377
response_result = unmarshal_response(request, response, spec=spec)
13781378

Diff for: tests/integration/unmarshalling/test_response_unmarshaller.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_invalid_response(self, response_unmarshaller):
7272

7373
def test_invalid_content_type(self, response_unmarshaller):
7474
request = MockRequest(self.host_url, "get", "/v1/pets")
75-
response = MockResponse("Not Found", mimetype="text/csv")
75+
response = MockResponse("Not Found", content_type="text/csv")
7676

7777
result = response_unmarshaller.unmarshal(request, response)
7878

Diff for: tests/integration/validation/test_response_validators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_invalid_response(self, response_validator):
6161

6262
def test_invalid_content_type(self, response_validator):
6363
request = MockRequest(self.host_url, "get", "/v1/pets")
64-
response = MockResponse("Not Found", mimetype="text/csv")
64+
response = MockResponse("Not Found", content_type="text/csv")
6565

6666
with pytest.raises(DataValidationError) as exc_info:
6767
response_validator.validate(request, response)

Diff for: tests/unit/contrib/django/test_django.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_stream_response(self, response_factory):
184184

185185
assert openapi_response.data == "foo\nbar\nbaz\n"
186186
assert openapi_response.status_code == response.status_code
187-
assert openapi_response.mimetype == response["Content-Type"]
187+
assert openapi_response.content_type == response["Content-Type"]
188188

189189
def test_redirect_response(self, response_factory):
190190
data = "/redirected/"
@@ -194,4 +194,4 @@ def test_redirect_response(self, response_factory):
194194

195195
assert openapi_response.data == data
196196
assert openapi_response.status_code == response.status_code
197-
assert openapi_response.mimetype == response["Content-Type"]
197+
assert openapi_response.content_type == response["Content-Type"]

Diff for: tests/unit/contrib/flask/test_flask_responses.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ def test_invalid_server(self, response_factory):
1717

1818
assert openapi_response.data == data
1919
assert openapi_response.status_code == status_code
20-
assert openapi_response.mimetype == response.mimetype
20+
assert openapi_response.content_type == response.mimetype

Diff for: tests/unit/contrib/requests/test_requests_responses.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ def test_invalid_server(self, response_factory):
1818
assert openapi_response.data == data
1919
assert openapi_response.status_code == status_code
2020
mimetype = response.headers.get("Content-Type")
21-
assert openapi_response.mimetype == mimetype
21+
assert openapi_response.content_type == mimetype

0 commit comments

Comments
 (0)