Skip to content

Commit 7f3b980

Browse files
committed
tests - fix formatting
1 parent a0a0915 commit 7f3b980

5 files changed

Lines changed: 117 additions & 59 deletions

File tree

imagekitio/constants/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ class ERRORS(enum.Enum):
8080
MISSING_CUSTOM_METADATA_FIELD_ID = {
8181
"message": "Missing field_id for update_custom_metadata_fields",
8282
"help": "",
83-
}
83+
}

imagekitio/file.py

Lines changed: 86 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,14 @@ def get_file_versions(self, file_id: str = None) -> ListFileResult:
165165
response_meta_data = populate_response_metadata(resp)
166166
if type(response_json) == str:
167167
response_json = ast.literal_eval(response_json)
168-
error_message = response_json['message'] if type(response_json) == dict else ""
169-
response_help = response_json['help'] if type(response_json) == dict else ""
168+
error_message = (
169+
response_json["message"] if type(response_json) == dict else ""
170+
)
171+
response_help = response_json["help"] if type(response_json) == dict else ""
170172
raise NotFoundException(error_message, response_help, response_meta_data)
171173
else:
172174
general_api_throw_exception(resp)
173175

174-
175176
def get_file_version_details(
176177
self, file_id: str = None, version_id: str = None
177178
) -> FileResultWithResponseMetadata:
@@ -194,8 +195,10 @@ def get_file_version_details(
194195
response_meta_data = populate_response_metadata(resp)
195196
if type(response_json) == str:
196197
response_json = ast.literal_eval(response_json)
197-
error_message = response_json['message'] if type(response_json) == dict else ""
198-
response_help = response_json['help'] if type(response_json) == dict else ""
198+
error_message = (
199+
response_json["message"] if type(response_json) == dict else ""
200+
)
201+
response_help = response_json["help"] if type(response_json) == dict else ""
199202
raise NotFoundException(error_message, response_help, response_meta_data)
200203
else:
201204
general_api_throw_exception(resp)
@@ -212,7 +215,11 @@ def update_file_details(
212215
url = "{}/v1/files/{}/details/".format(URL.API_BASE_URL, file_id)
213216
headers = {"Content-Type": "application/json"}
214217
headers.update(self.request.get_auth_headers())
215-
data = dumps(request_formatter(options.__dict__)) if options is not None else dict()
218+
data = (
219+
dumps(request_formatter(options.__dict__))
220+
if options is not None
221+
else dict()
222+
)
216223
resp = self.request.request(method="Patch", url=url, headers=headers, data=data)
217224
if resp.status_code == 200:
218225
response = convert_to_response_object(resp, FileResultWithResponseMetadata)
@@ -291,8 +298,8 @@ def delete_file_version(self, file_id, version_id) -> ResponseMetadataResult:
291298
response_meta_data = populate_response_metadata(resp)
292299
if type(response) == str:
293300
response = ast.literal_eval(response)
294-
error_message = response['message'] if type(response) == dict else ""
295-
response_help = response['help'] if type(response) == dict else ""
301+
error_message = response["message"] if type(response) == dict else ""
302+
response_help = response["help"] if type(response) == dict else ""
296303
if resp.status_code == 400:
297304
raise BadRequestException(
298305
error_message, response_help, response_meta_data
@@ -330,7 +337,11 @@ def copy_file(
330337
url = "{}/v1/files/copy".format(URL.API_BASE_URL)
331338
headers = {"Content-Type": "application/json"}
332339
headers.update(self.request.create_headers())
333-
formatted_options = dumps(request_formatter(options.__dict__)) if options is not None else dict()
340+
formatted_options = (
341+
dumps(request_formatter(options.__dict__))
342+
if options is not None
343+
else dict()
344+
)
334345
resp = self.request.request(
335346
method="Post", url=url, headers=headers, data=formatted_options
336347
)
@@ -342,8 +353,8 @@ def copy_file(
342353
response_meta_data = populate_response_metadata(resp)
343354
if type(response) == str:
344355
response = ast.literal_eval(response)
345-
error_message = response['message'] if type(response) == dict else ""
346-
response_help = response['help'] if type(response) == dict else ""
356+
error_message = response["message"] if type(response) == dict else ""
357+
response_help = response["help"] if type(response) == dict else ""
347358
raise NotFoundException(error_message, response_help, response_meta_data)
348359
else:
349360
general_api_throw_exception(resp)
@@ -355,7 +366,11 @@ def move_file(
355366
url = "{}/v1/files/move".format(URL.API_BASE_URL)
356367
headers = {"Content-Type": "application/json"}
357368
headers.update(self.request.create_headers())
358-
formatted_options = dumps(request_formatter(options.__dict__)) if options is not None else dict()
369+
formatted_options = (
370+
dumps(request_formatter(options.__dict__))
371+
if options is not None
372+
else dict()
373+
)
359374
resp = self.request.request(
360375
method="Post", url=url, headers=headers, data=formatted_options
361376
)
@@ -367,8 +382,8 @@ def move_file(
367382
response_meta_data = populate_response_metadata(resp)
368383
if type(response) == str:
369384
response = ast.literal_eval(response)
370-
error_message = response['message'] if type(response) == dict else ""
371-
response_help = response['help'] if type(response) == dict else ""
385+
error_message = response["message"] if type(response) == dict else ""
386+
response_help = response["help"] if type(response) == dict else ""
372387
raise NotFoundException(error_message, response_help, response_meta_data)
373388
else:
374389
general_api_throw_exception(resp)
@@ -378,7 +393,11 @@ def rename_file(self, options: RenameFileRequestOptions = None) -> RenameFileRes
378393
url = "{}/v1/files/rename".format(URL.API_BASE_URL)
379394
headers = {"Content-Type": "application/json"}
380395
headers.update(self.request.create_headers())
381-
formatted_options = dumps(request_formatter(options.__dict__)) if options is not None else dict()
396+
formatted_options = (
397+
dumps(request_formatter(options.__dict__))
398+
if options is not None
399+
else dict()
400+
)
382401
resp = self.request.request(
383402
method="Put", url=url, headers=headers, data=formatted_options
384403
)
@@ -392,8 +411,8 @@ def rename_file(self, options: RenameFileRequestOptions = None) -> RenameFileRes
392411
response_meta_data = populate_response_metadata(resp)
393412
if type(response) == str:
394413
response = ast.literal_eval(response)
395-
error_message = response['message'] if type(response) == dict else ""
396-
response_help = response['help'] if type(response) == dict else ""
414+
error_message = response["message"] if type(response) == dict else ""
415+
response_help = response["help"] if type(response) == dict else ""
397416
raise ConflictException(error_message, response_help, response_meta_data)
398417
else:
399418
general_api_throw_exception(resp)
@@ -419,8 +438,8 @@ def restore_file_version(
419438
response_meta_data = populate_response_metadata(resp)
420439
if type(response) == str:
421440
response = ast.literal_eval(response)
422-
error_message = response['message'] if type(response) == dict else ""
423-
response_help = response['help'] if type(response) == dict else ""
441+
error_message = response["message"] if type(response) == dict else ""
442+
response_help = response["help"] if type(response) == dict else ""
424443
raise NotFoundException(error_message, response_help, response_meta_data)
425444
else:
426445
general_api_throw_exception(resp)
@@ -431,7 +450,9 @@ def create_folder(
431450
"""Create folder by provided folderName and parentFolderPath as an options"""
432451
url = "{}/v1/folder".format(URL.API_BASE_URL)
433452
headers = self.request.create_headers()
434-
formatted_data = request_formatter(options.__dict__) if options is not None else dict()
453+
formatted_data = (
454+
request_formatter(options.__dict__) if options is not None else dict()
455+
)
435456
resp = self.request.request(
436457
method="Post", url=url, headers=headers, data=formatted_data
437458
)
@@ -443,8 +464,8 @@ def create_folder(
443464
response_meta_data = populate_response_metadata(resp)
444465
if type(response) == str:
445466
response = ast.literal_eval(response)
446-
error_message = response['message'] if type(response) == dict else ""
447-
response_help = response['help'] if type(response) == dict else ""
467+
error_message = response["message"] if type(response) == dict else ""
468+
response_help = response["help"] if type(response) == dict else ""
448469
raise UnknownException(error_message, response_help, response_meta_data)
449470

450471
def delete_folder(
@@ -453,7 +474,9 @@ def delete_folder(
453474
"""Delete folder by provided folderPath as an options"""
454475
url = "{}/v1/folder".format(URL.API_BASE_URL)
455476
headers = self.request.create_headers()
456-
formatted_data = request_formatter(options.__dict__) if options is not None else dict()
477+
formatted_data = (
478+
request_formatter(options.__dict__) if options is not None else dict()
479+
)
457480
resp = self.request.request(
458481
method="Delete", url=url, headers=headers, data=formatted_data
459482
)
@@ -465,8 +488,10 @@ def delete_folder(
465488
response_meta_data = populate_response_metadata(resp)
466489
if type(response_json) == str:
467490
response_json = ast.literal_eval(response_json)
468-
error_message = response_json['message'] if type(response_json) == dict else ""
469-
response_help = response_json['help'] if type(response_json) == dict else ""
491+
error_message = (
492+
response_json["message"] if type(response_json) == dict else ""
493+
)
494+
response_help = response_json["help"] if type(response_json) == dict else ""
470495
raise NotFoundException(error_message, response_help, response_meta_data)
471496
else:
472497
general_api_throw_exception(resp)
@@ -476,7 +501,11 @@ def copy_folder(self, options: CopyFolderRequestOptions = None) -> FolderResult:
476501
url = "{}/v1/bulkJobs/copyFolder".format(URL.API_BASE_URL)
477502
headers = self.request.create_headers()
478503
headers.update({"Content-Type": "application/json"})
479-
formatted_data = dumps(request_formatter(options.__dict__)) if options is not None else dict()
504+
formatted_data = (
505+
dumps(request_formatter(options.__dict__))
506+
if options is not None
507+
else dict()
508+
)
480509
resp = self.request.request(
481510
method="Post", url=url, headers=headers, data=formatted_data
482511
)
@@ -488,8 +517,10 @@ def copy_folder(self, options: CopyFolderRequestOptions = None) -> FolderResult:
488517
response_meta_data = populate_response_metadata(resp)
489518
if type(response_json) == str:
490519
response_json = ast.literal_eval(response_json)
491-
error_message = response_json['message'] if type(response_json) == dict else ""
492-
response_help = response_json['help'] if type(response_json) == dict else ""
520+
error_message = (
521+
response_json["message"] if type(response_json) == dict else ""
522+
)
523+
response_help = response_json["help"] if type(response_json) == dict else ""
493524
raise NotFoundException(error_message, response_help, response_meta_data)
494525
else:
495526
general_api_throw_exception(resp)
@@ -499,7 +530,11 @@ def move_folder(self, options: MoveFolderRequestOptions = None) -> FolderResult:
499530
url = "{}/v1/bulkJobs/moveFolder".format(URL.API_BASE_URL)
500531
headers = self.request.create_headers()
501532
headers.update({"Content-Type": "application/json"})
502-
formatted_data = dumps(request_formatter(options.__dict__)) if options is not None else dict()
533+
formatted_data = (
534+
dumps(request_formatter(options.__dict__))
535+
if options is not None
536+
else dict()
537+
)
503538
resp = self.request.request(
504539
method="Post", url=url, headers=headers, data=formatted_data
505540
)
@@ -512,8 +547,10 @@ def move_folder(self, options: MoveFolderRequestOptions = None) -> FolderResult:
512547
response_meta_data = populate_response_metadata(resp)
513548
if type(response_json) == str:
514549
response_json = ast.literal_eval(response_json)
515-
error_message = response_json['message'] if type(response_json) == dict else ""
516-
response_help = response_json['help'] if type(response_json) == dict else ""
550+
error_message = (
551+
response_json["message"] if type(response_json) == dict else ""
552+
)
553+
response_help = response_json["help"] if type(response_json) == dict else ""
517554
raise NotFoundException(error_message, response_help, response_meta_data)
518555
else:
519556
general_api_throw_exception(resp)
@@ -600,11 +637,11 @@ def create_custom_metadata_fields(
600637
"""creates custom metadata fields by passing name, label and schema as an options"""
601638
url = "{}/v1/customMetadataFields".format(URL.API_BASE_URL)
602639
if options is not None:
603-
if 'schema' in options.__dict__:
640+
if "schema" in options.__dict__:
604641
options.schema.__dict__ = request_formatter(options.schema.__dict__)
605642
options_dict = options.__dict__
606-
if 'schema' in options_dict:
607-
options_dict['schema'] = options.schema.__dict__
643+
if "schema" in options_dict:
644+
options_dict["schema"] = options.schema.__dict__
608645
formatted_options = dumps(options_dict)
609646
else:
610647
formatted_options = dict()
@@ -624,8 +661,10 @@ def create_custom_metadata_fields(
624661
response_meta_data = populate_response_metadata(resp)
625662
if type(response_json) == str:
626663
response_json = ast.literal_eval(response_json)
627-
error_message = response_json['message'] if type(response_json) == dict else ""
628-
response_help = response_json['help'] if type(response_json) == dict else ""
664+
error_message = (
665+
response_json["message"] if type(response_json) == dict else ""
666+
)
667+
response_help = response_json["help"] if type(response_json) == dict else ""
629668
if resp.status_code == 400:
630669
raise BadRequestException(
631670
error_message, response_help, response_meta_data
@@ -652,11 +691,10 @@ def get_custom_metadata_fields(
652691
response_meta_data = populate_response_metadata(resp)
653692
if type(response) == str:
654693
response = ast.literal_eval(response)
655-
error_message = response['message'] if type(response) == dict else ""
656-
response_help = response['help'] if type(response) == dict else ""
694+
error_message = response["message"] if type(response) == dict else ""
695+
response_help = response["help"] if type(response) == dict else ""
657696
raise UnknownException(error_message, response_help, response_meta_data)
658697

659-
660698
def update_custom_metadata_fields(
661699
self, field_id, options: UpdateCustomMetadataFieldsRequestOptions = None
662700
) -> CustomMetadataFieldsResultWithResponseMetadata:
@@ -685,8 +723,10 @@ def update_custom_metadata_fields(
685723
response_meta_data = populate_response_metadata(resp)
686724
if type(response_json) == str:
687725
response_json = ast.literal_eval(response_json)
688-
error_message = response_json['message'] if type(response_json) == dict else ""
689-
response_help = response_json['help'] if type(response_json) == dict else ""
726+
error_message = (
727+
response_json["message"] if type(response_json) == dict else ""
728+
)
729+
response_help = response_json["help"] if type(response_json) == dict else ""
690730
if resp.status_code == 400:
691731
raise BadRequestException(
692732
error_message, response_help, response_meta_data
@@ -712,8 +752,10 @@ def delete_custom_metadata_field(self, field_id: str) -> ResponseMetadataResult:
712752
response_meta_data = populate_response_metadata(resp)
713753
if type(response_json) == str:
714754
response_json = ast.literal_eval(response_json)
715-
error_message = response_json['message'] if type(response_json) == dict else ""
716-
response_help = response_json['help'] if type(response_json) == dict else ""
755+
error_message = (
756+
response_json["message"] if type(response_json) == dict else ""
757+
)
758+
response_help = response_json["help"] if type(response_json) == dict else ""
717759
if resp.status_code == 404:
718760
raise NotFoundException(
719761
error_message, response_help, response_meta_data
@@ -747,7 +789,7 @@ def validate_upload(options):
747789
if type(val) == dict or type(val) == tuple:
748790
options[key] = dumps(val)
749791
continue
750-
if key == 'extensions':
792+
if key == "extensions":
751793
options[key] = dumps(val)
752794
continue
753795
if key == "response_fields":

imagekitio/url.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def transformation_to_str(transformation):
191191
if transform_key == "oi" or transform_key == "di":
192192
value = value.strip("/")
193193
value = value.replace("/", "@@")
194-
if transform_key == 'raw':
194+
if transform_key == "raw":
195195
for i in value.split(","):
196196
parsed_transform_step.append(i)
197197
else:

0 commit comments

Comments
 (0)