diff --git a/swh/deposit/api/common.py b/swh/deposit/api/common.py --- a/swh/deposit/api/common.py +++ b/swh/deposit/api/common.py @@ -266,7 +266,7 @@ deposit = Deposit.objects.get(pk=deposit_id) except Deposit.DoesNotExist: return make_error_dict( - NOT_FOUND, "The deposit %s does not exist" % deposit_id + NOT_FOUND, f"The deposit {deposit_id} does not exist" ) DepositRequest.objects.filter(deposit=deposit, type=ARCHIVE_TYPE).delete() @@ -288,7 +288,7 @@ deposit = Deposit.objects.get(pk=deposit_id) except Deposit.DoesNotExist: return make_error_dict( - NOT_FOUND, "The deposit %s does not exist" % deposit_id + NOT_FOUND, f"The deposit {deposit_id} does not exist" ) if deposit.collection.name != collection_name: @@ -320,13 +320,13 @@ detailing the problem. """ + max_upload_size = self.config["max_upload_size"] if content_length: - if content_length > self.config["max_upload_size"]: + if content_length > max_upload_size: return make_error_dict( MAX_UPLOAD_SIZE_EXCEEDED, - "Upload size limit exceeded (max %s bytes)." - % self.config["max_upload_size"], - "Please consider sending the archive in " "multiple steps.", + f"Upload size limit exceeded (max {max_upload_size} bytes)." + "Please consider sending the archive in multiple steps.", ) length = filehandler.size @@ -341,9 +341,8 @@ return make_error_dict( CHECKSUM_MISMATCH, "Wrong md5 hash", - "The checksum sent %s and the actual checksum " - "%s does not match." - % (hashutil.hash_to_hex(md5sum), hashutil.hash_to_hex(_md5sum)), + f"The checksum sent {hashutil.hash_to_hex(md5sum)} and the actual " + f"checksum {hashutil.hash_to_hex(_md5sum)} does not match.", ) return None @@ -398,7 +397,7 @@ return make_error_dict( BAD_REQUEST, "CONTENT_LENGTH header is mandatory", - "For archive deposit, the " "CONTENT_LENGTH header must be sent.", + "For archive deposit, the CONTENT_LENGTH header must be sent.", ) content_disposition = headers["content-disposition"] @@ -406,15 +405,15 @@ return make_error_dict( BAD_REQUEST, "CONTENT_DISPOSITION header is mandatory", - "For archive deposit, the " "CONTENT_DISPOSITION header must be sent.", + "For archive deposit, the CONTENT_DISPOSITION header must be sent.", ) packaging = headers["packaging"] if packaging and packaging not in ACCEPT_PACKAGINGS: return make_error_dict( BAD_REQUEST, - "Only packaging %s is supported" % ACCEPT_PACKAGINGS, - "The packaging provided %s is not supported" % packaging, + f"Only packaging {ACCEPT_PACKAGINGS} is supported", + f"The packaging provided {packaging} is not supported", ) filehandler = request.FILES["file"] @@ -727,7 +726,7 @@ self._collection = DepositCollection.objects.get(name=collection_name) except DepositCollection.DoesNotExist: return make_error_dict( - NOT_FOUND, "Unknown collection name %s" % collection_name + NOT_FOUND, f"Unknown collection name {collection_name}" ) username = request.user.username @@ -735,13 +734,12 @@ try: self._client = DepositClient.objects.get(username=username) except DepositClient.DoesNotExist: - return make_error_dict(NOT_FOUND, "Unknown client name %s" % username) + return make_error_dict(NOT_FOUND, f"Unknown client name {username}") if self._collection.id not in self._client.collections: return make_error_dict( FORBIDDEN, - "Client %s cannot access collection %s" - % (username, collection_name), + f"Client {username} cannot access collection {collection_name}", ) if deposit_id: @@ -749,7 +747,7 @@ deposit = Deposit.objects.get(pk=deposit_id) except Deposit.DoesNotExist: return make_error_dict( - NOT_FOUND, "Deposit with id %s does not exist" % deposit_id + NOT_FOUND, f"Deposit with id {deposit_id} does not exist" ) checks = self.restrict_access(request, deposit) @@ -772,7 +770,7 @@ summary = "You can only act on deposit with status '%s'" % ( DEPOSIT_STATUS_PARTIAL, ) - description = "This deposit has status '%s'" % deposit.status + description = f"This deposit has status '{deposit.status}'" return make_error_dict( BAD_REQUEST, summary=summary, verbose_description=description ) @@ -781,7 +779,7 @@ return make_error_response( request, METHOD_NOT_ALLOWED, - "%s method is not supported on this endpoint" % method, + f"{method} method is not supported on this endpoint", ) def get(self, request, *args, **kwargs): diff --git a/swh/deposit/cli/client.py b/swh/deposit/cli/client.py --- a/swh/deposit/cli/client.py +++ b/swh/deposit/cli/client.py @@ -235,7 +235,7 @@ if not archive and not metadata and partial: raise InputError( - "Please provide an actionable command. See --help for more " "information" + "Please provide an actionable command. See --help for more information" ) if replace and not deposit_id: diff --git a/swh/deposit/tests/api/test_deposit_private_read_metadata.py b/swh/deposit/tests/api/test_deposit_private_read_metadata.py --- a/swh/deposit/tests/api/test_deposit_private_read_metadata.py +++ b/swh/deposit/tests/api/test_deposit_private_read_metadata.py @@ -255,7 +255,7 @@ "codemeta:version": "1", "external_identifier": ["some-external-id", "hal-01243065"], "id": "hal-01243065", - "title": "Composing a Web of Audio " "Applications", + "title": "Composing a Web of Audio Applications", "url": "https://hal-test.archives-ouvertes.fr/some-external-id", } expected_meta = { @@ -328,8 +328,8 @@ "author": {"email": "hal@ccsd.cnrs.fr", "name": "HAL"}, "client": "hal", "codemeta:applicationCategory": "test", - "codemeta:author": {"codemeta:name": "Morane " "Gruenpeter"}, - "codemeta:description": "this is the " "description", + "codemeta:author": {"codemeta:name": "Morane Gruenpeter"}, + "codemeta:description": "this is the description", "codemeta:developmentStatus": "stable", "codemeta:keywords": "DSP programming", "codemeta:license": [ @@ -356,7 +356,7 @@ "codemeta:version": "1", "external_identifier": "hal-01243065", "id": "hal-01243065", - "title": "Composing a Web of Audio " "Applications", + "title": "Composing a Web of Audio Applications", } expected_origin = { @@ -451,7 +451,7 @@ "author": {"email": "hal@ccsd.cnrs.fr", "name": "HAL"}, "client": "hal", "codemeta:applicationCategory": "test", - "codemeta:author": {"codemeta:name": "Morane " "Gruenpeter"}, + "codemeta:author": {"codemeta:name": "Morane Gruenpeter"}, "codemeta:dateCreated": [ "2015-04-06T17:08:47+02:00", "2016-04-06T17:08:47+02:00", @@ -487,7 +487,7 @@ "codemeta:version": "1", "external_identifier": "hal-01243065", "id": "hal-01243065", - "title": "Composing a Web of Audio " "Applications", + "title": "Composing a Web of Audio Applications", } expected_origin_metadata = {