Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 82a8f65

Browse files
committed
Fixes all but one test
1 parent 6359a5c commit 82a8f65

File tree

3 files changed

+51
-13
lines changed

3 files changed

+51
-13
lines changed

modules/openapi-json-schema-generator/src/main/resources/python/api_client.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ class RequestBody(StyleFormSerializer, JSONDetector):
14121412
request_field.make_multipart(content_type='application/octet-stream')
14131413
elif isinstance(value, FileIO):
14141414
# TODO use content.encoding to limit allowed content types if they are present
1415-
request_field = RequestField.from_tuple(key, (os.path.basename(value.name), value.read()))
1415+
request_field = RequestField.from_tuples(key, (os.path.basename(value.name), value.read()))
14161416
value.close()
14171417
else:
14181418
request_field = self.__multipart_json_item(key=key, value=value)

samples/openapi3/client/petstore/python/petstore_api/api_client.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ def __eq__(self, other):
5151
return False
5252
return self.__dict__ == other.__dict__
5353

54+
def __repr__(self):
55+
self_dict = {
56+
'name': self._name,
57+
'filename': self._filename,
58+
'headers': self.headers,
59+
}
60+
return json.dumps(self_dict)
61+
5462

5563
class JSONEncoder(json.JSONEncoder):
5664
compact_separators = (',', ':')
@@ -1411,7 +1419,7 @@ def __multipart_form_item(self, key: str, value: Schema) -> RequestField:
14111419
request_field.make_multipart(content_type='application/octet-stream')
14121420
elif isinstance(value, FileIO):
14131421
# TODO use content.encoding to limit allowed content types if they are present
1414-
request_field = RequestField.from_tuple(key, (os.path.basename(value.name), value.read()))
1422+
request_field = RequestField.from_tuples(key, (os.path.basename(value.name), value.read()))
14151423
value.close()
14161424
else:
14171425
request_field = self.__multipart_json_item(key=key, value=value)

samples/openapi3/client/petstore/python/tests_manual/test_fake_api.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,11 @@ def test_upload_file(self):
468468
name='file',
469469
data=file_bytes,
470470
filename=file_name,
471-
headers={'Content-Type': 'application/octet-stream'}
471+
headers={
472+
'Content-Location': None,
473+
'Content-Type': 'image/png',
474+
"Content-Disposition": "form-data; name=\"file\"; filename=\"1px_pic1.png\""
475+
}
472476
),
473477
),
474478
content_type='multipart/form-data'
@@ -492,7 +496,11 @@ def test_upload_file(self):
492496
api_client.RequestField(
493497
name='file',
494498
data=file_bytes,
495-
headers={'Content-Type': 'application/octet-stream'}
499+
headers={
500+
'Content-Type': 'application/octet-stream',
501+
"Content-Disposition": "form-data; name=\"file\"",
502+
"Content-Location": None
503+
}
496504
),
497505
),
498506
content_type='multipart/form-data'
@@ -547,13 +555,22 @@ def test_upload_files(self):
547555
name='files',
548556
data=file_bytes,
549557
filename=file_name,
550-
headers={'Content-Type': 'application/octet-stream'}
558+
headers={
559+
'Content-Type': 'image/png',
560+
"Content-Disposition": "form-data; name=\"files\"; filename=\"1px_pic1.png\"",
561+
"Content-Location": None
562+
}
551563
),
552564
api_client.RequestField(
553565
name='files',
554566
data=file_bytes,
555567
filename=file_name,
556-
headers={'Content-Type': 'application/octet-stream'}
568+
headers={
569+
'Content-Type': 'image/png',
570+
"Content-Disposition": "form-data; name=\"files\"; filename=\"1px_pic1.png\"",
571+
"Content-Location": None
572+
573+
}
557574
),
558575
),
559576
content_type='multipart/form-data'
@@ -578,12 +595,20 @@ def test_upload_files(self):
578595
api_client.RequestField(
579596
name='files',
580597
data=file_bytes,
581-
headers={'Content-Type': 'application/octet-stream'}
598+
headers={
599+
'Content-Type': 'application/octet-stream',
600+
"Content-Disposition": "form-data; name=\"files\"",
601+
"Content-Location": None
602+
}
582603
),
583604
api_client.RequestField(
584605
name='files',
585606
data=file_bytes,
586-
headers={'Content-Type': 'application/octet-stream'}
607+
headers={
608+
'Content-Type': 'application/octet-stream',
609+
"Content-Disposition": "form-data; name=\"files\"",
610+
"Content-Location": None
611+
}
587612
),
588613
),
589614
content_type='multipart/form-data'
@@ -650,17 +675,22 @@ def test_inline_composition(self, mock_request):
650675
content_type=content_type,
651676
accept_content_types=(content_type,)
652677
)
678+
self.maxDiff = None
653679
self.assert_request_called_with(
654680
mock_request,
655681
'http://petstore.swagger.io:80/v2/fake/inlineComposition/?compositionAtRoot=a&someProp=a',
656682
accept_content_type=content_type,
657683
content_type=content_type,
658684
fields=(
659-
api_client.RequestField(
660-
name='someProp',
661-
data=single_char_str,
662-
headers={'Content-Type': 'text/plain'}
663-
),
685+
api_client.RequestField(
686+
name='someProp',
687+
data=single_char_str,
688+
headers={
689+
'Content-Type': 'text/plain',
690+
"Content-Disposition": "form-data; name=\"someProp\"",
691+
"Content-Location": None
692+
}
693+
),
664694
),
665695
)
666696
self.assertEqual(api_response.body, {'someProp': single_char_str})

0 commit comments

Comments
 (0)