From 151abe11f25d9a31701582a1f30610276ead1931 Mon Sep 17 00:00:00 2001 From: Oittaa Date: Sat, 3 Aug 2024 20:32:36 +0200 Subject: [PATCH] Make linter happy --- src/gcp_storage_emulator/handlers/objects.py | 20 ++++++++++++-------- tests/test_server.py | 11 +++++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/gcp_storage_emulator/handlers/objects.py b/src/gcp_storage_emulator/handlers/objects.py index e10c92f..522c3ec 100644 --- a/src/gcp_storage_emulator/handlers/objects.py +++ b/src/gcp_storage_emulator/handlers/objects.py @@ -426,12 +426,14 @@ def rewrite(request, response, storage, *args, **kwargs): file, dest_obj, ) - response.json({ - "resource": dest_obj, - "written": dest_obj["size"], - "size": dest_obj["size"], - "done": True, - }) + response.json( + { + "resource": dest_obj, + "written": dest_obj["size"], + "size": dest_obj["size"], + "done": True, + } + ) except NotFound: response.status = HTTPStatus.NOT_FOUND except Conflict as err: @@ -510,8 +512,10 @@ def download(request, response, storage, *args, **kwargs): hash_header = "crc32c={},md5={}".format(obj["crc32c"], obj["md5Hash"]) response[_HASH_HEADER] = hash_header - if 'response-content-disposition' in request.query: - response['Content-Disposition'] = request.query['response-content-disposition'][0] + if "response-content-disposition" in request.query: + response["Content-Disposition"] = request.query[ + "response-content-disposition" + ][0] response.write_file(file, content_type=obj.get("contentType")) except NotFound: diff --git a/tests/test_server.py b/tests/test_server.py index e16b3cf..add76d3 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -817,7 +817,7 @@ def test_signed_url_download_with_content_disposition(self): blob = bucket.blob("signed-download") blob.upload_from_string(content, content_type="text/mycustom") - requested_filename = 'requested_filename.cst2' + requested_filename = "requested_filename.cst2" response_disposition = f'attachment; filename="{requested_filename}"' url = blob.generate_signed_url( @@ -832,17 +832,20 @@ def test_signed_url_download_with_content_disposition(self): response = requests.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, content) - self.assertEqual(response.headers['content-disposition'], f"{response_disposition}") + self.assertEqual( + response.headers["content-disposition"], f"{response_disposition}" + ) self.assertEqual(response.headers["content-type"], "text/mycustom") def test_url_generation_for_browser(self): - self.skipTest('Used to test browser functionality with URL, not API.') + self.skipTest("Used to test browser functionality with URL, not API.") os.environ["STORAGE_EMULATOR_HOST"] = "http://localhost:8080" content = b"The quick brown fox jumps over the lazy dog" # Cloud Storage uses environment variables to configure API endpoints for # file upload - which is read at module import time from google.cloud import storage + http = requests.Session() client = storage.Client( @@ -856,7 +859,7 @@ def test_url_generation_for_browser(self): blob = bucket.blob("signed-download") blob.upload_from_string(content, content_type="text/html") - requested_filename = 'requested_filename.cst2' + requested_filename = "requested_filename.cst2" response_disposition = f'attachment; filename="{requested_filename}"' url = blob.generate_signed_url(