diff --git a/swh/deposit/api/checks.py b/swh/deposit/api/checks.py index 1d82a28e975a5cfcd5672f8cf29eb50d343abf71..2243aee8d12c894d37fb4c46e46c8806bb4e5ed4 100644 --- a/swh/deposit/api/checks.py +++ b/swh/deposit/api/checks.py @@ -71,17 +71,23 @@ def absolute_uri_validator( url = urllib.parse.urlparse(element.text) except ValueError: yield xmlschema.XMLSchemaValidationError( - xsd_element, element, f"{element.text!r} is not a valid URI", + xsd_element, + element, + f"{element.text!r} is not a valid URI", ) else: if not url.scheme or not url.netloc: yield xmlschema.XMLSchemaValidationError( - xsd_element, element, f"{element.text!r} is not an absolute URI", + xsd_element, + element, + f"{element.text!r} is not an absolute URI", ) elif " " in url.netloc: # urllib is a little too permissive... yield xmlschema.XMLSchemaValidationError( - xsd_element, element, f"{element.text!r} is not a valid URI", + xsd_element, + element, + f"{element.text!r} is not a valid URI", ) @@ -236,5 +242,6 @@ def check_url_match_provider(url: str, provider_url: str) -> None: provider_url = provider_url.rstrip("/") + "/" if not url.startswith(provider_url): raise DepositError( - FORBIDDEN, f"URL mismatch: {url} must start with {provider_url}", + FORBIDDEN, + f"URL mismatch: {url} must start with {provider_url}", ) diff --git a/swh/deposit/api/collection.py b/swh/deposit/api/collection.py index b877ccf6369047429bf5012b8fde46b0535d49f0..e80c0bf0b5607583d2d64efd31af8e7740427d36 100644 --- a/swh/deposit/api/collection.py +++ b/swh/deposit/api/collection.py @@ -47,9 +47,7 @@ class CollectionAPI(ListAPIView, APIPost): pagination_class = DefaultPagination def get(self, request, *args, **kwargs): - """List the user's collection if the user has access to said collection. - - """ + """List the user's collection if the user has access to said collection.""" self.checks(request, kwargs["collection_name"]) paginated_result = super().get(request, *args, **kwargs) data = paginated_result.data diff --git a/swh/deposit/api/common.py b/swh/deposit/api/common.py index 3377cc42f070cb394f5f34107ce648bdb5c1ab63..a1c9bbcac236d02d96147bdcda635b02bc40ed4f 100644 --- a/swh/deposit/api/common.py +++ b/swh/deposit/api/common.py @@ -164,9 +164,7 @@ def guess_deposit_origin_url(deposit: Deposit): class APIBase(APIConfig, APIView, metaclass=ABCMeta): - """Base deposit request class sharing multiple common behaviors. - - """ + """Base deposit request class sharing multiple common behaviors.""" _client: Optional[DepositClient] = None @@ -326,9 +324,7 @@ class APIBase(APIConfig, APIView, metaclass=ABCMeta): return deposit_request def _delete_archives(self, collection_name: str, deposit: Deposit) -> Dict: - """Delete archive references from the deposit id. - - """ + """Delete archive references from the deposit id.""" DepositRequest.objects.filter(deposit=deposit, type=ARCHIVE_TYPE).delete() return {} @@ -361,7 +357,9 @@ class APIBase(APIConfig, APIView, metaclass=ABCMeta): return {} def _check_file_length( - self, filehandler: UploadedFile, content_length: Optional[int] = None, + self, + filehandler: UploadedFile, + content_length: Optional[int] = None, ) -> None: """Check the filehandler passed as argument has exactly the expected content_length @@ -387,7 +385,9 @@ class APIBase(APIConfig, APIView, metaclass=ABCMeta): ) def _check_file_md5sum( - self, filehandler: UploadedFile, md5sum: Optional[bytes], + self, + filehandler: UploadedFile, + md5sum: Optional[bytes], ) -> None: """Check the filehandler passed as argument has the expected md5sum @@ -479,7 +479,8 @@ class APIBase(APIConfig, APIView, metaclass=ABCMeta): # actual storage of data archive_metadata = filehandler self._deposit_put( - deposit=deposit, in_progress=headers.in_progress, + deposit=deposit, + in_progress=headers.in_progress, ) self._deposit_request_put( deposit, @@ -608,7 +609,8 @@ class APIBase(APIConfig, APIView, metaclass=ABCMeta): # actual storage of data self._deposit_put( - deposit=deposit, in_progress=headers.in_progress, + deposit=deposit, + in_progress=headers.in_progress, ) deposit_request_data = { ARCHIVE_KEY: filehandler, @@ -670,7 +672,8 @@ class APIBase(APIConfig, APIView, metaclass=ABCMeta): ) metadata_authority = MetadataAuthority( - type=MetadataAuthorityType.DEPOSIT_CLIENT, url=deposit.client.provider_url, + type=MetadataAuthorityType.DEPOSIT_CLIENT, + url=deposit.client.provider_url, ) metadata_fetcher = self.swh_deposit_fetcher() @@ -840,7 +843,9 @@ class APIBase(APIConfig, APIView, metaclass=ABCMeta): swhid_ref = parse_swh_reference(metadata_tree) except ValidationError as e: raise DepositError( - PARSING_ERROR, "Invalid SWHID reference", str(e), + PARSING_ERROR, + "Invalid SWHID reference", + str(e), ) if swhid_ref is not None and ( @@ -884,7 +889,8 @@ class APIBase(APIConfig, APIView, metaclass=ABCMeta): ) self._deposit_put( - deposit=deposit, in_progress=headers.in_progress, + deposit=deposit, + in_progress=headers.in_progress, ) self._deposit_request_put( @@ -1048,9 +1054,7 @@ class APIBase(APIConfig, APIView, metaclass=ABCMeta): def restrict_access( self, request: Request, headers: ParsedRequestHeaders, deposit: Deposit ) -> None: - """Allow modifications on deposit with status 'partial' only, reject the rest. - - """ + """Allow modifications on deposit with status 'partial' only, reject the rest.""" if request.method != "GET" and deposit.status != DEPOSIT_STATUS_PARTIAL: summary = "You can only act on deposit with status '%s'" % ( DEPOSIT_STATUS_PARTIAL, @@ -1062,7 +1066,8 @@ class APIBase(APIConfig, APIView, metaclass=ABCMeta): def _basic_not_allowed_method(self, request: Request, method: str): raise DepositError( - METHOD_NOT_ALLOWED, f"{method} method is not supported on this endpoint", + METHOD_NOT_ALLOWED, + f"{method} method is not supported on this endpoint", ) def get( @@ -1081,9 +1086,7 @@ class APIBase(APIConfig, APIView, metaclass=ABCMeta): class APIGet(APIBase, metaclass=ABCMeta): - """Mixin for class to support GET method. - - """ + """Mixin for class to support GET method.""" def get( # type: ignore self, request: Request, collection_name: str, deposit_id: int @@ -1127,9 +1130,7 @@ class APIGet(APIBase, metaclass=ABCMeta): class APIPost(APIBase, metaclass=ABCMeta): - """Mixin for class to support POST method. - - """ + """Mixin for class to support POST method.""" def post( # type: ignore self, request: Request, collection_name: str, deposit_id: Optional[int] = None @@ -1153,7 +1154,11 @@ class APIPost(APIBase, metaclass=ABCMeta): ) return self._make_deposit_receipt( - request, collection_name, status, iri_key, receipt, + request, + collection_name, + status, + iri_key, + receipt, ) def _make_deposit_receipt( @@ -1210,9 +1215,7 @@ class APIPost(APIBase, metaclass=ABCMeta): class APIPut(APIBase, metaclass=ABCMeta): - """Mixin for class to support PUT method. - - """ + """Mixin for class to support PUT method.""" def put( # type: ignore self, request: Request, collection_name: str, deposit_id: int @@ -1252,9 +1255,7 @@ class APIPut(APIBase, metaclass=ABCMeta): class APIDelete(APIBase, metaclass=ABCMeta): - """Mixin for class to support DELETE method. - - """ + """Mixin for class to support DELETE method.""" def delete( # type: ignore self, request: Request, collection_name: str, deposit_id: Optional[int] = None diff --git a/swh/deposit/api/edit.py b/swh/deposit/api/edit.py index 7f22266947cac1f419df4e1c4f24291a09061f16..67e8bf85a63c618589ff0df7cab7f7fe3018dcb4 100644 --- a/swh/deposit/api/edit.py +++ b/swh/deposit/api/edit.py @@ -17,9 +17,9 @@ from .common import APIDelete, APIPut, ParsedRequestHeaders class EditAPI(APIPut, APIDelete): """Deposit request class defining api endpoints for sword deposit. - What's known as 'Edit-IRI' in the sword specification. + What's known as 'Edit-IRI' in the sword specification. - HTTP verbs supported: PUT, DELETE + HTTP verbs supported: PUT, DELETE """ @@ -136,7 +136,7 @@ class EditAPI(APIPut, APIDelete): def process_delete(self, req, collection_name: str, deposit: Deposit) -> None: """Delete the container (deposit). - source: http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_deleteconteiner # noqa + source: http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_deleteconteiner # noqa """ self._delete_deposit(collection_name, deposit) diff --git a/swh/deposit/api/edit_media.py b/swh/deposit/api/edit_media.py index 102cae4039cac54dbfe63adf567bc0139fe80dfd..b673ff759bedd410cdc498701e692009f34a08ea 100644 --- a/swh/deposit/api/edit_media.py +++ b/swh/deposit/api/edit_media.py @@ -24,9 +24,9 @@ from .common import ( class EditMediaAPI(APIPost, APIPut, APIDelete): """Deposit request class defining api endpoints for sword deposit. - What's known as 'EM IRI' in the sword specification. + What's known as 'EM IRI' in the sword specification. - HTTP verbs supported: PUT, POST, DELETE + HTTP verbs supported: PUT, POST, DELETE """ diff --git a/swh/deposit/api/private/__init__.py b/swh/deposit/api/private/__init__.py index 0adbd25cdcc0f775bf541f39afc4e19eebb3d769..acf91c024a1dd1030289690ed1bdbaa7ceb56e2a 100644 --- a/swh/deposit/api/private/__init__.py +++ b/swh/deposit/api/private/__init__.py @@ -13,9 +13,7 @@ from ...models import Deposit, DepositRequest class DepositReadMixin: - """Deposit Read mixin - - """ + """Deposit Read mixin""" def _deposit_requests(self, deposit: Deposit, request_type: str): """Given a deposit, yields its associated deposit_request @@ -54,7 +52,7 @@ class DepositReadMixin: class APIPrivateView(APIConfig, APIView): """Mixin intended as private api (so no authentication) based API view - (for the private ones). + (for the private ones). """ @@ -64,20 +62,28 @@ class APIPrivateView(APIConfig, APIView): self.permission_classes = (AllowAny,) def checks(self, req, collection_name, deposit=None): - """Override default checks implementation to allow empty collection. - - """ + """Override default checks implementation to allow empty collection.""" headers = self._read_headers(req) self.additional_checks(req, headers, collection_name, deposit) return {"headers": headers} def get( - self, request, collection_name=None, deposit_id=None, *args, **kwargs, + self, + request, + collection_name=None, + deposit_id=None, + *args, + **kwargs, ): return super().get(request, collection_name, deposit_id) def put( - self, request, collection_name=None, deposit_id=None, *args, **kwargs, + self, + request, + collection_name=None, + deposit_id=None, + *args, + **kwargs, ): return super().put(request, collection_name, deposit_id) diff --git a/swh/deposit/api/private/deposit_check.py b/swh/deposit/api/private/deposit_check.py index 90598dc85f2a0d48ba15c1a78e16fd887bd00ed7..a8807908be897886d35b3e38a963dc8a4b1bce0e 100644 --- a/swh/deposit/api/private/deposit_check.py +++ b/swh/deposit/api/private/deposit_check.py @@ -75,7 +75,13 @@ class APIChecks(APIPrivateView, APIGet, DepositReadMixin): requests = list(self._deposit_requests(deposit, request_type=ARCHIVE_TYPE)) requests.reverse() if len(requests) == 0: # no associated archive is refused - return False, {"archive": [{"summary": MANDATORY_ARCHIVE_MISSING,}]} + return False, { + "archive": [ + { + "summary": MANDATORY_ARCHIVE_MISSING, + } + ] + } errors = [] for archive_request in requests: diff --git a/swh/deposit/api/private/deposit_read.py b/swh/deposit/api/private/deposit_read.py index 40b8f0f62582e24675edbf3451af32f3d29d9ab0..fb88d9a44a93fa72c7046e241cde478e8489d6bb 100644 --- a/swh/deposit/api/private/deposit_read.py +++ b/swh/deposit/api/private/deposit_read.py @@ -102,9 +102,7 @@ class APIReadArchives(APIPrivateView, APIGet, DepositReadMixin): class APIReadMetadata(APIPrivateView, APIGet, DepositReadMixin): - """Class in charge of aggregating metadata on a deposit. - - """ + """Class in charge of aggregating metadata on a deposit.""" def _parse_dates( self, deposit: Deposit, metadata: ElementTree.Element diff --git a/swh/deposit/api/sword_edit.py b/swh/deposit/api/sword_edit.py index e038a0c5f7ebc480230511266261d759a280ffa4..1378a5c1572e9fb18ec56b4d77040b9c9e0d20a2 100644 --- a/swh/deposit/api/sword_edit.py +++ b/swh/deposit/api/sword_edit.py @@ -19,9 +19,9 @@ from .common import APIPost, ParsedRequestHeaders, Receipt class SwordEditAPI(APIPost): """Deposit request class defining api endpoints for sword deposit. - What's known as 'SE-IRI' in the sword specification. + What's known as 'SE-IRI' in the sword specification. - HTTP verbs supported: POST + HTTP verbs supported: POST """ diff --git a/swh/deposit/api/utils.py b/swh/deposit/api/utils.py index 7a9aff1b951933da738ff10482f7c741f2d24925..43c8f3707cfd96d0a1554859e73c4f803df28cb3 100644 --- a/swh/deposit/api/utils.py +++ b/swh/deposit/api/utils.py @@ -18,8 +18,8 @@ class DefaultPagination(PageNumberPagination): class StatusDetailField(_UnvalidatedField): """status_detail field is a dict, we want a simple message instead. - So, we reuse the convert_status_detail from deposit_status - endpoint to that effect. + So, we reuse the convert_status_detail from deposit_status + endpoint to that effect. """ diff --git a/swh/deposit/auth.py b/swh/deposit/auth.py index 655d05a59b9a75fd71a01ae1b50657f863a451be..f1edd20fe6c64b1e22bf90831d008d86cd406a17 100644 --- a/swh/deposit/auth.py +++ b/swh/deposit/auth.py @@ -34,16 +34,16 @@ DEPOSIT_PERMISSION = "swh.deposit.api" def convert_response(request, content): """Convert response from drf's basic authentication mechanism to a - swh-deposit one. + swh-deposit one. - Args: - request (Request): Use to build the response - content (bytes): The drf's answer + Args: + request (Request): Use to build the response + content (bytes): The drf's answer - Returns: + Returns: - Response with the same status error as before, only the - body is now an swh-deposit compliant one. + Response with the same status error as before, only the + body is now an swh-deposit compliant one. """ from json import loads @@ -66,9 +66,9 @@ def convert_response(request, content): class WrapBasicAuthenticationResponseMiddleware: """Middleware to capture potential authentication error and convert - them to standard deposit response. + them to standard deposit response. - This is to be installed in django's settings.py module. + This is to be installed in django's settings.py module. """ @@ -88,9 +88,7 @@ class WrapBasicAuthenticationResponseMiddleware: class HasDepositPermission(BasePermission): - """Allows access to authenticated users with the DEPOSIT_PERMISSION. - - """ + """Allows access to authenticated users with the DEPOSIT_PERMISSION.""" def has_permission(self, request, view): assert isinstance(request.user, DepositClient) @@ -123,15 +121,11 @@ class KeycloakBasicAuthentication(BasicAuthentication): return self._client def _cache_key(self, user_id: str) -> str: - """Internal key to use to store user id token. - - """ + """Internal key to use to store user id token.""" return f"oidc_user_{self.client.realm_name}_{self.client.client_id}_{user_id}" def get_user(self, user_id: str) -> Optional[OIDCUser]: - """Retrieve user from cache if any. - - """ + """Retrieve user from cache if any.""" oidc_profile = cache.get(self._cache_key(user_id)) if oidc_profile: try: @@ -180,7 +174,9 @@ class KeycloakBasicAuthentication(BasicAuthentication): if ttl: # cache the oidc_profile user while it's valid cache.set( - self._cache_key(user_id), oidc_profile, timeout=max(0, ttl), + self._cache_key(user_id), + oidc_profile, + timeout=max(0, ttl), ) return (deposit_client, None) diff --git a/swh/deposit/cli/__init__.py b/swh/deposit/cli/__init__.py index 0e110ce4c0b5ae3afcdd90581abfd14c17369aa3..663035c53f10933f901e476f3eff183cff065d4c 100644 --- a/swh/deposit/cli/__init__.py +++ b/swh/deposit/cli/__init__.py @@ -18,8 +18,7 @@ logger = logging.getLogger(__name__) @swh_cli_group.group(context_settings=CONTEXT_SETTINGS) @click.pass_context def deposit(ctx): - """Deposit main command - """ + """Deposit main command""" ctx.ensure_object(dict) log_level = ctx.obj.get("log_level", logging.INFO) logger.setLevel(log_level) diff --git a/swh/deposit/cli/admin.py b/swh/deposit/cli/admin.py index 2c55a99631e3033b9633365cdb3fcc227db35fad..594ca17723a6859b9ce5ec6c2d4a972685f1f73f 100644 --- a/swh/deposit/cli/admin.py +++ b/swh/deposit/cli/admin.py @@ -22,7 +22,10 @@ if TYPE_CHECKING: "--config-file", "-C", default=None, - type=click.Path(exists=True, dir_okay=False,), + type=click.Path( + exists=True, + dir_okay=False, + ), help="Optional extra configuration file.", ) @click.option( @@ -139,8 +142,8 @@ def user_create( def user_list(ctx): """List existing users. - This entrypoint is not paginated yet as there is not a lot of - entry. + This entrypoint is not paginated yet as there is not a lot of + entry. """ # to avoid loading too early django namespaces @@ -158,8 +161,7 @@ def user_list(ctx): @click.argument("username", required=True) @click.pass_context def user_exists(ctx, username: str): - """Check if user exists. - """ + """Check if user exists.""" # to avoid loading too early django namespaces from swh.deposit.models import DepositClient @@ -191,8 +193,8 @@ def collection_create(ctx, name): def collection_list(ctx): """List existing collections. - This entrypoint is not paginated yet as there is not a lot of - entry. + This entrypoint is not paginated yet as there is not a lot of + entry. """ # to avoid loading too early django namespaces diff --git a/swh/deposit/cli/client.py b/swh/deposit/cli/client.py index 7df3e7b096185ffba30b1d85375e8e5569032070..2ec34fce61b5a669466d2669b91a5596842af60c 100644 --- a/swh/deposit/cli/client.py +++ b/swh/deposit/cli/client.py @@ -30,18 +30,14 @@ if TYPE_CHECKING: class InputError(ValueError): - """Input script error - - """ + """Input script error""" pass @contextmanager def trap_and_report_exceptions(): - """Trap and report exceptions (InputError, MaintenanceError) in a unified way. - - """ + """Trap and report exceptions (InputError, MaintenanceError) in a unified way.""" from swh.deposit.client import MaintenanceError try: @@ -144,9 +140,7 @@ def generate_metadata( def _collection(client: PublicApiDepositClient) -> str: - """Retrieve the client's collection - - """ + """Retrieve the client's collection""" # retrieve user's collection sd_content = client.service_document() if "error" in sd_content: @@ -322,9 +316,7 @@ def _subdict(d: Dict[str, Any], keys: Collection[str]) -> Dict[str, Any]: def credentials_decorator(f): - """Add default --url, --username and --password flag to cli. - - """ + """Add default --url, --username and --password flag to cli.""" f = click.option( "--password", required=True, help="(Mandatory) User's associated password" )(f) @@ -341,9 +333,7 @@ def credentials_decorator(f): def output_format_decorator(f): - """Add --format output flag decorator to cli. - - """ + """Add --format output flag decorator to cli.""" return click.option( "-f", "--format", @@ -462,10 +452,10 @@ def upload( ): """Software Heritage Public Deposit Client - Create/Update deposit through the command line. + Create/Update deposit through the command line. -More documentation can be found at -https://docs.softwareheritage.org/devel/swh-deposit/getting-started.html. + More documentation can be found at + https://docs.softwareheritage.org/devel/swh-deposit/getting-started.html. """ import tempfile @@ -545,9 +535,7 @@ https://docs.softwareheritage.org/devel/swh-deposit/getting-started.html. @output_format_decorator @click.pass_context def status(ctx, url, username, password, deposit_id, output_format): - """Deposit's status - - """ + """Deposit's status""" from swh.deposit.client import PublicApiDepositClient url = _url(url) @@ -563,9 +551,7 @@ def status(ctx, url, username, password, deposit_id, output_format): def print_result(data: Dict[str, Any], output_format: Optional[str]) -> None: - """Display the result data into a dedicated output format. - - """ + """Display the result data into a dedicated output format.""" import json import yaml @@ -590,9 +576,7 @@ def print_result(data: Dict[str, Any], output_format: Optional[str]) -> None: @output_format_decorator @click.pass_context def metadata_only(ctx, url, username, password, metadata_path, output_format): - """Deposit metadata only upload - - """ + """Deposit metadata only upload""" from xml.etree import ElementTree from swh.deposit.client import PublicApiDepositClient @@ -626,16 +610,18 @@ def metadata_only(ctx, url, username, password, metadata_path, output_format): @credentials_decorator @output_format_decorator @click.option( - "--page", default=1, help="Page number when requesting more information", + "--page", + default=1, + help="Page number when requesting more information", ) @click.option( - "--page-size", default=100, help="Page number when requesting more information", + "--page-size", + default=100, + help="Page number when requesting more information", ) @click.pass_context def deposit_list(ctx, url, username, password, output_format, page, page_size): - """Client deposit listing - - """ + """Client deposit listing""" from swh.deposit.client import PublicApiDepositClient url = _url(url) diff --git a/swh/deposit/client.py b/swh/deposit/client.py index ac8fbe704d2cf69f7c97c9dcb3705737fb3db4df..7054de8e7de5e065fe489e91ae5e4784866824cf 100644 --- a/swh/deposit/client.py +++ b/swh/deposit/client.py @@ -85,9 +85,7 @@ def compute_unified_information( class MaintenanceError(ValueError): - """Informational maintenance error exception - - """ + """Informational maintenance error exception""" pass @@ -109,9 +107,7 @@ def handle_deprecated_config(config: Dict) -> Tuple[str, Optional[Tuple[str, str class BaseApiDepositClient: - """Deposit client base class - - """ + """Deposit client base class""" def __init__( self, @@ -259,9 +255,7 @@ class PrivateApiDepositClient(BaseApiDepositClient): class BaseDepositClient(BaseApiDepositClient): - """Base Deposit client to access the public api. - - """ + """Base Deposit client to access the public api.""" def __init__( self, config=None, url=None, auth=None, error_msg=None, empty_result={} @@ -282,14 +276,14 @@ class BaseDepositClient(BaseApiDepositClient): self, xml_content: str, headers: Optional[Dict] = None ) -> Dict[str, Any]: """Given an xml result from the api endpoint, parse it and returns a - dict. + dict. """ raise NotImplementedError def compute_information(self, *args, **kwargs) -> Dict[str, Any]: """Compute some more information given the inputs (e.g http headers, - ...) + ...) """ return {} @@ -347,7 +341,9 @@ class BaseDepositClient(BaseApiDepositClient): msg = self.error_msg % (url, e) result = self.empty_result result.update( - {"error": msg,} + { + "error": msg, + } ) return result else: @@ -375,15 +371,15 @@ class BaseDepositClient(BaseApiDepositClient): if summary and detail: raise MaintenanceError(f"{summary}: {detail}") error.update( - {"status": response.status_code,} + { + "status": response.status_code, + } ) return error class ServiceDocumentDepositClient(BaseDepositClient): - """Service Document information retrieval. - - """ + """Service Document information retrieval.""" def __init__(self, config=None, url=None, auth=None): super().__init__( @@ -403,9 +399,7 @@ class ServiceDocumentDepositClient(BaseDepositClient): def parse_result_ok( self, xml_content: str, headers: Optional[Dict] = None ) -> Dict[str, Any]: - """Parse service document's success response. - - """ + """Parse service document's success response.""" single_keys = [ "atom:title", "sword:collectionPolicy", @@ -449,9 +443,7 @@ class ServiceDocumentDepositClient(BaseDepositClient): class StatusDepositClient(BaseDepositClient): - """Status information on a deposit. - - """ + """Status information on a deposit.""" def __init__(self, config=None, url=None, auth=None): super().__init__( @@ -475,9 +467,7 @@ class StatusDepositClient(BaseDepositClient): def parse_result_ok( self, xml_content: str, headers: Optional[Dict] = None ) -> Dict[str, Any]: - """Given an xml content as string, returns a deposit dict. - - """ + """Given an xml content as string, returns a deposit dict.""" data = ElementTree.fromstring(xml_content) keys = [ "deposit_id", @@ -491,9 +481,7 @@ class StatusDepositClient(BaseDepositClient): class CollectionListDepositClient(BaseDepositClient): - """List a collection of deposits (owned by a user) - - """ + """List a collection of deposits (owned by a user)""" def __init__(self, config=None, url=None, auth=None): super().__init__( @@ -520,9 +508,7 @@ class CollectionListDepositClient(BaseDepositClient): def parse_result_ok( self, xml_content: str, headers: Optional[Dict] = None ) -> Dict[str, Any]: - """Given an xml content as string, returns a deposit dict. - - """ + """Given an xml content as string, returns a deposit dict.""" link_header = headers.get("Link", "") if headers else "" links = parse_header_links(link_header) data = ElementTree.fromstring(xml_content) @@ -556,9 +542,7 @@ class CollectionListDepositClient(BaseDepositClient): class BaseCreateDepositClient(BaseDepositClient): - """Deposit client base class to post new deposit. - - """ + """Deposit client base class to post new deposit.""" def __init__(self, config=None, url=None, auth=None): super().__init__( @@ -566,7 +550,10 @@ class BaseCreateDepositClient(BaseDepositClient): auth=auth, config=config, error_msg="Post Deposit failure at %s: %s", - empty_result={"swh:deposit_id": None, "swh:deposit_status": None,}, + empty_result={ + "swh:deposit_id": None, + "swh:deposit_status": None, + }, ) def compute_url(self, collection, *args, **kwargs): @@ -578,9 +565,7 @@ class BaseCreateDepositClient(BaseDepositClient): def parse_result_ok( self, xml_content: str, headers: Optional[Dict] = None ) -> Dict[str, Any]: - """Given an xml content as string, returns a deposit dict. - - """ + """Given an xml content as string, returns a deposit dict.""" data = ElementTree.fromstring(xml_content) keys = [ "deposit_id", @@ -681,16 +666,16 @@ class CreateMetadataOnlyDepositClient(BaseCreateDepositClient): def compute_information(self, *args, **kwargs) -> Dict[str, Any]: return { - "headers": {"CONTENT-TYPE": "application/atom+xml;type=entry",}, + "headers": { + "CONTENT-TYPE": "application/atom+xml;type=entry", + }, "filepath": kwargs["metadata_path"], } def parse_result_ok( self, xml_content: str, headers: Optional[Dict] = None ) -> Dict[str, Any]: - """Given an xml content as string, returns a deposit dict. - - """ + """Given an xml content as string, returns a deposit dict.""" data = ElementTree.fromstring(xml_content) keys = [ "deposit_id", @@ -729,9 +714,13 @@ class CreateMultipartDepositClient(BaseCreateDepositClient): return files, headers def compute_information(self, *args, **kwargs) -> Dict[str, Any]: - info = compute_unified_information(*args, filepath=kwargs["archive_path"],) + info = compute_unified_information( + *args, + filepath=kwargs["archive_path"], + ) info_meta = compute_unified_information( - *args, filepath=kwargs["metadata_path"], + *args, + filepath=kwargs["metadata_path"], ) files, headers = self._multipart_info(info, info_meta) return {"files": files, "headers": headers} @@ -884,7 +873,9 @@ class PublicApiDepositClient(BaseApiDepositClient): return self.deposit_status(collection, deposit_id) def deposit_metadata_only( - self, collection: str, metadata: Optional[str] = None, + self, + collection: str, + metadata: Optional[str] = None, ): assert metadata is not None return CreateMetadataOnlyDepositClient( diff --git a/swh/deposit/config.py b/swh/deposit/config.py index 758ecf091e6098b8dbe3aec6a837fad581824a9a..e3bba9ff93e2bd0990d1bf160efedf35ba8e81c1 100644 --- a/swh/deposit/config.py +++ b/swh/deposit/config.py @@ -110,8 +110,12 @@ class APIConfig: def swh_deposit_authority(self): return MetadataAuthority( - type=MetadataAuthorityType.REGISTRY, url=self.config["swh_authority_url"], + type=MetadataAuthorityType.REGISTRY, + url=self.config["swh_authority_url"], ) def swh_deposit_fetcher(self): - return MetadataFetcher(name=self.tool["name"], version=self.tool["version"],) + return MetadataFetcher( + name=self.tool["name"], + version=self.tool["version"], + ) diff --git a/swh/deposit/errors.py b/swh/deposit/errors.py index ca8385acb75e2fc4e4db6f2e10ba70ff785dc91d..568d1d8b8ec545efe49aafecb9cc0779be9f8142 100644 --- a/swh/deposit/errors.py +++ b/swh/deposit/errors.py @@ -28,9 +28,7 @@ logger = logging.getLogger(__name__) class ParserError(ValueError): - """Specific parsing error detected when parsing the xml metadata input - - """ + """Specific parsing error detected when parsing the xml metadata input""" pass @@ -156,9 +154,7 @@ def make_error_response(req, key, summary=None, verbose_description=None): class DepositError(ValueError): - """Represents an error that should be reported to the client - - """ + """Represents an error that should be reported to the client""" def __init__(self, key, summary, verbose_description=None): self.key = key diff --git a/swh/deposit/exception.py b/swh/deposit/exception.py index 5c6a224a15ad91d72e872067d06d506e32ec3606..de56ed054b5474d850501d4ab034baf81732dc92 100644 --- a/swh/deposit/exception.py +++ b/swh/deposit/exception.py @@ -13,9 +13,7 @@ from rest_framework.exceptions import APIException def custom_exception_handler( exc: APIException, context: Dict ) -> Optional[HttpResponse]: - """Custom deposit exception handler to ensure consistent xml output - - """ + """Custom deposit exception handler to ensure consistent xml output""" from rest_framework.views import exception_handler # drf's default exception handler first, to get the standard error response diff --git a/swh/deposit/migrations/0001_initial.py b/swh/deposit/migrations/0001_initial.py index bc91890a7cb690df011aa219c114b4865b18596f..e62bed925e908f9136d0dcfeb819e6a68a2b80ef 100644 --- a/swh/deposit/migrations/0001_initial.py +++ b/swh/deposit/migrations/0001_initial.py @@ -30,7 +30,9 @@ class Migration(migrations.Migration): ), ("description", models.TextField(blank=True, null=True)), ], - options={"db_table": "dbversion",}, + options={ + "db_table": "dbversion", + }, ), migrations.CreateModel( name="Deposit", @@ -55,7 +57,9 @@ class Migration(migrations.Migration): ), ), ], - options={"db_table": "deposit",}, + options={ + "db_table": "deposit", + }, ), migrations.CreateModel( name="DepositClient", @@ -78,9 +82,13 @@ class Migration(migrations.Migration): ), ), ], - options={"db_table": "deposit_client",}, + options={ + "db_table": "deposit_client", + }, bases=("auth.user",), - managers=[("objects", django.contrib.auth.models.UserManager()),], + managers=[ + ("objects", django.contrib.auth.models.UserManager()), + ], ), migrations.CreateModel( name="DepositCollection", @@ -88,7 +96,9 @@ class Migration(migrations.Migration): ("id", models.BigAutoField(primary_key=True, serialize=False)), ("name", models.TextField()), ], - options={"db_table": "deposit_collection",}, + options={ + "db_table": "deposit_collection", + }, ), migrations.CreateModel( name="DepositRequest", @@ -104,7 +114,9 @@ class Migration(migrations.Migration): ), ), ], - options={"db_table": "deposit_request",}, + options={ + "db_table": "deposit_request", + }, ), migrations.CreateModel( name="DepositRequestType", @@ -112,7 +124,9 @@ class Migration(migrations.Migration): ("id", models.BigAutoField(primary_key=True, serialize=False)), ("name", models.TextField()), ], - options={"db_table": "deposit_request_type",}, + options={ + "db_table": "deposit_request_type", + }, ), migrations.AddField( model_name="depositrequest", diff --git a/swh/deposit/migrations/0003_temporaryarchive.py b/swh/deposit/migrations/0003_temporaryarchive.py index 737fb2b689eb08b76c06e9837140769c2f513f14..a2ac83950f5831edba02d83d74682ae5c6db9686 100644 --- a/swh/deposit/migrations/0003_temporaryarchive.py +++ b/swh/deposit/migrations/0003_temporaryarchive.py @@ -19,6 +19,8 @@ class Migration(migrations.Migration): ("path", models.TextField()), ("date", models.DateTimeField(auto_now_add=True)), ], - options={"db_table": "deposit_temporary_archive",}, + options={ + "db_table": "deposit_temporary_archive", + }, ), ] diff --git a/swh/deposit/migrations/0004_delete_temporaryarchive.py b/swh/deposit/migrations/0004_delete_temporaryarchive.py index 8c995aeabd1f7259a47e26948da8b71f2e245e28..d30b92114132131041d4a219fc54ffdf03900e80 100644 --- a/swh/deposit/migrations/0004_delete_temporaryarchive.py +++ b/swh/deposit/migrations/0004_delete_temporaryarchive.py @@ -12,5 +12,7 @@ class Migration(migrations.Migration): ] operations = [ - migrations.DeleteModel(name="TemporaryArchive",), + migrations.DeleteModel( + name="TemporaryArchive", + ), ] diff --git a/swh/deposit/migrations/0007_auto_20171129_1609.py b/swh/deposit/migrations/0007_auto_20171129_1609.py index ee2f158aa00299ab5895d076f6556fb991aea9bf..0db3703c841b45de9311e37e5e11435abdd382f5 100644 --- a/swh/deposit/migrations/0007_auto_20171129_1609.py +++ b/swh/deposit/migrations/0007_auto_20171129_1609.py @@ -13,6 +13,8 @@ class Migration(migrations.Migration): operations = [ migrations.AlterField( - model_name="depositclient", name="url", field=models.TextField(null=False), + model_name="depositclient", + name="url", + field=models.TextField(null=False), ), ] diff --git a/swh/deposit/migrations/0010_auto_20180110_0953.py b/swh/deposit/migrations/0010_auto_20180110_0953.py index 469208ed9f8db5741e0d0fda50a3f3fb7c335109..9df2b0c5acd76bf2b0ca3a5b7c9710c6a6a9f2f1 100644 --- a/swh/deposit/migrations/0010_auto_20180110_0953.py +++ b/swh/deposit/migrations/0010_auto_20180110_0953.py @@ -13,7 +13,9 @@ class Migration(migrations.Migration): operations = [ migrations.RenameField( - model_name="depositclient", old_name="url", new_name="provider_url", + model_name="depositclient", + old_name="url", + new_name="provider_url", ), migrations.AddField( model_name="depositclient", diff --git a/swh/deposit/migrations/0015_depositrequest_typemigration.py b/swh/deposit/migrations/0015_depositrequest_typemigration.py index a99742879529f8b799da8fe47daf85a5ccf3a899..f9748109ed44bde615d2160ffbecb647a4491eb4 100644 --- a/swh/deposit/migrations/0015_depositrequest_typemigration.py +++ b/swh/deposit/migrations/0015_depositrequest_typemigration.py @@ -32,9 +32,16 @@ class Migration(migrations.Migration): ), ), migrations.RunPython(populate_deposit_type2), - migrations.RemoveField(model_name="depositrequest", name="type",), + migrations.RemoveField( + model_name="depositrequest", + name="type", + ), migrations.RenameField( - model_name="depositrequest", old_name="type2", new_name="type", + model_name="depositrequest", + old_name="type2", + new_name="type", + ), + migrations.DeleteModel( + name="DepositRequestType", ), - migrations.DeleteModel(name="DepositRequestType",), ] diff --git a/swh/deposit/migrations/0018_migrate_swhids.py b/swh/deposit/migrations/0018_migrate_swhids.py index d58358246625cabcdf83217e113adcbe28b87793..b9bb2e57cdffa6d899dc891610a7481d5f812c50 100644 --- a/swh/deposit/migrations/0018_migrate_swhids.py +++ b/swh/deposit/migrations/0018_migrate_swhids.py @@ -29,9 +29,7 @@ swh_storage = None def get_storage() -> Optional[Any]: - """Instantiate a storage client - - """ + """Instantiate a storage client""" settings = os.environ.get("DJANGO_SETTINGS_MODULE") if settings != "swh.deposit.settings.production": # Bypass for now return None diff --git a/swh/deposit/migrations/0019_auto_20200519_1035.py b/swh/deposit/migrations/0019_auto_20200519_1035.py index f54ee98de29b20d1249fe96065611fd4fa899332..f1e0911b54112accc0a5a1ab8f17abefa84ac861 100644 --- a/swh/deposit/migrations/0019_auto_20200519_1035.py +++ b/swh/deposit/migrations/0019_auto_20200519_1035.py @@ -12,6 +12,12 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RemoveField(model_name="deposit", name="swh_anchor_id",), - migrations.RemoveField(model_name="deposit", name="swh_anchor_id_context",), + migrations.RemoveField( + model_name="deposit", + name="swh_anchor_id", + ), + migrations.RemoveField( + model_name="deposit", + name="swh_anchor_id_context", + ), ] diff --git a/swh/deposit/migrations/0020_auto_20200929_0855.py b/swh/deposit/migrations/0020_auto_20200929_0855.py index 2ec6cef2be65674cc2fb6714672b2ceb9e554415..dafeb8c8da5fd4cc07cf0bd332a7078659111624 100644 --- a/swh/deposit/migrations/0020_auto_20200929_0855.py +++ b/swh/deposit/migrations/0020_auto_20200929_0855.py @@ -13,9 +13,13 @@ class Migration(migrations.Migration): operations = [ migrations.RenameField( - model_name="deposit", old_name="swh_id", new_name="swhid", + model_name="deposit", + old_name="swh_id", + new_name="swhid", ), migrations.RenameField( - model_name="deposit", old_name="swh_id_context", new_name="swhid_context", + model_name="deposit", + old_name="swh_id_context", + new_name="swhid_context", ), ] diff --git a/swh/deposit/migrations/0021_deposit_origin_url_20201124_1438.py b/swh/deposit/migrations/0021_deposit_origin_url_20201124_1438.py index 399a9bf1ab6e90a2bd0645a018ac077879e87a2c..326a407bdc02d2d42ac469728a641fab4b7fd10d 100644 --- a/swh/deposit/migrations/0021_deposit_origin_url_20201124_1438.py +++ b/swh/deposit/migrations/0021_deposit_origin_url_20201124_1438.py @@ -19,10 +19,14 @@ class Migration(migrations.Migration): operations = [ migrations.AddField( - model_name="deposit", name="origin_url", field=models.TextField(null=True), + model_name="deposit", + name="origin_url", + field=models.TextField(null=True), ), # migrations.RunPython(fill_origin_url), migrations.AlterField( - model_name="deposit", name="external_id", field=models.TextField(null=True), + model_name="deposit", + name="external_id", + field=models.TextField(null=True), ), ] diff --git a/swh/deposit/migrations/0022_auto_20220223_1542.py b/swh/deposit/migrations/0022_auto_20220223_1542.py index 70bf4e5fc0499d797447625511da24af54136d60..f78c42ed74ca68cbe6e099cea64914d93dc1b49a 100644 --- a/swh/deposit/migrations/0022_auto_20220223_1542.py +++ b/swh/deposit/migrations/0022_auto_20220223_1542.py @@ -47,12 +47,15 @@ class Migration(migrations.Migration): model_name="deposit", name="type", field=models.CharField( - choices=DEPOSIT_TYPES, default=DEPOSIT_CODE, max_length=4, + choices=DEPOSIT_TYPES, + default=DEPOSIT_CODE, + max_length=4, ), preserve_default=False, ), # Migrate and make the operations possibly reversible migrations.RunPython( - fill_deposit_type, reverse_code=migrations.RunPython.noop, + fill_deposit_type, + reverse_code=migrations.RunPython.noop, ), ] diff --git a/swh/deposit/models.py b/swh/deposit/models.py index 3d8702d47fe552798f94b0d65492e892a2e9305e..af3574057699f27070d537e55265494069ca730f 100644 --- a/swh/deposit/models.py +++ b/swh/deposit/models.py @@ -30,9 +30,7 @@ from .config import ( class Dbversion(models.Model): - """Db version - - """ + """Db version""" version = models.IntegerField(primary_key=True) release = models.DateTimeField(default=now, null=True) @@ -85,9 +83,7 @@ DEPOSIT_STATUS_DETAIL = { class DepositClient(User): - """Deposit client - - """ + """Deposit client""" collections = ArrayField(models.IntegerField(), null=True) objects = UserManager() # type: ignore @@ -124,9 +120,7 @@ DEPOSIT_TYPES = [ class Deposit(models.Model): - """Deposit reception table - - """ + """Deposit reception table""" id = models.BigAutoField(primary_key=True) @@ -214,9 +208,7 @@ REQUEST_TYPES = [(ARCHIVE_TYPE, ARCHIVE_TYPE), (METADATA_TYPE, METADATA_TYPE)] class DepositRequest(models.Model): - """Deposit request associated to one deposit. - - """ + """Deposit request associated to one deposit.""" id = models.BigAutoField(primary_key=True) # Deposit concerned by the request diff --git a/swh/deposit/parsers.py b/swh/deposit/parsers.py index 5dfc4795eaf1cb5748003160e7ae82d41baf98e2..5b68179ce4b7703dd9a194812c70a9d9595af9df 100644 --- a/swh/deposit/parsers.py +++ b/swh/deposit/parsers.py @@ -20,17 +20,13 @@ logger = logging.getLogger(__name__) class SWHFileUploadZipParser(FileUploadParser): - """File upload parser limited to zip archive. - - """ + """File upload parser limited to zip archive.""" media_type = "application/zip" class SWHFileUploadTarParser(FileUploadParser): - """File upload parser limited to tarball (tar, tar.gz, tar.*) archives. - - """ + """File upload parser limited to tarball (tar, tar.gz, tar.*) archives.""" media_type = "application/x-tar" @@ -53,9 +49,7 @@ class SWHXMLParser(BaseParser): class SWHAtomEntryParser(SWHXMLParser): - """Atom entry parser limited to specific mediatype - - """ + """Atom entry parser limited to specific mediatype""" media_type = "application/atom+xml;type=entry" @@ -68,9 +62,7 @@ class SWHAtomEntryParser(SWHXMLParser): class SWHMultiPartParser(MultiPartParser): - """Multipart parser limited to a subset of mediatypes. - - """ + """Multipart parser limited to a subset of mediatypes.""" media_type = "multipart/*; *" diff --git a/swh/deposit/settings/common.py b/swh/deposit/settings/common.py index 38e26d79d1653ce1f78e830661ee79e28619e9a0..5a85b99de2436da3aeb30ea4e145f27397fdd890 100644 --- a/swh/deposit/settings/common.py +++ b/swh/deposit/settings/common.py @@ -77,9 +77,15 @@ AUTH_PASSWORD_VALIDATORS = [ { "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", # noqa }, - {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",}, - {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",}, - {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",}, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, ] @@ -111,4 +117,8 @@ FILE_UPLOAD_HANDLERS = [ "django.core.files.uploadhandler.TemporaryFileUploadHandler", ] -CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache",}} +CACHES = { + "default": { + "BACKEND": "django.core.cache.backends.locmem.LocMemCache", + } +} diff --git a/swh/deposit/settings/development.py b/swh/deposit/settings/development.py index 8667055897e3e06fa5bef73f8f0acbaafc5d8171..f7a63e9c95b08e221fdbc3b402b2377f0fdc367d 100644 --- a/swh/deposit/settings/development.py +++ b/swh/deposit/settings/development.py @@ -29,13 +29,20 @@ LOGGING = { }, }, "loggers": { - "django": {"handlers": ["console"], "level": "DEBUG", "propagate": True,}, + "django": { + "handlers": ["console"], + "level": "DEBUG", + "propagate": True, + }, "django.db.backends": { "handlers": ["console"], "level": "INFO", "propagate": False, }, - "swh.deposit": {"handlers": ["console"], "level": "DEBUG",}, + "swh.deposit": { + "handlers": ["console"], + "level": "DEBUG", + }, }, } diff --git a/swh/deposit/settings/testing.py b/swh/deposit/settings/testing.py index ea67376c607d94f6603010c8fd3a008a8e50bf2e..10e683f22f455966953ff92cb0749144f624fc06 100644 --- a/swh/deposit/settings/testing.py +++ b/swh/deposit/settings/testing.py @@ -30,7 +30,12 @@ LOGGING = { "formatter": "standard", }, }, - "loggers": {"swh.deposit": {"handlers": ["console"], "level": "ERROR",},}, + "loggers": { + "swh.deposit": { + "handlers": ["console"], + "level": "ERROR", + }, + }, } # https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-MEDIA_ROOT diff --git a/swh/deposit/tests/api/conftest.py b/swh/deposit/tests/api/conftest.py index 6dbcfe8fdc5ae861aedb6aba02ffd75a0e02547e..d9c676f3edc6795d330c55075426885830bb8800 100644 --- a/swh/deposit/tests/api/conftest.py +++ b/swh/deposit/tests/api/conftest.py @@ -28,9 +28,7 @@ def datadir(request): @pytest.fixture def ready_deposit_ok(partial_deposit_with_metadata): - """Returns a deposit ready for checks (it will pass the checks). - - """ + """Returns a deposit ready for checks (it will pass the checks).""" deposit = partial_deposit_with_metadata deposit.status = DEPOSIT_STATUS_DEPOSITED deposit.save() @@ -39,9 +37,7 @@ def ready_deposit_ok(partial_deposit_with_metadata): @pytest.fixture def ready_deposit_verified(partial_deposit_with_metadata): - """Returns a deposit ready for checks (it will pass the checks). - - """ + """Returns a deposit ready for checks (it will pass the checks).""" deposit = partial_deposit_with_metadata deposit.status = DEPOSIT_STATUS_VERIFIED deposit.save() @@ -51,7 +47,7 @@ def ready_deposit_verified(partial_deposit_with_metadata): @pytest.fixture def ready_deposit_only_metadata(partial_deposit_only_metadata): """Deposit in status ready that will fail the checks (because missing - archive). + archive). """ deposit = partial_deposit_only_metadata diff --git a/swh/deposit/tests/api/test_basic_auth.py b/swh/deposit/tests/api/test_basic_auth.py index fe21499420439a416f30b330e55cfacf7be35cd5..c5ca171c1d47d1e0194f3dc69061a1730d7453a4 100644 --- a/swh/deposit/tests/api/test_basic_auth.py +++ b/swh/deposit/tests/api/test_basic_auth.py @@ -24,9 +24,7 @@ def deposit_config(common_deposit_config): def test_service_document_basic(basic_authenticated_client): - """With authentication, service document list user's collection - - """ + """With authentication, service document list user's collection""" url = reverse(SD_IRI) response = basic_authenticated_client.get(url) check_response(response, basic_authenticated_client.deposit_client.username) diff --git a/swh/deposit/tests/api/test_checks.py b/swh/deposit/tests/api/test_checks.py index e3e557044ae69b89fc4e9ebf3f49fc36a39bc6a6..b287d3580db4e71163530df59c3decde422cd547 100644 --- a/swh/deposit/tests/api/test_checks.py +++ b/swh/deposit/tests/api/test_checks.py @@ -404,7 +404,8 @@ _parameters1 = [ @pytest.mark.parametrize( - "metadata_ok", _parameters1, + "metadata_ok", + _parameters1, ) def test_api_checks_check_metadata_ok(metadata_ok, swh_checks_deposit): actual_check, detail = check_metadata(ElementTree.fromstring(metadata_ok)) diff --git a/swh/deposit/tests/api/test_collection.py b/swh/deposit/tests/api/test_collection.py index ade4e7cd2c090ecb5ec343233fabc9973478df29..a434009557fdc9146859b13d2ffdcf9e7d7907d4 100644 --- a/swh/deposit/tests/api/test_collection.py +++ b/swh/deposit/tests/api/test_collection.py @@ -14,9 +14,7 @@ from swh.deposit.parsers import parse_xml def test_deposit_post_will_fail_with_401(unauthorized_client): - """Without authentication, endpoint refuses access with 401 response - - """ + """Without authentication, endpoint refuses access with 401 response""" url = reverse(COL_IRI, args=["hal"]) response = unauthorized_client.post(url) assert response.status_code == status.HTTP_401_UNAUTHORIZED @@ -33,21 +31,20 @@ def test_deposit_post_insufficient_permission(insufficient_perm_client): def test_access_to_another_user_collection_is_forbidden( authenticated_client, deposit_another_collection, deposit_user ): - """Access to another user collection should return a 403 - - """ + """Access to another user collection should return a 403""" coll2 = deposit_another_collection url = reverse(COL_IRI, args=[coll2.name]) response = authenticated_client.post(url) assert response.status_code == status.HTTP_403_FORBIDDEN - msg = "Client %s cannot access collection %s" % (deposit_user.username, coll2.name,) + msg = "Client %s cannot access collection %s" % ( + deposit_user.username, + coll2.name, + ) assert msg in response.content.decode("utf-8") def test_put_on_col_iri_not_supported(authenticated_client, deposit_collection): - """Delete on col iri should return a 405 response - - """ + """Delete on col iri should return a 405 response""" url = reverse(COL_IRI, args=[deposit_collection.name]) response = authenticated_client.put(url) assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED @@ -57,9 +54,7 @@ def test_put_on_col_iri_not_supported(authenticated_client, deposit_collection): def test_delete_on_col_iri_not_supported(authenticated_client, deposit_collection): - """Delete on col iri should return a 405 response - - """ + """Delete on col iri should return a 405 response""" url = reverse(COL_IRI, args=[deposit_collection.name]) response = authenticated_client.delete(url) assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED diff --git a/swh/deposit/tests/api/test_collection_add_to_origin.py b/swh/deposit/tests/api/test_collection_add_to_origin.py index 8f3f02e3c14ce850fa0bba9398e0f26fe99ec08e..666bedc676fbc6d4954739f8944b868608f76b28 100644 --- a/swh/deposit/tests/api/test_collection_add_to_origin.py +++ b/swh/deposit/tests/api/test_collection_add_to_origin.py @@ -22,9 +22,7 @@ def test_add_deposit_with_add_to_origin( atom_dataset, deposit_user, ): - """Posting deposit with <swh:add_to_origin> creates a new deposit with parent - - """ + """Posting deposit with <swh:add_to_origin> creates a new deposit with parent""" # given multiple deposit already loaded deposit = completed_deposit assert deposit.status == DEPOSIT_STATUS_LOAD_SUCCESS @@ -89,7 +87,10 @@ def test_add_deposit_add_to_origin_conflict( def test_add_deposit_add_to_wrong_origin( - authenticated_client, deposit_collection, atom_dataset, sample_archive, + authenticated_client, + deposit_collection, + atom_dataset, + sample_archive, ): """Posting a deposit with an <swh:add_to_origin> referencing an origin not starting with the provider_url raises an error @@ -115,9 +116,7 @@ def test_add_deposit_with_add_to_origin_and_external_identifier( atom_dataset, deposit_user, ): - """Posting deposit with <swh:add_to_origin> creates a new deposit with parent - - """ + """Posting deposit with <swh:add_to_origin> creates a new deposit with parent""" # given multiple deposit already loaded origin_url = deposit_user.provider_url + completed_deposit.external_id @@ -137,9 +136,7 @@ def test_add_deposit_with_add_to_origin_and_external_identifier( def test_post_deposit_atom_403_add_to_wrong_origin_url_prefix( authenticated_client, deposit_collection, atom_dataset, deposit_user ): - """Creating an origin for a prefix not owned by the client is forbidden - - """ + """Creating an origin for a prefix not owned by the client is forbidden""" origin_url = "http://example.org/foo" response = post_atom( diff --git a/swh/deposit/tests/api/test_collection_list.py b/swh/deposit/tests/api/test_collection_list.py index c92b10940ee6f4a6940079ac67a7c8f826a08df2..c6395008517071897ceec5696fe889d222addbb4 100644 --- a/swh/deposit/tests/api/test_collection_list.py +++ b/swh/deposit/tests/api/test_collection_list.py @@ -14,9 +14,7 @@ from swh.deposit.utils import NAMESPACES def test_deposit_collection_list_is_auth_protected(anonymous_client): - """Deposit list should require authentication - - """ + """Deposit list should require authentication""" url = reverse(COL_IRI, args=("test",)) response = anonymous_client.get(url) assert response.status_code == status.HTTP_401_UNAUTHORIZED @@ -26,9 +24,7 @@ def test_deposit_collection_list_is_auth_protected(anonymous_client): def test_deposit_collection_list_collection_access_restricted_to_user_coll( deposit_another_collection, deposit_user, authenticated_client ): - """Deposit list api should restrict access to user's collection - - """ + """Deposit list api should restrict access to user's collection""" collection_id = authenticated_client.deposit_client.collections[0] coll = DepositCollection.objects.get(pk=collection_id) # authenticated_client has access to the "coll" collection @@ -46,9 +42,7 @@ def test_deposit_collection_list_collection_access_restricted_to_user_coll( def test_deposit_collection_list_nominal( partial_deposit, deposited_deposit, authenticated_client ): - """Deposit list api should return the user deposits in a paginated way - - """ + """Deposit list api should return the user deposits in a paginated way""" client_id = authenticated_client.deposit_client.id assert partial_deposit.client.id == client_id assert deposited_deposit.client.id == client_id diff --git a/swh/deposit/tests/api/test_collection_post_atom.py b/swh/deposit/tests/api/test_collection_post_atom.py index ae2f795327a11c5d7746131a16e1b396b53fd3f8..a613b4ec40692551eafc2ff25c0342c2642bdc64 100644 --- a/swh/deposit/tests/api/test_collection_post_atom.py +++ b/swh/deposit/tests/api/test_collection_post_atom.py @@ -75,7 +75,8 @@ def _assert_deposit_info_on_metadata( swh_storage, metadata_swhid, deposit, metadata_fetcher ): swh_authority = MetadataAuthority( - MetadataAuthorityType.REGISTRY, "http://deposit.softwareheritage.example/", + MetadataAuthorityType.REGISTRY, + "http://deposit.softwareheritage.example/", ) page_results = swh_storage.raw_extrinsic_metadata_get(metadata_swhid, swh_authority) @@ -109,9 +110,7 @@ def _assert_deposit_info_on_metadata( def test_post_deposit_atom_201_even_with_decimal( authenticated_client, deposit_collection, atom_dataset ): - """Posting an initial atom entry should return 201 with deposit receipt - - """ + """Posting an initial atom entry should return 201 with deposit receipt""" atom_error_with_decimal = atom_dataset["error-with-decimal"] response = post_atom( @@ -141,9 +140,7 @@ def test_post_deposit_atom_201_even_with_decimal( def test_post_deposit_atom_400_with_empty_body( authenticated_client, deposit_collection, atom_dataset ): - """Posting empty body request should return a 400 response - - """ + """Posting empty body request should return a 400 response""" atom_content = atom_dataset["entry-data-empty-body"] response = post_atom( authenticated_client, @@ -160,9 +157,7 @@ def test_post_deposit_atom_400_with_empty_body( def test_post_deposit_atom_400_with_empty_request( authenticated_client, deposit_collection ): - """Posting empty request should return a 400 response - - """ + """Posting empty request should return a 400 response""" response = post_atom( authenticated_client, reverse(COL_IRI, args=[deposit_collection.name]), @@ -177,9 +172,7 @@ def test_post_deposit_atom_400_with_empty_request( def test_post_deposit_atom_400_badly_formatted_atom( authenticated_client, deposit_collection, atom_dataset ): - """Posting a badly formatted atom should return a 400 response - - """ + """Posting a badly formatted atom should return a 400 response""" response = post_atom( authenticated_client, reverse(COL_IRI, args=[deposit_collection.name]), @@ -193,9 +186,7 @@ def test_post_deposit_atom_400_badly_formatted_atom( def test_post_deposit_atom_parsing_error( authenticated_client, deposit_collection, atom_dataset ): - """Posting parsing error prone atom should return 400 - - """ + """Posting parsing error prone atom should return 400""" response = post_atom( authenticated_client, reverse(COL_IRI, args=[deposit_collection.name]), @@ -209,9 +200,7 @@ def test_post_deposit_atom_parsing_error( def test_post_deposit_atom_400_both_create_origin_and_add_to_origin( authenticated_client, deposit_collection, atom_dataset ): - """Posting a badly formatted atom should return a 400 response - - """ + """Posting a badly formatted atom should return a 400 response""" response = post_atom( authenticated_client, reverse(COL_IRI, args=[deposit_collection.name]), @@ -227,9 +216,7 @@ def test_post_deposit_atom_400_both_create_origin_and_add_to_origin( def test_post_deposit_atom_403_create_wrong_origin_url_prefix( authenticated_client, deposit_collection, atom_dataset, deposit_user ): - """Creating an origin for a prefix not owned by the client is forbidden - - """ + """Creating an origin for a prefix not owned by the client is forbidden""" origin_url = "http://example.org/foo" response = post_atom( @@ -275,9 +262,7 @@ def test_post_deposit_atom_use_slug_header( def test_post_deposit_atom_no_origin_url_nor_slug_header( authenticated_client, deposit_collection, deposit_user, atom_dataset, mocker ): - """Posting an atom entry without an origin url or a slug header should generate one - - """ + """Posting an atom entry without an origin url or a slug header should generate one""" url = reverse(COL_IRI, args=[deposit_collection.name]) slug = str(uuid.uuid4()) @@ -369,12 +354,16 @@ def test_post_deposit_atom_with_create_origin_and_external_identifier( url = reverse(COL_IRI, args=[deposit_collection.name]) document = atom_dataset["error-with-external-identifier-and-create-origin"].format( - external_id=external_id, url=origin_url, + external_id=external_id, + url=origin_url, ) # when response = post_atom( - authenticated_client, url, data=document, HTTP_IN_PROGRESS="false", + authenticated_client, + url, + data=document, + HTTP_IN_PROGRESS="false", ) assert b"<external_identifier> is deprecated" in response.content @@ -384,20 +373,22 @@ def test_post_deposit_atom_with_create_origin_and_external_identifier( def test_post_deposit_atom_with_create_origin_and_reference( authenticated_client, deposit_collection, atom_dataset, deposit_user ): - """<swh:reference> and <swh:create_origin> are mutually exclusive - - """ + """<swh:reference> and <swh:create_origin> are mutually exclusive""" external_id = "foobar" origin_url = deposit_user.provider_url + external_id url = reverse(COL_IRI, args=[deposit_collection.name]) document = atom_dataset["error-with-reference-and-create-origin"].format( - external_id=external_id, url=origin_url, + external_id=external_id, + url=origin_url, ) # when response = post_atom( - authenticated_client, url, data=document, HTTP_IN_PROGRESS="false", + authenticated_client, + url, + data=document, + HTTP_IN_PROGRESS="false", ) assert b"only one may be used on a given deposit" in response.content @@ -405,9 +396,7 @@ def test_post_deposit_atom_with_create_origin_and_reference( def test_post_deposit_atom_unknown_collection(authenticated_client, atom_dataset): - """Posting an atom entry to an unknown collection should return a 404 - - """ + """Posting an atom entry to an unknown collection should return a 404""" unknown_collection = "unknown-one" with pytest.raises(DepositCollection.DoesNotExist): DepositCollection.objects.get(name=unknown_collection) @@ -425,9 +414,7 @@ def test_post_deposit_atom_unknown_collection(authenticated_client, atom_dataset def test_post_deposit_atom_entry_initial( authenticated_client, deposit_collection, atom_dataset, deposit_user ): - """Posting an initial atom entry should return 201 with deposit receipt - - """ + """Posting an initial atom entry should return 201 with deposit receipt""" # given origin_url = deposit_user.provider_url + "1225c695-cfb8-4ebb-aaaa-80da344efa6a" @@ -473,9 +460,7 @@ def test_post_deposit_atom_entry_initial( def test_post_deposit_atom_entry_with_codemeta( authenticated_client, deposit_collection, atom_dataset, deposit_user ): - """Posting an initial atom entry should return 201 with deposit receipt - - """ + """Posting an initial atom entry should return 201 with deposit receipt""" # given origin_url = deposit_user.provider_url + "1225c695-cfb8-4ebb-aaaa-80da344efa6a" @@ -512,9 +497,7 @@ def test_post_deposit_atom_entry_with_codemeta( def test_deposit_metadata_invalid( authenticated_client, deposit_collection, atom_dataset ): - """Posting invalid swhid reference is bad request returned to client - - """ + """Posting invalid swhid reference is bad request returned to client""" invalid_swhid = "swh:1:dir :31b5c8cc985d190b5a7ef4878128ebfdc2358f49" xml_data = atom_dataset["entry-data-with-swhid-no-prov"].format(swhid=invalid_swhid) @@ -530,9 +513,7 @@ def test_deposit_metadata_invalid( def test_deposit_metadata_invalid_metadata_provenance( authenticated_client, deposit_collection, atom_dataset ): - """Posting invalid metadata provenance is bad request returned to client - - """ + """Posting invalid metadata provenance is bad request returned to client""" invalid_swhid = "swh:1:dir:31b5c8cc985d190b5a7ef4878128ebfdc2358f49" xml_data = atom_dataset["entry-data-with-swhid"].format( swhid=invalid_swhid, @@ -553,9 +534,7 @@ def test_deposit_metadata_invalid_metadata_provenance( def test_deposit_metadata_fails_functional_checks( authenticated_client, deposit_collection, atom_dataset ): - """Posting functionally invalid metadata swhid is bad request returned to client - - """ + """Posting functionally invalid metadata swhid is bad request returned to client""" swhid = "swh:1:dir:31b5c8cc985d190b5a7ef4878128ebfdc2358f49" invalid_xml_data = atom_dataset[ "entry-data-with-swhid-fail-metadata-functional-checks" @@ -586,11 +565,13 @@ def test_deposit_metadata_fails_functional_checks( ], ) def test_deposit_metadata_swhid( - swhid, authenticated_client, deposit_collection, atom_dataset, swh_storage, + swhid, + authenticated_client, + deposit_collection, + atom_dataset, + swh_storage, ): - """Posting a swhid reference is stored on raw extrinsic metadata storage - - """ + """Posting a swhid reference is stored on raw extrinsic metadata storage""" swhid_reference = QualifiedSWHID.from_string(swhid) swhid_target = extended_swhid_from_qualified(swhid_reference) @@ -622,7 +603,8 @@ def test_deposit_metadata_swhid( # Ensure metadata stored in the metadata storage is consistent metadata_authority = MetadataAuthority( - type=MetadataAuthorityType.DEPOSIT_CLIENT, url=deposit_client.provider_url, + type=MetadataAuthorityType.DEPOSIT_CLIENT, + url=deposit_client.provider_url, ) actual_authority = swh_storage.metadata_authority_get( @@ -632,7 +614,8 @@ def test_deposit_metadata_swhid( config = APIConfig() metadata_fetcher = MetadataFetcher( - name=config.tool["name"], version=config.tool["version"], + name=config.tool["name"], + version=config.tool["version"], ) actual_fetcher = swh_storage.metadata_fetcher_get( @@ -659,7 +642,10 @@ def test_deposit_metadata_swhid( metadata=xml_data.encode(), **metadata_context, ) - assert page_results == PagedResult(results=[metadata], next_page_token=None,) + assert page_results == PagedResult( + results=[metadata], + next_page_token=None, + ) # Get metadata about the deposited metadata object and check it: _assert_deposit_info_on_metadata( @@ -668,14 +654,20 @@ def test_deposit_metadata_swhid( @pytest.mark.parametrize( - "url", ["https://gitlab.org/user/repo", "https://whatever.else/repo",] + "url", + [ + "https://gitlab.org/user/repo", + "https://whatever.else/repo", + ], ) def test_deposit_metadata_origin( - url, authenticated_client, deposit_collection, atom_dataset, swh_storage, + url, + authenticated_client, + deposit_collection, + atom_dataset, + swh_storage, ): - """Posting a swhid reference is stored on raw extrinsic metadata storage - - """ + """Posting a swhid reference is stored on raw extrinsic metadata storage""" xml_data = atom_dataset["entry-data-with-origin-reference"].format(url=url) origin_swhid = Origin(url).swhid() deposit_client = authenticated_client.deposit_client @@ -700,7 +692,8 @@ def test_deposit_metadata_origin( # Ensure metadata stored in the metadata storage is consistent metadata_authority = MetadataAuthority( - type=MetadataAuthorityType.DEPOSIT_CLIENT, url=deposit_client.provider_url, + type=MetadataAuthorityType.DEPOSIT_CLIENT, + url=deposit_client.provider_url, ) actual_authority = swh_storage.metadata_authority_get( @@ -710,7 +703,8 @@ def test_deposit_metadata_origin( config = APIConfig() metadata_fetcher = MetadataFetcher( - name=config.tool["name"], version=config.tool["version"], + name=config.tool["name"], + version=config.tool["version"], ) actual_fetcher = swh_storage.metadata_fetcher_get( @@ -735,7 +729,10 @@ def test_deposit_metadata_origin( format="sword-v2-atom-codemeta", metadata=xml_data.encode(), ) - assert page_results == PagedResult(results=[metadata], next_page_token=None,) + assert page_results == PagedResult( + results=[metadata], + next_page_token=None, + ) # Get metadata about the deposited metadata object and check it: _assert_deposit_info_on_metadata( @@ -759,11 +756,13 @@ def test_deposit_metadata_origin( ], ) def test_deposit_metadata_unknown_swhid( - swhid, authenticated_client, deposit_collection, atom_dataset, swh_storage, + swhid, + authenticated_client, + deposit_collection, + atom_dataset, + swh_storage, ): - """Posting a swhid reference is rejected if the referenced object is unknown - - """ + """Posting a swhid reference is rejected if the referenced object is unknown""" xml_data = atom_dataset["entry-data-with-swhid-no-prov"].format(swhid=swhid) response = post_atom( @@ -789,7 +788,11 @@ def test_deposit_metadata_unknown_swhid( ], ) def test_deposit_metadata_extended_swhid( - swhid, authenticated_client, deposit_collection, atom_dataset, swh_storage, + swhid, + authenticated_client, + deposit_collection, + atom_dataset, + swh_storage, ): """Posting a swhid reference is rejected if the referenced SWHID is for an extended object type @@ -813,11 +816,12 @@ def test_deposit_metadata_extended_swhid( def test_deposit_metadata_unknown_origin( - authenticated_client, deposit_collection, atom_dataset, swh_storage, + authenticated_client, + deposit_collection, + atom_dataset, + swh_storage, ): - """Posting a swhid reference is stored on raw extrinsic metadata storage - - """ + """Posting a swhid reference is stored on raw extrinsic metadata storage""" url = "https://gitlab.org/user/repo" xml_data = atom_dataset["entry-data-with-origin-reference"].format(url=url) response = post_atom( diff --git a/swh/deposit/tests/api/test_collection_post_binary.py b/swh/deposit/tests/api/test_collection_post_binary.py index 5e39aeb9c3e86c7046c618758826222ef6291078..26e7f5a40d50962212f2c1a0b78b0e792284db82 100644 --- a/swh/deposit/tests/api/test_collection_post_binary.py +++ b/swh/deposit/tests/api/test_collection_post_binary.py @@ -25,9 +25,7 @@ from swh.deposit.utils import NAMESPACES def test_post_deposit_binary_no_slug( authenticated_client, deposit_collection, sample_archive, deposit_user, mocker ): - """Posting a binary deposit without slug header should generate one - - """ + """Posting a binary deposit without slug header should generate one""" id_ = str(uuid.uuid4()) mocker.patch("uuid.uuid4", return_value=id_) @@ -35,7 +33,10 @@ def test_post_deposit_binary_no_slug( # when response = post_archive( - authenticated_client, url, sample_archive, in_progress="false", + authenticated_client, + url, + sample_archive, + in_progress="false", ) assert response.status_code == status.HTTP_201_CREATED @@ -51,9 +52,7 @@ def test_post_deposit_binary_no_slug( def test_post_deposit_binary_support( authenticated_client, deposit_collection, sample_archive ): - """Binary upload with content-type not in [zip,x-tar] should return 415 - - """ + """Binary upload with content-type not in [zip,x-tar] should return 415""" # given url = reverse(COL_IRI, args=[deposit_collection.name]) @@ -78,9 +77,7 @@ def test_post_deposit_binary_support( def test_post_deposit_binary_upload_ok( authenticated_client, deposit_collection, sample_archive ): - """Binary upload with correct headers should return 201 with receipt - - """ + """Binary upload with correct headers should return 201 with receipt""" # given url = reverse(COL_IRI, args=[deposit_collection.name]) @@ -151,9 +148,7 @@ def test_post_deposit_binary_upload_ok( def test_post_deposit_binary_failure_unsupported_packaging_header( authenticated_client, deposit_collection, sample_archive ): - """Bin deposit without supported content_disposition header returns 400 - - """ + """Bin deposit without supported content_disposition header returns 400""" # given url = reverse(COL_IRI, args=[deposit_collection.name]) @@ -182,9 +177,7 @@ def test_post_deposit_binary_failure_unsupported_packaging_header( def test_post_deposit_binary_upload_no_content_disposition_header( authenticated_client, deposit_collection, sample_archive ): - """Binary upload without content_disposition header should return 400 - - """ + """Binary upload without content_disposition header should return 400""" # given url = reverse(COL_IRI, args=[deposit_collection.name]) @@ -211,9 +204,7 @@ def test_post_deposit_binary_upload_no_content_disposition_header( def test_post_deposit_mediation_not_supported( authenticated_client, deposit_collection, sample_archive ): - """Binary upload with mediation should return a 412 response - - """ + """Binary upload with mediation should return a 412 response""" # given url = reverse(COL_IRI, args=[deposit_collection.name]) @@ -239,9 +230,7 @@ def test_post_deposit_mediation_not_supported( def test_post_deposit_binary_upload_fail_if_upload_size_limit_exceeded( authenticated_client, deposit_collection, sample_archive, tmp_path ): - """Binary upload must not exceed the limit set up... - - """ + """Binary upload must not exceed the limit set up...""" tmp_path = str(tmp_path) url = reverse(COL_IRI, args=[deposit_collection.name]) @@ -271,9 +260,7 @@ def test_post_deposit_binary_upload_fail_if_upload_size_limit_exceeded( def test_post_deposit_binary_upload_fail_if_content_length_missing( authenticated_client, deposit_collection, sample_archive, tmp_path ): - """The Content-Length header is mandatory - - """ + """The Content-Length header is mandatory""" tmp_path = str(tmp_path) url = reverse(COL_IRI, args=[deposit_collection.name]) @@ -304,9 +291,7 @@ def test_post_deposit_binary_upload_fail_if_content_length_missing( def test_post_deposit_2_post_2_different_deposits( authenticated_client, deposit_collection, sample_archive ): - """2 posting deposits should return 2 different 201 with receipt - - """ + """2 posting deposits should return 2 different 201 with receipt""" url = reverse(COL_IRI, args=[deposit_collection.name]) # when diff --git a/swh/deposit/tests/api/test_collection_post_multipart.py b/swh/deposit/tests/api/test_collection_post_multipart.py index aa0759e8393b74a38751d767775ff6a4bec00dfe..20f1bdb4c60215427d44639860b3711b2fa75f6b 100644 --- a/swh/deposit/tests/api/test_collection_post_multipart.py +++ b/swh/deposit/tests/api/test_collection_post_multipart.py @@ -89,9 +89,7 @@ def test_post_deposit_multipart_without_origin_url( def test_post_deposit_multipart_zip( authenticated_client, deposit_collection, atom_dataset, sample_archive ): - """one multipart deposit (zip+xml) should be accepted - - """ + """one multipart deposit (zip+xml) should be accepted""" # given url = reverse(COL_IRI, args=[deposit_collection.name]) data_atom_entry = atom_dataset["entry-data-deposit-binary"] @@ -139,9 +137,7 @@ def test_post_deposit_multipart_zip( def test_post_deposit_multipart_tar( authenticated_client, deposit_collection, atom_dataset, sample_archive ): - """one multipart deposit (tar+xml) should be accepted - - """ + """one multipart deposit (tar+xml) should be accepted""" # given url = reverse(COL_IRI, args=[deposit_collection.name]) data_atom_entry = atom_dataset["entry-data-deposit-binary"] @@ -190,7 +186,7 @@ def test_post_deposit_multipart_put_to_replace_metadata( authenticated_client, deposit_collection, atom_dataset, sample_archive ): """One multipart deposit followed by a metadata update should be - accepted + accepted """ # given @@ -306,7 +302,10 @@ def test_post_deposit_multipart_only_archive_and_atom_entry( response = authenticated_client.post( url, format="multipart", - data={"archive": archive, "atom_entry": other_archive,}, + data={ + "archive": archive, + "atom_entry": other_archive, + }, # + headers HTTP_IN_PROGRESS="false", HTTP_SLUG="external-id", @@ -324,7 +323,9 @@ def test_post_deposit_multipart_only_archive_and_atom_entry( response = authenticated_client.post( url, format="multipart", - data={"archive": archive,}, + data={ + "archive": archive, + }, # + headers HTTP_IN_PROGRESS="false", HTTP_SLUG="external-id", diff --git a/swh/deposit/tests/api/test_collection_reuse_slug.py b/swh/deposit/tests/api/test_collection_reuse_slug.py index 2d533657a49c5f7b9676b8e1fee08f4ba80b2fcb..ed6fe1c063e2f9f769c70255b041b582a95d1dd1 100644 --- a/swh/deposit/tests/api/test_collection_reuse_slug.py +++ b/swh/deposit/tests/api/test_collection_reuse_slug.py @@ -48,9 +48,7 @@ def test_add_deposit_when_partial_makes_new_deposit( atom_dataset, deposit_user, ): - """Posting deposit on collection when previous is partial makes new deposit - - """ + """Posting deposit on collection when previous is partial makes new deposit""" deposit = partial_deposit assert deposit.status == DEPOSIT_STATUS_PARTIAL origin_url = deposit_user.provider_url + deposit.external_id diff --git a/swh/deposit/tests/api/test_converters.py b/swh/deposit/tests/api/test_converters.py index a446d1c7c0447f49455bb0d6ba3de02fb0abb77e..f4bd177af10212a8c2f0a05b1cef2f8359cc51e8 100644 --- a/swh/deposit/tests/api/test_converters.py +++ b/swh/deposit/tests/api/test_converters.py @@ -18,13 +18,21 @@ def test_convert_status_detail(): "fields": ["blahurl", "testurl"], }, "metadata": [ - {"summary": "Mandatory fields missing", "fields": ["url", "title"],}, + { + "summary": "Mandatory fields missing", + "fields": ["url", "title"], + }, { "summary": "Alternate fields missing", "fields": ["name or title", "url or badurl"], }, ], - "archive": [{"summary": "Unreadable archive", "fields": ["1"],}], + "archive": [ + { + "summary": "Unreadable archive", + "fields": ["1"], + } + ], } expected_status_detail = """- Mandatory fields missing (url, title) @@ -43,10 +51,21 @@ def test_convert_status_detail_2(): "summary": "At least one compatible url field. Failed", "fields": ["testurl"], }, - "metadata": [{"summary": "Mandatory fields missing", "fields": ["name"],},], + "metadata": [ + { + "summary": "Mandatory fields missing", + "fields": ["name"], + }, + ], "archive": [ - {"summary": "Invalid archive", "fields": ["2"],}, - {"summary": "Unsupported archive", "fields": ["1"],}, + { + "summary": "Invalid archive", + "fields": ["2"], + }, + { + "summary": "Unsupported archive", + "fields": ["1"], + }, ], "loading": ["error1", "error 2"], } @@ -65,7 +84,9 @@ def test_convert_status_detail_2(): def test_convert_status_detail_3(): status_detail = { - "url": {"summary": "At least one compatible url field",}, + "url": { + "summary": "At least one compatible url field", + }, } expected_status_detail = "- At least one compatible url field\n" @@ -80,11 +101,20 @@ def test_convert_status_detail_edge_case(): "fields": ["testurl"], }, "metadata": [ - {"summary": "Mandatory fields missing", "fields": ["9", 10, 1.212],}, + { + "summary": "Mandatory fields missing", + "fields": ["9", 10, 1.212], + }, ], "archive": [ - {"summary": "Invalid archive", "fields": ["3"],}, - {"summary": "Unsupported archive", "fields": [2],}, + { + "summary": "Invalid archive", + "fields": ["3"], + }, + { + "summary": "Unsupported archive", + "fields": [2], + }, ], } diff --git a/swh/deposit/tests/api/test_delete.py b/swh/deposit/tests/api/test_delete.py index af274d87849775ddc56ea8925f549239c7d09317..780882e41996151b50abe9b80c51bb98343e6acb 100644 --- a/swh/deposit/tests/api/test_delete.py +++ b/swh/deposit/tests/api/test_delete.py @@ -31,9 +31,7 @@ def count_deposit_request_types(deposit_requests) -> Mapping[str, int]: def test_delete_archive_on_partial_deposit_works( authenticated_client, partial_deposit_with_metadata, deposit_collection ): - """Removing partial deposit's archive should return a 204 response - - """ + """Removing partial deposit's archive should return a 204 response""" deposit_id = partial_deposit_with_metadata.id deposit = Deposit.objects.get(pk=deposit_id) deposit_requests = DepositRequest.objects.filter(deposit=deposit) @@ -59,9 +57,7 @@ def test_delete_archive_on_partial_deposit_works( def test_delete_archive_on_undefined_deposit_fails( authenticated_client, deposit_collection, sample_archive ): - """Delete undefined deposit returns a 404 response - - """ + """Delete undefined deposit returns a 404 response""" # when update_uri = reverse(EM_IRI, args=[deposit_collection.name, 999]) response = authenticated_client.delete(update_uri) @@ -72,9 +68,7 @@ def test_delete_archive_on_undefined_deposit_fails( def test_delete_non_partial_deposit( authenticated_client, deposit_collection, deposited_deposit ): - """Delete !partial status deposit should return a 400 response - - """ + """Delete !partial status deposit should return a 400 response""" deposit = deposited_deposit assert deposit.status == DEPOSIT_STATUS_DEPOSITED @@ -95,9 +89,7 @@ def test_delete_non_partial_deposit( def test_delete_partial_deposit( authenticated_client, deposit_collection, partial_deposit ): - """Delete deposit should return a 204 response - - """ + """Delete deposit should return a 204 response""" # given deposit = partial_deposit @@ -115,9 +107,7 @@ def test_delete_partial_deposit( def test_delete_on_edit_iri_cannot_delete_non_partial_deposit( authenticated_client, deposit_collection, complete_deposit ): - """Delete !partial deposit should return a 400 response - - """ + """Delete !partial deposit should return a 400 response""" # given deposit = complete_deposit diff --git a/swh/deposit/tests/api/test_deposit_private_check.py b/swh/deposit/tests/api/test_deposit_private_check.py index c2dda547226b12f8d4ddeab73fc20d36f9e08688..6f7acc7649586658c75206a3c0262123cebfc8f4 100644 --- a/swh/deposit/tests/api/test_deposit_private_check.py +++ b/swh/deposit/tests/api/test_deposit_private_check.py @@ -43,9 +43,7 @@ def private_check_url_endpoints(collection, deposit): def test_deposit_ok( authenticated_client, deposit_collection, ready_deposit_ok, extension ): - """Proper deposit should succeed the checks (-> status ready) - - """ + """Proper deposit should succeed the checks (-> status ready)""" deposit = ready_deposit_ok for url in private_check_url_endpoints(deposit_collection, deposit): response = authenticated_client.get(url) @@ -72,9 +70,7 @@ def test_deposit_ok( def test_deposit_invalid_tarball( tmp_path, authenticated_client, deposit_collection, extension ): - """Deposit with tarball (of 1 tarball) should fail the checks: rejected - - """ + """Deposit with tarball (of 1 tarball) should fail the checks: rejected""" deposit = create_deposit_archive_with_archive( tmp_path, extension, authenticated_client, deposit_collection.name ) @@ -95,9 +91,7 @@ def test_deposit_invalid_tarball( def test_deposit_ko_missing_tarball( authenticated_client, deposit_collection, ready_deposit_only_metadata ): - """Deposit without archive should fail the checks: rejected - - """ + """Deposit without archive should fail the checks: rejected""" deposit = ready_deposit_only_metadata assert deposit.status == DEPOSIT_STATUS_DEPOSITED @@ -121,9 +115,7 @@ def test_deposit_ko_missing_tarball( def test_deposit_ko_unsupported_tarball( tmp_path, authenticated_client, deposit_collection, ready_deposit_invalid_archive ): - """Deposit with an unsupported tarball should fail the checks: rejected - - """ + """Deposit with an unsupported tarball should fail the checks: rejected""" deposit = ready_deposit_invalid_archive assert DEPOSIT_STATUS_DEPOSITED == deposit.status @@ -154,9 +146,9 @@ def test_check_deposit_metadata_ok( authenticated_client, deposit_collection, ready_deposit_ok ): """Proper deposit should succeed the checks (-> status ready) - with all **MUST** metadata + with all **MUST** metadata - using the codemeta metadata test set + using the codemeta metadata test set """ deposit = ready_deposit_ok assert deposit.status == DEPOSIT_STATUS_DEPOSITED diff --git a/swh/deposit/tests/api/test_deposit_private_list.py b/swh/deposit/tests/api/test_deposit_private_list.py index a5c135acf2f14616b8d0c60f1050d8ad6324bc64..7017d8d40921502747d54530ef972bf9cc01dd35 100644 --- a/swh/deposit/tests/api/test_deposit_private_list.py +++ b/swh/deposit/tests/api/test_deposit_private_list.py @@ -16,10 +16,21 @@ STATUS_DETAIL = { "summary": "At least one compatible url field. Failed", "fields": ["testurl"], }, - "metadata": [{"summary": "Mandatory fields missing", "fields": ["9", 10, 1.212],},], + "metadata": [ + { + "summary": "Mandatory fields missing", + "fields": ["9", 10, 1.212], + }, + ], "archive": [ - {"summary": "Invalid archive", "fields": ["3"],}, - {"summary": "Unsupported archive", "fields": [2],}, + { + "summary": "Invalid archive", + "fields": ["3"], + }, + { + "summary": "Unsupported archive", + "fields": [2], + }, ], } @@ -30,9 +41,7 @@ def test_deposit_list( partial_deposit, authenticated_client, ): - """Deposit list api should return all deposits in a paginated way - - """ + """Deposit list api should return all deposits in a paginated way""" partial_deposit_with_metadata.status_detail = STATUS_DETAIL partial_deposit_with_metadata.save() deposit1 = partial_deposit_with_metadata @@ -110,9 +119,7 @@ def test_deposit_list( def test_deposit_list_exclude(partial_deposit, deposited_deposit, authenticated_client): - """Exclusion pattern on external_id should be respected - - """ + """Exclusion pattern on external_id should be respected""" partial_deposit.status_detail = STATUS_DETAIL partial_deposit.save() diff --git a/swh/deposit/tests/api/test_deposit_private_read_archive.py b/swh/deposit/tests/api/test_deposit_private_read_archive.py index 3ec0c186391e1feb39662134659c7f9da7696b55..85eeb5bb5b08d0197bd7228b06d4ab13406e357b 100644 --- a/swh/deposit/tests/api/test_deposit_private_read_archive.py +++ b/swh/deposit/tests/api/test_deposit_private_read_archive.py @@ -31,9 +31,7 @@ def test_access_to_existing_deposit_with_one_archive( sample_archive, tmp_path, ): - """Access to deposit should stream a 200 response with its raw content - - """ + """Access to deposit should stream a 200 response with its raw content""" deposit = complete_deposit for i, url in enumerate(private_get_raw_url_endpoints(deposit_collection, deposit)): @@ -57,9 +55,7 @@ def test_access_to_existing_deposit_with_one_archive( def test_access_to_existing_deposit_with_multiple_archives( tmp_path, authenticated_client, deposit_collection, partial_deposit, sample_archive ): - """Access to deposit should stream a 200 response with its raw contents - - """ + """Access to deposit should stream a 200 response with its raw contents""" deposit = partial_deposit archive2 = create_arborescence_archive( tmp_path, "archive2", "file2", b"some other content in file" diff --git a/swh/deposit/tests/api/test_deposit_private_read_metadata.py b/swh/deposit/tests/api/test_deposit_private_read_metadata.py index 7e8879b63f7616ce1b3c70ae90cf65036731ad4b..8428266ada708aed75113dd27ae8ac5701907a9a 100644 --- a/swh/deposit/tests/api/test_deposit_private_read_metadata.py +++ b/swh/deposit/tests/api/test_deposit_private_read_metadata.py @@ -38,9 +38,7 @@ def update_deposit_with_metadata(authenticated_client, collection, deposit, meta def test_read_missing_metadata( authenticated_client, deposit_collection, partial_deposit, atom_dataset ): - """Private metadata read api to existing deposit should return metadata - - """ + """Private metadata read api to existing deposit should return metadata""" deposit = partial_deposit deposit.external_id = "some-external-id" deposit.origin_url = f"https://hal-test.archives-ouvertes.fr/{deposit.external_id}" @@ -85,9 +83,7 @@ def test_read_missing_metadata( def test_read_metadata( authenticated_client, deposit_collection, partial_deposit, atom_dataset ): - """Private metadata read api to existing deposit should return metadata - - """ + """Private metadata read api to existing deposit should return metadata""" deposit = partial_deposit deposit.external_id = "some-external-id" deposit.origin_url = f"https://hal-test.archives-ouvertes.fr/{deposit.external_id}" @@ -95,7 +91,10 @@ def test_read_metadata( metadata_xml_raw = atom_dataset["entry-data2"] deposit = update_deposit_with_metadata( - authenticated_client, deposit_collection, deposit, metadata_xml_raw, + authenticated_client, + deposit_collection, + deposit, + metadata_xml_raw, ) for url in private_get_raw_url_endpoints(deposit_collection, deposit): @@ -143,16 +142,17 @@ def test_read_metadata( def test_read_metadata_revision_with_parent( authenticated_client, deposit_collection, partial_deposit, atom_dataset ): - """Private read metadata to a deposit (with parent) returns metadata - - """ + """Private read metadata to a deposit (with parent) returns metadata""" deposit = partial_deposit deposit.external_id = "some-external-id" deposit.origin_url = f"https://hal-test.archives-ouvertes.fr/{deposit.external_id}" deposit.save() metadata_xml_raw = atom_dataset["entry-data2"] deposit = update_deposit_with_metadata( - authenticated_client, deposit_collection, deposit, metadata_xml_raw, + authenticated_client, + deposit_collection, + deposit, + metadata_xml_raw, ) rev_id = "da78a9d4cf1d5d29873693fd496142e3a18c20fa" @@ -210,9 +210,7 @@ def test_read_metadata_revision_with_parent( def test_read_metadata_3( authenticated_client, deposit_collection, partial_deposit, atom_dataset ): - """date(Created|Published) provided, uses author/committer date - - """ + """date(Created|Published) provided, uses author/committer date""" deposit = partial_deposit deposit.external_id = "hal-01243065" deposit.origin_url = f"https://hal-test.archives-ouvertes.fr/{deposit.external_id}" @@ -220,7 +218,10 @@ def test_read_metadata_3( metadata_xml_raw = atom_dataset["entry-data3"] update_deposit_with_metadata( - authenticated_client, deposit_collection, deposit, metadata_xml_raw, + authenticated_client, + deposit_collection, + deposit, + metadata_xml_raw, ) for url in private_get_raw_url_endpoints(deposit_collection, deposit): @@ -269,9 +270,7 @@ def test_read_metadata_3( def test_read_metadata_4( authenticated_client, deposit_collection, atom_dataset, partial_deposit ): - """dateCreated/datePublished not provided, revision uses complete_date - - """ + """dateCreated/datePublished not provided, revision uses complete_date""" deposit = partial_deposit codemeta_entry_data = atom_dataset["metadata"] % "" deposit = update_deposit_with_metadata( @@ -290,7 +289,10 @@ def test_read_metadata_4( actual_data = response.json() assert actual_data == { - "origin": {"type": "deposit", "url": None,}, + "origin": { + "type": "deposit", + "url": None, + }, "raw_metadata": codemeta_entry_data, "provider": { "metadata": {}, @@ -394,11 +396,10 @@ def test_read_metadata_5( def test_access_to_nonexisting_deposit_returns_404_response( - authenticated_client, deposit_collection, + authenticated_client, + deposit_collection, ): - """Read unknown collection should return a 404 response - - """ + """Read unknown collection should return a 404 response""" unknown_id = 999 try: Deposit.objects.get(pk=unknown_id) @@ -415,9 +416,7 @@ def test_access_to_nonexisting_deposit_returns_404_response( def test_read_metadata_multiple_release_notes( authenticated_client, deposit_collection, partial_deposit, atom_dataset ): - """Private metadata read api to existing deposit should return metadata - - """ + """Private metadata read api to existing deposit should return metadata""" deposit = partial_deposit deposit.external_id = "some-external-id" deposit.origin_url = f"https://hal-test.archives-ouvertes.fr/{deposit.external_id}" @@ -425,7 +424,10 @@ def test_read_metadata_multiple_release_notes( metadata_xml_raw = atom_dataset["entry-data-multiple-release-notes"] deposit = update_deposit_with_metadata( - authenticated_client, deposit_collection, deposit, metadata_xml_raw, + authenticated_client, + deposit_collection, + deposit, + metadata_xml_raw, ) for url in private_get_raw_url_endpoints(deposit_collection, deposit): diff --git a/swh/deposit/tests/api/test_deposit_private_update_status.py b/swh/deposit/tests/api/test_deposit_private_update_status.py index 7ac6974b7ca4f90eac271d323f0bbce53d56db4d..e859635e9b2868090a0c6da12a7649112be4e6d7 100644 --- a/swh/deposit/tests/api/test_deposit_private_update_status.py +++ b/swh/deposit/tests/api/test_deposit_private_update_status.py @@ -31,9 +31,7 @@ def private_check_url_endpoints(collection, deposit): def test_update_deposit_status_success_with_info( authenticated_client, deposit_collection, ready_deposit_verified ): - """Update deposit with load success should require all information to succeed - - """ + """Update deposit with load success should require all information to succeed""" deposit = ready_deposit_verified expected_status = DEPOSIT_STATUS_LOAD_SUCCESS status_detail = "it works!" @@ -61,7 +59,9 @@ def test_update_deposit_status_success_with_info( ) response = authenticated_client.put( - url, content_type="application/json", data=json.dumps(full_body_info), + url, + content_type="application/json", + data=json.dumps(full_body_info), ) assert response.status_code == status.HTTP_204_NO_CONTENT @@ -80,9 +80,7 @@ def test_update_deposit_status_success_with_info( def test_update_deposit_status_rejected_with_info( authenticated_client, deposit_collection, ready_deposit_verified ): - """Update deposit with rejected status needs few information to succeed - - """ + """Update deposit with rejected status needs few information to succeed""" deposit = ready_deposit_verified for url in private_check_url_endpoints(deposit_collection, deposit): @@ -108,9 +106,7 @@ def test_update_deposit_status_rejected_with_info( def test_update_deposit_status_success_with_incomplete_data( authenticated_client, deposit_collection, ready_deposit_verified ): - """Update deposit status with status success and incomplete information should fail - - """ + """Update deposit status with status success and incomplete information should fail""" deposit = ready_deposit_verified origin_url = "something" @@ -134,7 +130,9 @@ def test_update_deposit_status_success_with_incomplete_data( body.pop(key) # make the body incomplete response = authenticated_client.put( - url, content_type="application/json", data=json.dumps(body), + url, + content_type="application/json", + data=json.dumps(body), ) assert response.status_code == status.HTTP_400_BAD_REQUEST @@ -147,9 +145,7 @@ def test_update_deposit_status_success_with_incomplete_data( def test_update_deposit_status_will_fail_with_unknown_status( authenticated_client, deposit_collection, ready_deposit_verified ): - """Unknown status for update should return a 400 response - - """ + """Unknown status for update should return a 400 response""" deposit = ready_deposit_verified for url in private_check_url_endpoints(deposit_collection, deposit): response = authenticated_client.put( @@ -163,9 +159,7 @@ def test_update_deposit_status_will_fail_with_unknown_status( def test_update_deposit_status_will_fail_with_no_status_key( authenticated_client, deposit_collection, ready_deposit_verified ): - """No status provided for update should return a 400 response - - """ + """No status provided for update should return a 400 response""" deposit = ready_deposit_verified for url in private_check_url_endpoints(deposit_collection, deposit): response = authenticated_client.put( @@ -181,9 +175,7 @@ def test_update_deposit_status_will_fail_with_no_status_key( def test_update_deposit_status_success_without_swhid_fail( authenticated_client, deposit_collection, ready_deposit_verified ): - """Providing successful status without swhid should return a 400 - - """ + """Providing successful status without swhid should return a 400""" deposit = ready_deposit_verified for url in private_check_url_endpoints(deposit_collection, deposit): response = authenticated_client.put( diff --git a/swh/deposit/tests/api/test_deposit_schedule.py b/swh/deposit/tests/api/test_deposit_schedule.py index caf64d9aa82d9ee43d9964fef24a14ba9661d0b9..7c617e0f377485e8c444f9546b38c86ba04b575a 100644 --- a/swh/deposit/tests/api/test_deposit_schedule.py +++ b/swh/deposit/tests/api/test_deposit_schedule.py @@ -43,7 +43,10 @@ def assert_task_for_deposit( assert timestamp_before_call <= task.pop("next_run") <= timestamp_after_call assert task["arguments"] == { "args": [], - "kwargs": {"collection": "test", "deposit_id": deposit_id,}, + "kwargs": { + "collection": "test", + "deposit_id": deposit_id, + }, } assert task["policy"] == "oneshot" assert task["type"] == "check-deposit" @@ -53,9 +56,7 @@ def assert_task_for_deposit( def test_add_deposit_schedules_check( authenticated_client, deposit_collection, sample_archive, swh_scheduler ): - """Posting deposit by POST Col-IRI creates a checker task - - """ + """Posting deposit by POST Col-IRI creates a checker task""" tasks = swh_scheduler.grab_ready_tasks("check-deposit") assert len(tasks) == 0 @@ -100,9 +101,7 @@ def test_update_deposit_schedules_check( atom_dataset, swh_scheduler, ): - """Updating deposit by POST SE-IRI creates a checker task - - """ + """Updating deposit by POST SE-IRI creates a checker task""" deposit = partial_deposit_with_metadata assert deposit.status == DEPOSIT_STATUS_PARTIAL diff --git a/swh/deposit/tests/api/test_deposit_state.py b/swh/deposit/tests/api/test_deposit_state.py index beaafdee73c79a35755340b256421f3f61b56e88..f9cf861fad244d8b132e862f45ea12a5e486a933 100644 --- a/swh/deposit/tests/api/test_deposit_state.py +++ b/swh/deposit/tests/api/test_deposit_state.py @@ -19,9 +19,7 @@ from swh.deposit.utils import NAMESPACES def test_post_deposit_with_status_check(authenticated_client, deposited_deposit): - """Successful but not loaded deposit should have a status 'deposited' - - """ + """Successful but not loaded deposit should have a status 'deposited'""" deposit = deposited_deposit status_url = reverse(STATE_IRI, args=[deposit.collection.name, deposit.id]) @@ -51,9 +49,7 @@ def test_post_deposit_with_status_check(authenticated_client, deposited_deposit) def test_status_unknown_deposit(authenticated_client, deposit_collection): - """Unknown deposit status should return 404 response - - """ + """Unknown deposit status should return 404 response""" unknown_deposit_id = 999 status_url = reverse(STATE_IRI, args=[deposit_collection.name, unknown_deposit_id]) status_response = authenticated_client.get(status_url) @@ -70,9 +66,7 @@ def test_status_unknown_collection(authenticated_client, deposited_deposit): def test_status_deposit_rejected(authenticated_client, rejected_deposit): - """Rejected deposit status should be 'rejected' with detailed summary - - """ + """Rejected deposit status should be 'rejected' with detailed summary""" deposit = rejected_deposit # _status_detail = {'url': {'summary': 'Wrong url'}} @@ -100,9 +94,7 @@ def test_status_deposit_rejected(authenticated_client, rejected_deposit): def test_status_with_http_accept_header_should_not_break( authenticated_client, partial_deposit ): - """Asking deposit status with Accept header should return 200 - - """ + """Asking deposit status with Accept header should return 200""" deposit = partial_deposit status_url = reverse(STATE_IRI, args=[deposit.collection.name, deposit.id]) @@ -117,9 +109,7 @@ def test_status_with_http_accept_header_should_not_break( def test_status_complete_deposit(authenticated_client, complete_deposit): - """Successful and loaded deposit should be 'done' and have detailed swh ids - - """ + """Successful and loaded deposit should be 'done' and have detailed swh ids""" deposit = complete_deposit url = reverse(STATE_IRI, args=[deposit.collection.name, deposit.id]) diff --git a/swh/deposit/tests/api/test_deposit_update.py b/swh/deposit/tests/api/test_deposit_update.py index 828c9d8a70de49048e1804bafe0ec136b6e1b079..ed0248c76e9d861493ba15b0eb5a9a10d1b4da60 100644 --- a/swh/deposit/tests/api/test_deposit_update.py +++ b/swh/deposit/tests/api/test_deposit_update.py @@ -80,7 +80,11 @@ def test_post_metadata_empty_post_finalize_deposit_ok( update_uri = reverse(SE_IRI, args=[deposit_collection.name, deposit.id]) response = post_atom( - authenticated_client, update_uri, data="", size=0, HTTP_IN_PROGRESS=False, + authenticated_client, + update_uri, + data="", + size=0, + HTTP_IN_PROGRESS=False, ) assert response.status_code == status.HTTP_200_OK diff --git a/swh/deposit/tests/api/test_deposit_update_atom.py b/swh/deposit/tests/api/test_deposit_update_atom.py index 4a243cf96c7dcbdf71ba7bd86fafb91a6c20e887..4809d982dd0d02904b57a6576ae820191e7512f4 100644 --- a/swh/deposit/tests/api/test_deposit_update_atom.py +++ b/swh/deposit/tests/api/test_deposit_update_atom.py @@ -34,9 +34,7 @@ from swh.storage.interface import PagedResult def test_post_deposit_atom_entry_multiple_steps( authenticated_client, deposit_collection, atom_dataset, deposit_user ): - """After initial deposit, updating a deposit should return a 201 - - """ + """After initial deposit, updating a deposit should return a 201""" # given origin_url = deposit_user.provider_url + "2225c695-cfb8-4ebb-aaaa-80da344efa6a" @@ -74,7 +72,10 @@ def test_post_deposit_atom_entry_multiple_steps( # when updating the first deposit post response = post_atom( - authenticated_client, se_iri, data=atom_entry_data, HTTP_IN_PROGRESS="False", + authenticated_client, + se_iri, + data=atom_entry_data, + HTTP_IN_PROGRESS="False", ) # then @@ -113,9 +114,7 @@ def test_replace_metadata_to_deposit_is_possible( atom_dataset, deposit_user, ): - """Replace all metadata with another one should return a 204 response - - """ + """Replace all metadata with another one should return a 204 response""" # given deposit = partial_deposit_with_metadata origin_url = deposit_user.provider_url + deposit.external_id @@ -132,7 +131,9 @@ def test_replace_metadata_to_deposit_is_possible( update_uri = reverse(EDIT_IRI, args=[deposit_collection.name, deposit.id]) response = put_atom( - authenticated_client, update_uri, data=atom_dataset["entry-data1"], + authenticated_client, + update_uri, + data=atom_dataset["entry-data1"], ) assert response.status_code == status.HTTP_204_NO_CONTENT @@ -159,9 +160,7 @@ def test_add_metadata_to_deposit_is_possible( atom_dataset, deposit_user, ): - """Add metadata with another one should return a 204 response - - """ + """Add metadata with another one should return a 204 response""" deposit = partial_deposit_with_metadata origin_url = deposit_user.provider_url + deposit.external_id requests = DepositRequest.objects.filter(deposit=deposit, type="metadata") @@ -197,9 +196,7 @@ def test_add_metadata_to_deposit_is_possible( def test_add_metadata_to_unknown_deposit( deposit_collection, authenticated_client, atom_dataset ): - """Replacing metadata to unknown deposit should return a 404 response - - """ + """Replacing metadata to unknown deposit should return a 404 response""" unknown_deposit_id = 1000 try: Deposit.objects.get(pk=unknown_deposit_id) @@ -207,7 +204,11 @@ def test_add_metadata_to_unknown_deposit( assert True url = reverse(SE_IRI, args=[deposit_collection, unknown_deposit_id]) - response = post_atom(authenticated_client, url, data=atom_dataset["entry-data1"],) + response = post_atom( + authenticated_client, + url, + data=atom_dataset["entry-data1"], + ) assert response.status_code == status.HTTP_404_NOT_FOUND response_content = parse_xml(response.content) assert "Deposit 1000 does not exist" in response_content.findtext( @@ -218,9 +219,7 @@ def test_add_metadata_to_unknown_deposit( def test_add_metadata_to_unknown_collection( partial_deposit, authenticated_client, atom_dataset ): - """Replacing metadata to unknown deposit should return a 404 response - - """ + """Replacing metadata to unknown deposit should return a 404 response""" deposit = partial_deposit unknown_collection_name = "unknown-collection" try: @@ -229,7 +228,11 @@ def test_add_metadata_to_unknown_collection( assert True url = reverse(SE_IRI, args=[unknown_collection_name, deposit.id]) - response = post_atom(authenticated_client, url, data=atom_dataset["entry-data1"],) + response = post_atom( + authenticated_client, + url, + data=atom_dataset["entry-data1"], + ) assert response.status_code == status.HTTP_404_NOT_FOUND response_content = parse_xml(response.content) assert "Unknown collection name" in response_content.findtext( @@ -240,16 +243,18 @@ def test_add_metadata_to_unknown_collection( def test_replace_metadata_to_unknown_deposit( authenticated_client, deposit_collection, atom_dataset ): - """Adding metadata to unknown deposit should return a 404 response - - """ + """Adding metadata to unknown deposit should return a 404 response""" unknown_deposit_id = 998 try: Deposit.objects.get(pk=unknown_deposit_id) except Deposit.DoesNotExist: assert True url = reverse(EDIT_IRI, args=[deposit_collection.name, unknown_deposit_id]) - response = put_atom(authenticated_client, url, data=atom_dataset["entry-data1"],) + response = put_atom( + authenticated_client, + url, + data=atom_dataset["entry-data1"], + ) assert response.status_code == status.HTTP_404_NOT_FOUND response_content = parse_xml(response.content) assert ( @@ -261,9 +266,7 @@ def test_replace_metadata_to_unknown_deposit( def test_post_metadata_to_em_iri_failure( authenticated_client, deposit_collection, partial_deposit, atom_dataset ): - """Update (POST) archive with wrong content type should return 400 - - """ + """Update (POST) archive with wrong content type should return 400""" deposit = partial_deposit update_uri = reverse(EM_IRI, args=[deposit_collection.name, deposit.id]) response = authenticated_client.post( @@ -280,15 +283,15 @@ def test_post_metadata_to_em_iri_failure( def test_put_metadata_to_em_iri_failure( authenticated_client, deposit_collection, partial_deposit, atom_dataset ): - """Update (PUT) archive with wrong content type should return 400 - - """ + """Update (PUT) archive with wrong content type should return 400""" # given deposit = partial_deposit # when update_uri = reverse(EM_IRI, args=[deposit_collection.name, deposit.id]) response = put_atom( - authenticated_client, update_uri, data=atom_dataset["entry-data1"], + authenticated_client, + update_uri, + data=atom_dataset["entry-data1"], ) # then assert response.status_code == status.HTTP_400_BAD_REQUEST @@ -307,10 +310,10 @@ def test_put_update_metadata_done_deposit_nominal( swh_storage, ): """Nominal scenario, client send an update of metadata on a deposit with status "done" - with an existing swhid. Such swhid has its metadata updated accordingly both in - the deposit backend and in the metadata storage. + with an existing swhid. Such swhid has its metadata updated accordingly both in + the deposit backend and in the metadata storage. - Response: 204 + Response: 204 """ deposit_swhid = CoreSWHID.from_string(complete_deposit.swhid) @@ -377,7 +380,8 @@ def test_put_update_metadata_done_deposit_nominal( config = APIConfig() metadata_fetcher = MetadataFetcher( - name=config.tool["name"], version=config.tool["version"], + name=config.tool["name"], + version=config.tool["version"], ) actual_fetcher = swh_storage.metadata_fetcher_get( @@ -415,7 +419,7 @@ def test_put_update_metadata_done_deposit_failure_mismatched_swhid( ): """failure: client updates metadata on deposit with SWHID not matching the deposit's. - Response: 400 + Response: 400 """ incorrect_swhid = "swh:1:dir:ef04a768181417fbc5eef4243e2507915f24deea" @@ -443,7 +447,7 @@ def test_put_update_metadata_done_deposit_failure_malformed_xml( ): """failure: client updates metadata on deposit done with a malformed xml - Response: 400 + Response: 400 """ update_uri = reverse(EDIT_IRI, args=[deposit_collection.name, complete_deposit.id]) @@ -468,7 +472,7 @@ def test_put_update_metadata_done_deposit_failure_empty_xml( ): """failure: client updates metadata on deposit done with an empty xml. - Response: 400 + Response: 400 """ update_uri = reverse(EDIT_IRI, args=[deposit_collection.name, complete_deposit.id]) @@ -495,7 +499,7 @@ def test_put_update_metadata_done_deposit_failure_functional_checks( ): """failure: client updates metadata on deposit done without required incomplete metadata - Response: 400 + Response: 400 """ update_uri = reverse(EDIT_IRI, args=[deposit_collection.name, complete_deposit.id]) @@ -559,9 +563,7 @@ def test_put_atom_with_create_origin_and_external_identifier( def test_put_atom_with_create_origin_and_reference( authenticated_client, deposit_collection, atom_dataset, deposit_user ): - """<swh:reference> and <swh:create_origin> are mutually exclusive - - """ + """<swh:reference> and <swh:create_origin> are mutually exclusive""" external_id = "foobar" origin_url = deposit_user.provider_url + external_id url = reverse(COL_IRI, args=[deposit_collection.name]) diff --git a/swh/deposit/tests/api/test_deposit_update_binary.py b/swh/deposit/tests/api/test_deposit_update_binary.py index 22e97240c2d610080b737e8a7e9cf393139e53d4..e1c7a73fc743743cba6cedb9f8c116fd92efd93e 100644 --- a/swh/deposit/tests/api/test_deposit_update_binary.py +++ b/swh/deposit/tests/api/test_deposit_update_binary.py @@ -29,9 +29,7 @@ from swh.deposit.utils import NAMESPACES def test_post_deposit_binary_and_post_to_add_another_archive( authenticated_client, deposit_collection, sample_archive, tmp_path ): - """Updating a deposit should return a 201 with receipt - - """ + """Updating a deposit should return a 201 with receipt""" tmp_path = str(tmp_path) url = reverse(COL_IRI, args=[deposit_collection.name]) @@ -73,7 +71,10 @@ def test_post_deposit_binary_and_post_to_add_another_archive( # adding another archive for the deposit and finalizing it response = post_archive( - authenticated_client, update_uri, archive2, HTTP_SLUG=external_id, + authenticated_client, + update_uri, + archive2, + HTTP_SLUG=external_id, ) assert response.status_code == status.HTTP_201_CREATED @@ -112,9 +113,7 @@ def test_replace_archive_to_deposit_is_possible( sample_archive, atom_dataset, ): - """Replace all archive with another one should return a 204 response - - """ + """Replace all archive with another one should return a 204 response""" tmp_path = str(tmp_path) # given deposit = partial_deposit @@ -167,9 +166,7 @@ def test_replace_archive_to_deposit_is_possible( def test_add_archive_to_unknown_deposit( authenticated_client, deposit_collection, atom_dataset ): - """Adding metadata to unknown deposit should return a 404 response - - """ + """Adding metadata to unknown deposit should return a 404 response""" unknown_deposit_id = 997 try: Deposit.objects.get(pk=unknown_deposit_id) @@ -191,9 +188,7 @@ def test_add_archive_to_unknown_deposit( def test_replace_archive_to_unknown_deposit( authenticated_client, deposit_collection, atom_dataset ): - """Replacing archive to unknown deposit should return a 404 response - - """ + """Replacing archive to unknown deposit should return a 404 response""" unknown_deposit_id = 996 try: Deposit.objects.get(pk=unknown_deposit_id) @@ -219,9 +214,7 @@ def test_add_archive_to_deposit_is_possible( partial_deposit_with_metadata, sample_archive, ): - """Add another archive to a deposit return a 201 response - - """ + """Add another archive to a deposit return a 201 response""" tmp_path = str(tmp_path) deposit = partial_deposit_with_metadata @@ -269,9 +262,7 @@ def test_add_archive_to_deposit_is_possible( def test_post_deposit_then_update_refused( authenticated_client, deposit_collection, sample_archive, atom_dataset, tmp_path ): - """Updating a deposit with status 'ready' should return a 400 - - """ + """Updating a deposit with status 'ready' should return a 400""" tmp_path = str(tmp_path) url = reverse(COL_IRI, args=[deposit_collection.name]) @@ -404,7 +395,10 @@ def test_post_deposit_then_update_refused( r = authenticated_client.put( edit_iri, format="multipart", - data={"archive": archive, "atom_entry": atom_entry,}, + data={ + "archive": archive, + "atom_entry": atom_entry, + }, ) assert r.status_code == status.HTTP_400_BAD_REQUEST @@ -418,7 +412,10 @@ def test_post_deposit_then_update_refused( r = authenticated_client.post( se_iri, format="multipart", - data={"archive": archive, "atom_entry": atom_entry,}, + data={ + "archive": archive, + "atom_entry": atom_entry, + }, ) assert r.status_code == status.HTTP_400_BAD_REQUEST diff --git a/swh/deposit/tests/api/test_exception.py b/swh/deposit/tests/api/test_exception.py index f1ea1e8cc43b0e0cf069a8ae74bd0a42a91b531f..8d10688786d2287ec0cb7634fee9ac4061f142d7 100644 --- a/swh/deposit/tests/api/test_exception.py +++ b/swh/deposit/tests/api/test_exception.py @@ -11,9 +11,7 @@ from swh.deposit.exception import custom_exception_handler def test_custom_exception_handler_operational_error(mocker): - """Operation error are translated to service unavailable - - """ + """Operation error are translated to service unavailable""" fake_exception = OperationalError("Fake internal error", 503) response = custom_exception_handler(fake_exception, {}) @@ -36,9 +34,7 @@ def test_custom_exception_handler_operational_error(mocker): def test_custom_exception_handler_default_behavior_maintained(mocker): - """Other internal errors are transmitted as is - - """ + """Other internal errors are transmitted as is""" fake_exception = APIException("Fake internal error", 500) fake_response = Response( exception=fake_exception, status=fake_exception.status_code diff --git a/swh/deposit/tests/api/test_get_file.py b/swh/deposit/tests/api/test_get_file.py index dbaf64d3ce4db8bb9fc95323a6c16019de4d95b6..186fc2ba74496692762358d1d982fb4311fb48f1 100644 --- a/swh/deposit/tests/api/test_get_file.py +++ b/swh/deposit/tests/api/test_get_file.py @@ -19,9 +19,7 @@ from swh.deposit.utils import NAMESPACES def test_api_deposit_content_nominal( authenticated_client, complete_deposit, partial_deposit_only_metadata ): - """Retrieve information on deposit should return 200 response - - """ + """Retrieve information on deposit should return 200 response""" now = datetime.datetime.now(tz=datetime.timezone.utc) for deposit in [complete_deposit, partial_deposit_only_metadata]: @@ -52,9 +50,7 @@ def test_api_deposit_content_nominal( def test_api_deposit_content_unknown( authenticated_client, complete_deposit, deposit_collection ): - """Retrieve information on unknown deposit or collection should return 404 - - """ + """Retrieve information on unknown deposit or collection should return 404""" unknown_deposit_id = 999 unknown_collection = "unknown" for collection, deposit_id in [ diff --git a/swh/deposit/tests/api/test_keycloak_auth.py b/swh/deposit/tests/api/test_keycloak_auth.py index cdb834e917ab6b069d3177e87e1421d3625ae0ce..5278d4026ac3728359977326701f64c3ac849b1e 100644 --- a/swh/deposit/tests/api/test_keycloak_auth.py +++ b/swh/deposit/tests/api/test_keycloak_auth.py @@ -26,9 +26,7 @@ def mock_keycloakopenidconnect_ko(mocker, keycloak_mock_auth_failure): def test_keycloak_failure_service_document(unauthorized_client): - """With authentication failure without detail, exception is returned correctly - - """ + """With authentication failure without detail, exception is returned correctly""" url = reverse(SD_IRI) response = unauthorized_client.get(url) assert response.status_code == 401 diff --git a/swh/deposit/tests/api/test_service_document.py b/swh/deposit/tests/api/test_service_document.py index 0c5d69cbe5ac78a68298fe195cbfce5c53b72603..1a2bcceee780f4a59444b35ea5b31bf10f2b5c94 100644 --- a/swh/deposit/tests/api/test_service_document.py +++ b/swh/deposit/tests/api/test_service_document.py @@ -10,36 +10,28 @@ from swh.deposit.config import SD_IRI def test_service_document_no_auth_fails(client): - """Without authentication, service document endpoint should return 401 - - """ + """Without authentication, service document endpoint should return 401""" url = reverse(SD_IRI) response = client.get(url) assert response.status_code == status.HTTP_401_UNAUTHORIZED def test_service_document_no_auth_with_http_auth_should_not_break(client): - """Without auth, sd endpoint through browser should return 401 - - """ + """Without auth, sd endpoint through browser should return 401""" url = reverse(SD_IRI) response = client.get(url, HTTP_ACCEPT="text/html,application/xml;q=9,*/*,q=8") assert response.status_code == status.HTTP_401_UNAUTHORIZED def test_service_document(authenticated_client): - """With authentication, service document list user's collection - - """ + """With authentication, service document list user's collection""" url = reverse(SD_IRI) response = authenticated_client.get(url) check_response(response, authenticated_client.deposit_client.username) def test_service_document_with_http_accept_header(authenticated_client): - """With authentication, with browser, sd list user's collection - - """ + """With authentication, with browser, sd list user's collection""" url = reverse(SD_IRI) response = authenticated_client.get( url, HTTP_ACCEPT="text/html,application/xml;q=9,*/*,q=8" diff --git a/swh/deposit/tests/cli/test_admin.py b/swh/deposit/tests/cli/test_admin.py index 69860ba99791f01c5dddc7aec07f3d3d9dde8fe9..af576c69404f0c40526aa1f34b5ea49b90637250 100644 --- a/swh/deposit/tests/cli/test_admin.py +++ b/swh/deposit/tests/cli/test_admin.py @@ -21,21 +21,39 @@ def enable_db_access_for_all_tests(db): def test_cli_admin_user_list_nothing(cli_runner): - result = cli_runner.invoke(cli, ["user", "list",]) + result = cli_runner.invoke( + cli, + [ + "user", + "list", + ], + ) assert result.exit_code == 0, f"Unexpected output: {result.output}" assert result.output == "Empty user list\n" def test_cli_admin_user_list_with_users(cli_runner, deposit_user): - result = cli_runner.invoke(cli, ["user", "list",]) + result = cli_runner.invoke( + cli, + [ + "user", + "list", + ], + ) assert result.exit_code == 0, f"Unexpected output: {result.output}" assert result.output == f"{deposit_user.username}\n" # only 1 user def test_cli_admin_collection_list_nothing(cli_runner): - result = cli_runner.invoke(cli, ["collection", "list",]) + result = cli_runner.invoke( + cli, + [ + "collection", + "list", + ], + ) assert result.exit_code == 0, f"Unexpected output: {result.output}" assert result.output == "Empty collection list\n" @@ -46,7 +64,13 @@ def test_cli_admin_collection_list_with_collections(cli_runner, deposit_collecti new_collection = create_deposit_collection("something") - result = cli_runner.invoke(cli, ["collection", "list",]) + result = cli_runner.invoke( + cli, + [ + "collection", + "list", + ], + ) assert result.exit_code == 0, f"Unexpected output: {result.output}" collections = "\n".join([deposit_collection.name, new_collection.name]) @@ -76,7 +100,13 @@ def test_cli_admin_create_collection(cli_runner): pass result = cli_runner.invoke( - cli, ["collection", "create", "--name", collection_name,] + cli, + [ + "collection", + "create", + "--name", + collection_name, + ], ) assert result.exit_code == 0, f"Unexpected output: {result.output}" @@ -91,7 +121,13 @@ Collection '{collection_name}' created. ) result2 = cli_runner.invoke( - cli, ["collection", "create", "--name", collection_name,] + cli, + [ + "collection", + "create", + "--name", + collection_name, + ], ) assert result2.exit_code == 0, f"Unexpected output: {result.output}" assert ( @@ -116,7 +152,15 @@ def test_cli_admin_user_create(cli_runner): pass result = cli_runner.invoke( - cli, ["user", "create", "--username", user_name, "--password", "password",] + cli, + [ + "user", + "create", + "--username", + user_name, + "--password", + "password", + ], ) assert result.exit_code == 0, f"Unexpected output: {result.output}" user = DepositClient.objects.get(username=user_name) @@ -198,9 +242,7 @@ User '{user_name}' updated. def test_cli_admin_reschedule_unknown_deposit(cli_runner): - """Rescheduling unknown deposit should report failure - - """ + """Rescheduling unknown deposit should report failure""" unknown_deposit_id = 666 from swh.deposit.models import Deposit @@ -219,9 +261,7 @@ def test_cli_admin_reschedule_unknown_deposit(cli_runner): def test_cli_admin_reschedule_verified_deposit(cli_runner, complete_deposit): - """Rescheduling verified deposit should do nothing but report - - """ + """Rescheduling verified deposit should do nothing but report""" deposit = complete_deposit deposit.status = "verified" deposit.save() @@ -240,9 +280,7 @@ def test_cli_admin_reschedule_verified_deposit(cli_runner, complete_deposit): def test_cli_admin_reschedule_unaccepted_deposit_status( status_to_check, cli_runner, complete_deposit ): - """Rescheduling verified deposit should do nothing but report - - """ + """Rescheduling verified deposit should do nothing but report""" deposit = complete_deposit deposit.status = status_to_check # not accepted status will fail the check deposit.save() @@ -259,9 +297,7 @@ def test_cli_admin_reschedule_unaccepted_deposit_status( def test_cli_admin_reschedule_missing_task_id(cli_runner, complete_deposit): - """Rescheduling deposit with no load_task_id cannot work. - - """ + """Rescheduling deposit with no load_task_id cannot work.""" deposit = complete_deposit deposit.load_task_id = "" # drop the load-task-id so it fails the check deposit.save() @@ -278,9 +314,7 @@ def test_cli_admin_reschedule_missing_task_id(cli_runner, complete_deposit): def test_cli_admin_reschedule_nominal(cli_runner, complete_deposit, swh_scheduler): - """Rescheduling deposit with no load_task_id cannot work. - - """ + """Rescheduling deposit with no load_task_id cannot work.""" deposit = complete_deposit from swh.deposit.models import Deposit diff --git a/swh/deposit/tests/cli/test_client.py b/swh/deposit/tests/cli/test_client.py index fd753b7d5607a58edadfc4267a7f46de66ae99b4..a169960174ad04455267388ce52eb4b9272f2032 100644 --- a/swh/deposit/tests/cli/test_client.py +++ b/swh/deposit/tests/cli/test_client.py @@ -36,9 +36,7 @@ from ..conftest import TEST_USER def generate_slug() -> str: - """Generate a slug (sample purposes). - - """ + """Generate a slug (sample purposes).""" import uuid return str(uuid.uuid4()) @@ -66,9 +64,7 @@ def patched_tmp_path(tmp_path, mocker): @pytest.fixture def client_mock_api_down(mocker, slug): - """A mock client whose connection with api fails due to maintenance issue - - """ + """A mock client whose connection with api fails due to maintenance issue""" mock_client = MagicMock() mocker.patch("swh.deposit.client.PublicApiDepositClient", return_value=mock_client) mock_client.service_document.side_effect = MaintenanceError( @@ -108,11 +104,13 @@ def test_cli_collection_ko_because_downtime(): def test_cli_upload_conflictual_flags( - datadir, requests_mock_datadir, cli_runner, atom_dataset, tmp_path, + datadir, + requests_mock_datadir, + cli_runner, + atom_dataset, + tmp_path, ): - """Post metadata-only deposit through cli with invalid swhid raises - - """ + """Post metadata-only deposit through cli with invalid swhid raises""" api_url_basename = "deposit.test.metadataonly" metadata = atom_dataset["entry-data-minimal"] metadata_path = os.path.join(tmp_path, "entry-data-minimal.xml") @@ -141,9 +139,7 @@ def test_cli_upload_conflictual_flags( def test_cli_deposit_with_server_down_for_maintenance( sample_archive, caplog, client_mock_api_down, slug, patched_tmp_path, cli_runner ): - """ Deposit failure due to maintenance down time should be explicit - - """ + """Deposit failure due to maintenance down time should be explicit""" # fmt: off result = cli_runner.invoke( cli, @@ -172,9 +168,7 @@ def test_cli_deposit_with_server_down_for_maintenance( def test_cli_client_generate_metadata_ok(slug): - """Generated metadata is well formed and pass service side metadata checks - - """ + """Generated metadata is well formed and pass service side metadata checks""" actual_metadata_xml = generate_metadata( "deposit-client", "project-name", @@ -227,11 +221,11 @@ def test_cli_client_generate_metadata_ok(slug): def test_cli_client_generate_metadata_ok2(slug): - """Generated metadata is well formed and pass service side metadata checks - - """ + """Generated metadata is well formed and pass service side metadata checks""" actual_metadata_xml = generate_metadata( - "deposit-client", "project-name", authors=["some", "authors"], + "deposit-client", + "project-name", + authors=["some", "authors"], ) actual_metadata = parse_xml(actual_metadata_xml) @@ -267,9 +261,14 @@ def test_cli_client_generate_metadata_ok2(slug): def test_cli_single_minimal_deposit_with_slug( - sample_archive, slug, patched_tmp_path, requests_mock_datadir, cli_runner, caplog, + sample_archive, + slug, + patched_tmp_path, + requests_mock_datadir, + cli_runner, + caplog, ): - """ This ensure a single deposit upload through the cli is fine, cf. + """This ensure a single deposit upload through the cli is fine, cf. https://docs.softwareheritage.org/devel/swh-deposit/getting-started.html#single-deposit """ # noqa @@ -337,9 +336,14 @@ def test_cli_single_minimal_deposit_with_slug( def test_cli_single_minimal_deposit_with_create_origin( - sample_archive, slug, patched_tmp_path, requests_mock_datadir, cli_runner, caplog, + sample_archive, + slug, + patched_tmp_path, + requests_mock_datadir, + cli_runner, + caplog, ): - """ This ensure a single deposit upload through the cli is fine, cf. + """This ensure a single deposit upload through the cli is fine, cf. https://docs.softwareheritage.org/devel/swh-deposit/getting-started.html#single-deposit """ # noqa @@ -419,9 +423,7 @@ def test_cli_single_minimal_deposit_with_create_origin( def test_cli_validation_metadata( sample_archive, caplog, patched_tmp_path, cli_runner, slug ): - """Multiple metadata flags scenario (missing, conflicts) properly fails the calls - - """ + """Multiple metadata flags scenario (missing, conflicts) properly fails the calls""" metadata_path = os.path.join(patched_tmp_path, "metadata.xml") with open(metadata_path, "a"): @@ -532,9 +534,7 @@ def test_cli_validation_metadata( def test_cli_validation_no_actionable_command(caplog, cli_runner): - """Multiple metadata flags scenario (missing, conflicts) properly fails the calls - - """ + """Multiple metadata flags scenario (missing, conflicts) properly fails the calls""" # no actionable command # fmt: off result = cli_runner.invoke( @@ -565,9 +565,7 @@ def test_cli_validation_no_actionable_command(caplog, cli_runner): def test_cli_validation_replace_with_no_deposit_id_fails( sample_archive, caplog, patched_tmp_path, requests_mock_datadir, datadir, cli_runner ): - """--replace flags require --deposit-id otherwise fails - - """ + """--replace flags require --deposit-id otherwise fails""" metadata_path = os.path.join(datadir, "atom", "entry-data-deposit-binary.xml") # fmt: off @@ -637,7 +635,7 @@ def test_cli_single_deposit_slug_generation( def test_cli_multisteps_deposit( sample_archive, datadir, slug, requests_mock_datadir, cli_runner ): - """ First deposit a partial deposit (no metadata, only archive), then update the metadata part. + """First deposit a partial deposit (no metadata, only archive), then update the metadata part. https://docs.softwareheritage.org/devel/swh-deposit/getting-started.html#multisteps-deposit """ # noqa api_url = "https://deposit.test.metadata/1" @@ -739,9 +737,7 @@ def test_cli_multisteps_deposit( def test_cli_deposit_status_with_output_format( output_format, parser_fn, datadir, slug, requests_mock_datadir, caplog, cli_runner ): - """Check deposit status cli with all possible output formats (json, yaml, logging). - - """ + """Check deposit status cli with all possible output formats (json, yaml, logging).""" api_url_basename = "deposit.test.status" deposit_id = 1033 expected_deposit_status = { @@ -785,8 +781,7 @@ def test_cli_deposit_status_with_output_format( def test_cli_update_metadata_with_swhid_on_completed_deposit( datadir, requests_mock_datadir, cli_runner ): - """Update new metadata on a completed deposit (status done) is ok - """ + """Update new metadata on a completed deposit (status done) is ok""" api_url_basename = "deposit.test.updateswhid" deposit_id = 123 expected_deposit_status = { @@ -829,8 +824,7 @@ def test_cli_update_metadata_with_swhid_on_completed_deposit( def test_cli_update_metadata_with_swhid_on_other_status_deposit( datadir, requests_mock_datadir, cli_runner ): - """Update new metadata with swhid on other deposit status is not possible - """ + """Update new metadata with swhid on other deposit status is not possible""" api_url_basename = "deposit.test.updateswhid" deposit_id = "321" @@ -935,11 +929,13 @@ def test_cli_metadata_only_deposit_full_metadata_file( def test_cli_metadata_only_deposit_invalid_swhid( - datadir, requests_mock_datadir, cli_runner, atom_dataset, tmp_path, + datadir, + requests_mock_datadir, + cli_runner, + atom_dataset, + tmp_path, ): - """Post metadata-only deposit through cli with invalid swhid raises - - """ + """Post metadata-only deposit through cli with invalid swhid raises""" api_url_basename = "deposit.test.metadataonly" invalid_swhid = "ssh:2:sth:xxx" metadata = atom_dataset["entry-data-with-swhid-no-prov"].format(swhid=invalid_swhid) @@ -965,11 +961,13 @@ def test_cli_metadata_only_deposit_invalid_swhid( def test_cli_metadata_only_deposit_no_swhid( - datadir, requests_mock_datadir, cli_runner, atom_dataset, tmp_path, + datadir, + requests_mock_datadir, + cli_runner, + atom_dataset, + tmp_path, ): - """Post metadata-only deposit through cli with invalid swhid raises - - """ + """Post metadata-only deposit through cli with invalid swhid raises""" api_url_basename = "deposit.test.metadataonly" metadata = atom_dataset["entry-data-minimal"] metadata_path = os.path.join(tmp_path, "entry-data-minimal.xml") @@ -1004,9 +1002,7 @@ def test_cli_deposit_warning_missing_origin( cli_runner, requests_mock_datadir, ): - """Deposit cli should warn when provided metadata xml is missing 'origins' tags - - """ + """Deposit cli should warn when provided metadata xml is missing 'origins' tags""" # For the next deposit, no warning should be logged as either <swh:create_origin> or # <swh:origin_to_add> are provided, and <swh:metadata-provenance-url> is always # provided. @@ -1035,11 +1031,13 @@ def test_cli_deposit_warning_missing_origin( def test_cli_deposit_warning_missing_provenance_url( - tmp_path, atom_dataset, caplog, cli_runner, requests_mock_datadir, + tmp_path, + atom_dataset, + caplog, + cli_runner, + requests_mock_datadir, ): - """Deposit cli should warn when no metadata provenance is provided - - """ + """Deposit cli should warn when no metadata provenance is provided""" atom_template = atom_dataset["entry-data-with-add-to-origin-no-prov"] raw_metadata = atom_template % "some-url" metadata_path = os.path.join(tmp_path, "metadata-with-missing-prov-url.xml") @@ -1088,9 +1086,7 @@ def test_cli_failure_should_be_parseable(atom_dataset, mocker): def test_cli_service_document_failure(atom_dataset, mocker): - """Ensure service document failures are properly served - - """ + """Ensure service document failures are properly served""" summary = "Invalid user credentials" error_xml = atom_dataset["error-cli"].format(summary=summary, verboseDescription="") @@ -1115,9 +1111,7 @@ def test_cli_service_document_failure(atom_dataset, mocker): def test_cli_deposit_collection_list( output_format, parser_fn, datadir, slug, requests_mock_datadir, caplog, cli_runner ): - """Check deposit status cli with all possible output formats (json, yaml, logging). - - """ + """Check deposit status cli with all possible output formats (json, yaml, logging).""" api_url_basename = "deposit.test.list" expected_deposits = { diff --git a/swh/deposit/tests/common.py b/swh/deposit/tests/common.py index 2e9008e0052c3135745386ed953b6012257a2fa7..2651f1584dfbe117e1738b36de80ae502c96bdb0 100644 --- a/swh/deposit/tests/common.py +++ b/swh/deposit/tests/common.py @@ -16,9 +16,7 @@ from swh.core import tarball def compute_info(archive_path): - """Given a path, compute information on path. - - """ + """Given a path, compute information on path.""" with open(archive_path, "rb") as f: length = 0 sha1sum = hashlib.sha1() @@ -42,9 +40,7 @@ def compute_info(archive_path): def _compress(path, extension, dir_path): - """Compress path according to extension - - """ + """Compress path according to extension""" if extension == "zip" or extension == "tar": return tarball.compress(path, extension, dir_path) elif "." in extension: @@ -118,9 +114,7 @@ def create_arborescence_archive( def create_archive_with_archive(root_path, name, archive): - """Create an archive holding another. - - """ + """Create an archive holding another.""" invalid_archive_path = os.path.join(root_path, name) with tarfile.open(invalid_archive_path, "w:gz") as _archive: _archive.add(archive["path"], arcname=archive["name"]) @@ -157,7 +151,12 @@ def _post_or_put_archive(f, url, archive, slug=None, in_progress=None, **kwargs) HTTP_PACKAGING="http://purl.org/net/sword/package/SimpleZip", ) kwargs = {**default_kwargs, **kwargs} - return f(url, data=archive["data"], HTTP_CONTENT_MD5=archive["md5sum"], **kwargs,) + return f( + url, + data=archive["data"], + HTTP_CONTENT_MD5=archive["md5sum"], + **kwargs, + ) def post_archive(authenticated_client, *args, **kwargs): @@ -202,7 +201,10 @@ def _post_or_put_multipart(f, url, archive, atom_entry, **kwargs): return f( url, format="multipart", - data={"archive": archive, "atom_entry": atom_entry,}, + data={ + "archive": archive, + "atom_entry": atom_entry, + }, **kwargs, ) diff --git a/swh/deposit/tests/conftest.py b/swh/deposit/tests/conftest.py index 04fae35e74f053af2496512245662501b57fb899..be3b947ff9d9ad9e967a8582a15f2b8920a441c5 100644 --- a/swh/deposit/tests/conftest.py +++ b/swh/deposit/tests/conftest.py @@ -118,9 +118,7 @@ def pytest_configure(): @pytest.fixture def requests_mock_datadir(datadir, requests_mock_datadir): - """Override default behavior to deal with put/post methods - - """ + """Override default behavior to deal with put/post methods""" cb = partial(get_response_cb, datadir=datadir) requests_mock_datadir.put(re.compile("https://"), body=cb) requests_mock_datadir.post(re.compile("https://"), body=cb) @@ -133,7 +131,10 @@ def common_deposit_config(swh_scheduler_config, swh_storage_backend_config): "max_upload_size": 5000, "extraction_dir": "/tmp/swh-deposit/test/extraction-dir", "checks": False, - "scheduler": {"cls": "local", **swh_scheduler_config,}, + "scheduler": { + "cls": "local", + **swh_scheduler_config, + }, "storage": swh_storage_backend_config, "storage_metadata": swh_storage_backend_config, "swh_authority_url": "http://deposit.softwareheritage.example/", @@ -218,7 +219,7 @@ def execute_sql(sql): @pytest.fixture(autouse=True, scope="session") def swh_proxy(): """Automatically inject this fixture in all tests to ensure no outside - connection takes place. + connection takes place. """ os.environ["http_proxy"] = "http://localhost:999" @@ -226,9 +227,7 @@ def swh_proxy(): def create_deposit_collection(collection_name: str): - """Create a deposit collection with name collection_name - - """ + """Create a deposit collection with name collection_name""" from swh.deposit.models import DepositCollection try: @@ -288,16 +287,12 @@ def deposit_another_user(db, deposit_another_collection): @pytest.fixture def anonymous_client(): - """Create an anonymous client (no credentials during queries to the deposit) - - """ + """Create an anonymous client (no credentials during queries to the deposit)""" return APIClient() # <- drf's client def mock_keycloakopenidconnect(mocker, keycloak_mock): - """Mock swh.deposit.auth.KeycloakOpenIDConnect to return the keycloak_mock - - """ + """Mock swh.deposit.auth.KeycloakOpenIDConnect to return the keycloak_mock""" mock = mocker.patch("swh.deposit.auth.KeycloakOpenIDConnect") mock.from_configfile.return_value = keycloak_mock return mock @@ -306,7 +301,7 @@ def mock_keycloakopenidconnect(mocker, keycloak_mock): @pytest.fixture def mock_keycloakopenidconnect_ok(mocker, keycloak_mock_auth_success): """Mock keycloak so it always accepts connection for user with the right - permissions + permissions """ return mock_keycloakopenidconnect(mocker, keycloak_mock_auth_success) @@ -350,9 +345,7 @@ def authenticated_client(mock_keycloakopenidconnect_ok, anonymous_client, deposi @pytest.fixture def unauthorized_client(mock_keycloakopenidconnect_ko, anonymous_client, deposit_user): - """Create an unauthorized client (will see their authentication fail) - - """ + """Create an unauthorized client (will see their authentication fail)""" yield from _create_authenticated_client(anonymous_client, deposit_user) @@ -361,7 +354,7 @@ def insufficient_perm_client( mocker, keycloak_mock_auth_success, anonymous_client, deposit_user ): """keycloak accepts connection but client returned has no deposit permission, so access - is not allowed. + is not allowed. """ keycloak_mock_auth_success.client_permissions = [] @@ -371,9 +364,7 @@ def insufficient_perm_client( @pytest.fixture def sample_archive(tmp_path): - """Returns a sample archive - - """ + """Returns a sample archive""" tmp_path = str(tmp_path) # pytest version limitation in previous version archive = create_arborescence_archive( tmp_path, "archive1", "file1", b"some content in file" @@ -410,9 +401,7 @@ def internal_create_deposit( external_id: str, status: str, ) -> "Deposit": - """Create a deposit for a given collection with internal tool - - """ + """Create a deposit for a given collection with internal tool""" from swh.deposit.models import Deposit deposit = Deposit( @@ -430,9 +419,7 @@ def create_deposit( deposit_status=DEPOSIT_STATUS_DEPOSITED, in_progress=False, ): - """Create a skeleton shell deposit - - """ + """Create a skeleton shell deposit""" url = reverse(COL_IRI, args=[collection_name]) # when response = post_archive( @@ -468,7 +455,7 @@ def create_binary_deposit( **kwargs, ): """Create a deposit with both metadata and archive set. Then alters its status - to `deposit_status`. + to `deposit_status`. """ deposit = create_deposit( @@ -499,9 +486,7 @@ def create_binary_deposit( def deposit_factory(deposit_status=DEPOSIT_STATUS_DEPOSITED, in_progress=False): - """Build deposit with a specific status - - """ + """Build deposit with a specific status""" @pytest.fixture() def _deposit( @@ -537,9 +522,7 @@ failed_deposit = deposit_factory(deposit_status=DEPOSIT_STATUS_LOAD_FAILURE) def partial_deposit_with_metadata( sample_archive, deposit_collection, authenticated_client, atom_dataset ): - """Returns deposit with archive and metadata provided, status 'partial' - - """ + """Returns deposit with archive and metadata provided, status 'partial'""" return create_binary_deposit( authenticated_client, deposit_collection.name, @@ -577,9 +560,7 @@ def partial_deposit_only_metadata( @pytest.fixture def complete_deposit(sample_archive, deposit_collection, authenticated_client): - """Returns a completed deposit (load success) - - """ + """Returns a completed deposit (load success)""" deposit = create_deposit( authenticated_client, deposit_collection.name, diff --git a/swh/deposit/tests/loader/common.py b/swh/deposit/tests/loader/common.py index fd466f0cfe4d2c4b72f01220e243f4e5fc3c2381..942429bac5c5a7d60c97697e1061b2e53faa346d 100644 --- a/swh/deposit/tests/loader/common.py +++ b/swh/deposit/tests/loader/common.py @@ -19,7 +19,7 @@ CLIENT_TEST_CONFIG = { class SWHDepositTestClient(PrivateApiDepositClient): """Deposit test client to permit overriding the default request - client. + client. """ @@ -66,7 +66,7 @@ class SWHDepositTestClient(PrivateApiDepositClient): def get_stats(storage) -> Dict: """Adaptation utils to unify the stats counters across storage - implementation. + implementation. """ storage.refresh_stat_counters() @@ -87,9 +87,7 @@ def get_stats(storage) -> Dict: def decode_target(branch: Optional[SnapshotBranch]) -> Optional[Dict]: - """Test helper to ease readability in test - - """ + """Test helper to ease readability in test""" if not branch: return None target_type = branch.target_type diff --git a/swh/deposit/tests/loader/test_checker.py b/swh/deposit/tests/loader/test_checker.py index 60d451efa7ce206b325c8e7b934b5465d31b6ed0..56189517035cd0d633e5537519d3c717ec1d2a69 100644 --- a/swh/deposit/tests/loader/test_checker.py +++ b/swh/deposit/tests/loader/test_checker.py @@ -7,26 +7,20 @@ from unittest.mock import patch def test_checker_deposit_ready(requests_mock_datadir, deposit_checker): - """Check on a valid 'deposited' deposit should result in 'verified' - - """ + """Check on a valid 'deposited' deposit should result in 'verified'""" actual_result = deposit_checker.check(collection="test", deposit_id=1) assert actual_result == {"status": "eventful"} def test_checker_deposit_rejected(requests_mock_datadir, deposit_checker): - """Check on invalid 'deposited' deposit should result in 'rejected' - - """ + """Check on invalid 'deposited' deposit should result in 'rejected'""" actual_result = deposit_checker.check(collection="test", deposit_id=2) assert actual_result == {"status": "failed"} @patch("swh.deposit.client.requests.get") def test_checker_deposit_rejected_exception(mock_requests, deposit_checker): - """Check on invalid 'deposited' deposit should result in 'rejected' - - """ + """Check on invalid 'deposited' deposit should result in 'rejected'""" mock_requests.side_effect = ValueError("simulated problem when checking") actual_result = deposit_checker.check(collection="test", deposit_id=3) assert actual_result == {"status": "failed"} diff --git a/swh/deposit/tests/loader/test_client.py b/swh/deposit/tests/loader/test_client.py index 7745a009a3104f47b9420f613b00fac8c9763d97..e9949f016c3e322ce26af77f7833e15d9a1e9079 100644 --- a/swh/deposit/tests/loader/test_client.py +++ b/swh/deposit/tests/loader/test_client.py @@ -37,9 +37,7 @@ def test_client_config(deposit_config_path): def build_expected_path(datadir, base_url: str, api_url: str) -> str: - """Build expected path from api to served file - - """ + """Build expected path from api to served file""" url = urlparse(base_url) dirname = "%s_%s" % (url.scheme, url.hostname) if api_url.endswith("/"): @@ -62,9 +60,7 @@ def read_served_path( api_url: str, convert_fn: Optional[Callable[[str], Any]] = None, ) -> bytes: - """Read served path - - """ + """Read served path""" archive_path = build_expected_path(datadir, base_url, api_url) with open(archive_path, "rb") as f: content = f.read() @@ -89,9 +85,7 @@ def test_read_served_path(datadir): def test_archive_get(tmp_path, datadir, requests_mock_datadir): - """Retrieving archive data through private api should stream data - - """ + """Retrieving archive data through private api should stream data""" api_url = "/1/private/test/1/raw/" client = PrivateApiDepositClient(CLIENT_TEST_CONFIG) @@ -111,9 +105,7 @@ def test_archive_get(tmp_path, datadir, requests_mock_datadir): def test_archive_get_auth(tmp_path, datadir, requests_mock_datadir): - """Retrieving archive data through private api should stream data - - """ + """Retrieving archive data through private api should stream data""" api_url = "/1/private/test/1/raw/" config = CLIENT_TEST_CONFIG.copy() config["auth"] = { # add authentication setup @@ -138,9 +130,7 @@ def test_archive_get_auth(tmp_path, datadir, requests_mock_datadir): def test_archive_get_ko(tmp_path, datadir, requests_mock_datadir): - """Reading archive can fail for some reasons - - """ + """Reading archive can fail for some reasons""" unknown_api_url = "/1/private/unknown/deposit-id/raw/" client = PrivateApiDepositClient(config=CLIENT_TEST_CONFIG) @@ -152,9 +142,7 @@ def test_archive_get_ko(tmp_path, datadir, requests_mock_datadir): def test_metadata_get(datadir, requests_mock_datadir): - """Reading archive should write data in temporary directory - - """ + """Reading archive should write data in temporary directory""" api_url = "/1/private/test/1/metadata" client = PrivateApiDepositClient(config=CLIENT_TEST_CONFIG) actual_metadata = client.metadata_get(api_url) @@ -167,9 +155,7 @@ def test_metadata_get(datadir, requests_mock_datadir): def test_metadata_get_ko(requests_mock_datadir): - """Reading metadata can fail for some reasons - - """ + """Reading metadata can fail for some reasons""" unknown_api_url = "/1/private/unknown/deposit-id/metadata/" client = PrivateApiDepositClient(config=CLIENT_TEST_CONFIG) @@ -181,9 +167,7 @@ def test_metadata_get_ko(requests_mock_datadir): def test_check(requests_mock_datadir): - """When check ok, this should return the deposit's status - - """ + """When check ok, this should return the deposit's status""" api_url = "/1/private/test/1/check" client = PrivateApiDepositClient(config=CLIENT_TEST_CONFIG) @@ -192,9 +176,7 @@ def test_check(requests_mock_datadir): def test_check_fails(requests_mock_datadir): - """Checking deposit can fail for some reason - - """ + """Checking deposit can fail for some reason""" unknown_api_url = "/1/private/test/10/check" client = PrivateApiDepositClient(config=CLIENT_TEST_CONFIG) @@ -206,9 +188,7 @@ def test_check_fails(requests_mock_datadir): def test_status_update(mocker): - """Update status - - """ + """Update status""" mocked_put = mocker.patch.object(Session, "request") deposit_client = PrivateApiDepositClient(config=CLIENT_TEST_CONFIG) @@ -231,9 +211,7 @@ def test_status_update(mocker): def test_status_update_with_no_release_id(mocker): - """Reading metadata can fail for some reasons - - """ + """Reading metadata can fail for some reasons""" mocked_put = mocker.patch.object(Session, "request") deposit_client = PrivateApiDepositClient(config=CLIENT_TEST_CONFIG) @@ -242,5 +220,7 @@ def test_status_update_with_no_release_id(mocker): mocked_put.assert_called_once_with( "put", "https://nowhere.org/update/status/fail", - json={"status": DEPOSIT_STATUS_LOAD_FAILURE,}, + json={ + "status": DEPOSIT_STATUS_LOAD_FAILURE, + }, ) diff --git a/swh/deposit/tests/loader/test_tasks.py b/swh/deposit/tests/loader/test_tasks.py index 5f85ebcd1bfb1874d6de0d87dc1f955014c7a282..068444d4b63f4d153a549e527cf3f12e29ceda9d 100644 --- a/swh/deposit/tests/loader/test_tasks.py +++ b/swh/deposit/tests/loader/test_tasks.py @@ -10,9 +10,7 @@ import pytest def test_task_check_eventful( mocker, deposit_config_path, swh_scheduler_celery_app, swh_scheduler_celery_worker ): - """Successful check should make the check succeed - - """ + """Successful check should make the check succeed""" client = mocker.patch("swh.deposit.loader.checker.PrivateApiDepositClient.check") client.return_value = "verified" @@ -33,9 +31,7 @@ def test_task_check_eventful( def test_task_check_failure( mocker, deposit_config_path, swh_scheduler_celery_app, swh_scheduler_celery_worker ): - """Unverified check status should make the check fail - - """ + """Unverified check status should make the check fail""" client = mocker.patch("swh.deposit.loader.checker.PrivateApiDepositClient.check") client.return_value = "not-verified" # will make the status "failed" @@ -56,9 +52,7 @@ def test_task_check_failure( def test_task_check_3( mocker, deposit_config_path, swh_scheduler_celery_app, swh_scheduler_celery_worker ): - """Unexpected failures should fail the check - - """ + """Unexpected failures should fail the check""" client = mocker.patch("swh.deposit.loader.checker.PrivateApiDepositClient.check") client.side_effect = ValueError("unexpected failure will make it fail") diff --git a/swh/deposit/tests/test_backend.py b/swh/deposit/tests/test_backend.py index ca31d40a19cbc143aad2c007db98d01e27f06ba9..b647ea78b0608369f55a35553f86297c06da521f 100644 --- a/swh/deposit/tests/test_backend.py +++ b/swh/deposit/tests/test_backend.py @@ -52,9 +52,7 @@ def test_backend_authentication_user_inactive(backend_success, deposit_user): def test_backend_authentication_ok(backend_success, deposit_user): - """Keycloak configured ok, backend db configured ok, user logs in - - """ + """Keycloak configured ok, backend db configured ok, user logs in""" user0, _ = backend_success.authenticate_credentials( deposit_user.username, PASSWORD, REQUEST_OBJECT ) diff --git a/swh/deposit/tests/test_client_module.py b/swh/deposit/tests/test_client_module.py index b6a5f9f06d0e97cd8f4d76d33bf45dfc032795eb..d52b2c797f7c43e0c8bdb219623ecf57de4a6f1c 100644 --- a/swh/deposit/tests/test_client_module.py +++ b/swh/deposit/tests/test_client_module.py @@ -62,7 +62,8 @@ def test_client_read_data_no_result(requests_mock): def test_client_read_data_collection_error_503(requests_mock, atom_dataset): error_content = atom_dataset["error-cli"].format( - summary="forbidden", verboseDescription="Access restricted", + summary="forbidden", + verboseDescription="Access restricted", ) url = "https://deposit.swh.test/1" requests_mock.get(f"{url}/servicedocument/", status_code=503, text=error_content) @@ -82,7 +83,8 @@ def test_client_read_data_collection_error_503(requests_mock, atom_dataset): def test_client_read_data_status_error_503(requests_mock, atom_dataset): error_content = atom_dataset["error-cli"].format( - summary="forbidden", verboseDescription="Access restricted", + summary="forbidden", + verboseDescription="Access restricted", ) collection = "test" deposit_id = 1 @@ -172,13 +174,17 @@ def test_client_collection_list_with_pagination_headers(requests_mock, atom_data url_page1, status_code=200, text=collection_list_xml_page1, - headers={"Link": to_header_link(url_page2, "next"),}, + headers={ + "Link": to_header_link(url_page2, "next"), + }, ) requests_mock.get( url_page2, status_code=200, text=collection_list_xml_page2, - headers={"Link": to_header_link(url_page1, "previous"),}, + headers={ + "Link": to_header_link(url_page1, "previous"), + }, ) expected_result_page1 = { diff --git a/swh/deposit/tests/test_gunicorn_config.py b/swh/deposit/tests/test_gunicorn_config.py index 48fc5d61246d794afe6f52a13e813c5cfb599038..5f522a7bb8b52f05c5454666b1e1ee6b5298a52c 100644 --- a/swh/deposit/tests/test_gunicorn_config.py +++ b/swh/deposit/tests/test_gunicorn_config.py @@ -24,7 +24,10 @@ def test_post_fork_with_dsn_env(): with patch("sentry_sdk.init") as sentry_sdk_init: with patch.dict( os.environ, - {"SWH_SENTRY_DSN": "test_dsn", "SWH_SENTRY_ENVIRONMENT": "test",}, + { + "SWH_SENTRY_DSN": "test_dsn", + "SWH_SENTRY_ENVIRONMENT": "test", + }, ): gunicorn_config.post_fork(None, None) diff --git a/swh/deposit/tests/test_migrations.py b/swh/deposit/tests/test_migrations.py index 0fb97ce9351d8f1c39ab6011cd5725e8edcacc7e..9565f0a8a4fab54e9a599750b5a9738bed7945ce 100644 --- a/swh/deposit/tests/test_migrations.py +++ b/swh/deposit/tests/test_migrations.py @@ -96,7 +96,8 @@ def test_migrations_22_add_deposit_type_column_model_and_data(migrator): client_id=client.id, collection_id=collection.id, swhid=CoreSWHID( - object_type=ObjectType.DIRECTORY, object_id=hash_to_bytes(directory_id), + object_type=ObjectType.DIRECTORY, + object_id=hash_to_bytes(directory_id), ), swhid_context=QualifiedSWHID( object_type=ObjectType.DIRECTORY, diff --git a/swh/deposit/tests/test_utils.py b/swh/deposit/tests/test_utils.py index 91ff6be2e1bd71d41134c22e9faae8a4f6ebaa24..8c56bbec2f18dbc10f874a662c4e84504694d384 100644 --- a/swh/deposit/tests/test_utils.py +++ b/swh/deposit/tests/test_utils.py @@ -29,8 +29,7 @@ def xml_with_origin_reference(): def test_normalize_date_0(): - """When date is a list, choose the first date and normalize it - """ + """When date is a list, choose the first date and normalize it""" actual_date = utils.normalize_date(["2017-10-12", "date1"]) assert actual_date == { @@ -40,8 +39,7 @@ def test_normalize_date_0(): def test_normalize_date_1(): - """Providing a date in a reasonable format, everything is fine - """ + """Providing a date in a reasonable format, everything is fine""" actual_date = utils.normalize_date("2018-06-11 17:02:02") assert actual_date == { @@ -51,8 +49,7 @@ def test_normalize_date_1(): def test_normalize_date_doing_irrelevant_stuff(): - """Providing a date with only the year results in a reasonable date - """ + """Providing a date with only the year results in a reasonable date""" actual_date = utils.normalize_date("2017") assert actual_date == { @@ -64,7 +61,10 @@ def test_normalize_date_doing_irrelevant_stuff(): @pytest.mark.parametrize( "swhid,expected_metadata_context", [ - ("swh:1:cnt:51b5c8cc985d190b5a7ef4878128ebfdc2358f49", {"origin": None},), + ( + "swh:1:cnt:51b5c8cc985d190b5a7ef4878128ebfdc2358f49", + {"origin": None}, + ), ( "swh:1:snp:51b5c8cc985d190b5a7ef4878128ebfdc2358f49;origin=http://blah", {"origin": "http://blah", "path": None}, @@ -156,7 +156,9 @@ def xml_with_swhid(atom_dataset): ], ) def test_parse_swh_reference_swhid(swhid, xml_with_swhid): - xml_data = xml_with_swhid.format(swhid=swhid,) + xml_data = xml_with_swhid.format( + swhid=swhid, + ) metadata = ElementTree.fromstring(xml_data) actual_swhid = utils.parse_swh_reference(metadata) @@ -179,9 +181,7 @@ def test_parse_swh_reference_swhid(swhid, xml_with_swhid): ], ) def test_parse_swh_reference_invalid_swhid(invalid_swhid, xml_with_swhid): - """Unparsable swhid should raise - - """ + """Unparsable swhid should raise""" xml_invalid_swhid = xml_with_swhid.format(swhid=invalid_swhid) metadata = ElementTree.fromstring(xml_invalid_swhid) diff --git a/swh/deposit/utils.py b/swh/deposit/utils.py index 7b6b5cab71bbdfcaa9c413752ac649a2635e0d37..772cc9550236b8d73166728b59eb9044062d9a8f 100644 --- a/swh/deposit/utils.py +++ b/swh/deposit/utils.py @@ -57,9 +57,7 @@ def normalize_date(date): def compute_metadata_context(swhid_reference: QualifiedSWHID) -> Dict[str, Any]: - """Given a SWHID object, determine the context as a dict. - - """ + """Given a SWHID object, determine the context as a dict.""" metadata_context: Dict[str, Any] = {"origin": None} if swhid_reference.qualifiers(): metadata_context = { @@ -85,7 +83,9 @@ ALLOWED_QUALIFIERS_NODE_TYPE = ( ) -def parse_swh_metadata_provenance(metadata: ElementTree.Element,) -> Optional[str]: +def parse_swh_metadata_provenance( + metadata: ElementTree.Element, +) -> Optional[str]: """Parse swh metadata-provenance within the metadata dict reference if found, None otherwise.