From c6e790d1d9749f4aa4265e8dfbf0631e5ce2a9d4 Mon Sep 17 00:00:00 2001 From: Evgenia Lyjina Date: Fri, 4 Mar 2022 13:13:49 +0000 Subject: [PATCH] Fix private methods names with underscore --- metadata_backend/api/handlers/object.py | 24 ++++++++++++------------ tests/test_handlers.py | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/metadata_backend/api/handlers/object.py b/metadata_backend/api/handlers/object.py index 699c20f23..7fb25b1c7 100644 --- a/metadata_backend/api/handlers/object.py +++ b/metadata_backend/api/handlers/object.py @@ -164,12 +164,12 @@ async def post_object(self, req: Request) -> Response: if not isinstance(data, List): objects = [json_data] folder_op = FolderOperator(db_client) - patch = self.prepare_folder_patch_new_object(collection, objects, patch_params) + patch = self._prepare_folder_patch_new_object(collection, objects, patch_params) await folder_op.update_folder(folder_id, patch) # Create draft dataset to Metax catalog if collection in {"study", "dataset"}: - [await self.create_metax_dataset(req, collection, item) for item in objects] + [await self._create_metax_dataset(req, collection, item) for item in objects] body = ujson.dumps(data, escape_forward_slashes=False) @@ -237,7 +237,7 @@ async def delete_object(self, req: Request) -> Response: # Delete draft dataset from Metax catalog if collection in {"study", "dataset"}: - await self.delete_metax_dataset(req, metax_id) + await self._delete_metax_dataset(req, metax_id) LOG.info(f"DELETE object with accession ID {accession_id} in schema {collection} was successful.") return web.Response(status=204) @@ -286,12 +286,12 @@ async def put_object(self, req: Request) -> Response: raise web.HTTPUnauthorized(reason=reason) data = await operator.replace_metadata_object(collection, accession_id, content) - patch = self.prepare_folder_patch_update_object(collection, data, filename) + patch = self._prepare_folder_patch_update_object(collection, data, filename) await folder_op.update_folder(folder_id, patch) # Update draft dataset to Metax catalog if collection in {"study", "dataset"}: - await self.update_metax_dataset(req, collection, accession_id) + await self._update_metax_dataset(req, collection, accession_id) body = ujson.dumps({"accessionId": accession_id}, escape_forward_slashes=False) LOG.info(f"PUT object with accession ID {accession_id} in schema {collection} was successful.") @@ -337,20 +337,20 @@ async def patch_object(self, req: Request) -> Response: # If there's changed title it will be updated to folder try: _ = content["descriptor"]["studyTitle"] if collection == "study" else content["title"] - patch = self.prepare_folder_patch_update_object(collection, content) + patch = self._prepare_folder_patch_update_object(collection, content) await folder_op.update_folder(folder_id, patch) except (TypeError, KeyError): pass # Update draft dataset to Metax catalog if collection in {"study", "dataset"}: - await self.update_metax_dataset(req, collection, accession_id) + await self._update_metax_dataset(req, collection, accession_id) body = ujson.dumps({"accessionId": accession_id}, escape_forward_slashes=False) LOG.info(f"PATCH object with accession ID {accession_id} in schema {collection} was successful.") return web.Response(body=body, status=200, content_type="application/json") - def prepare_folder_patch_new_object(self, schema: str, objects: List, params: Dict[str, str]) -> List: + def _prepare_folder_patch_new_object(self, schema: str, objects: List, params: Dict[str, str]) -> List: """Prepare patch operations list for adding an object or objects to a folder. :param schema: schema of objects to be added to the folder @@ -393,7 +393,7 @@ def prepare_folder_patch_new_object(self, schema: str, objects: List, params: Di patch.append(patch_ops) return patch - def prepare_folder_patch_update_object(self, schema: str, data: Dict, filename: str = "") -> List: + def _prepare_folder_patch_update_object(self, schema: str, data: Dict, filename: str = "") -> List: """Prepare patch operation for updating object's title in a folder. :param schema: schema of object to be updated @@ -432,7 +432,7 @@ def prepare_folder_patch_update_object(self, schema: str, data: Dict, filename: return [patch_op] # TODO: update doi related code - async def create_metax_dataset(self, req: Request, collection: str, object: Dict) -> str: + async def _create_metax_dataset(self, req: Request, collection: str, object: Dict) -> str: """Handle connection to Metax api handler. Sends Dataset or Study object's data to Metax api handler. @@ -459,7 +459,7 @@ async def create_metax_dataset(self, req: Request, collection: str, object: Dict return metax_id # TODO: update doi related code - async def update_metax_dataset(self, req: Request, collection: str, accession_id: str) -> str: + async def _update_metax_dataset(self, req: Request, collection: str, accession_id: str) -> str: """Handle connection to Metax api handler. Sends Dataset or Study object's data to Metax api handler. @@ -483,7 +483,7 @@ async def update_metax_dataset(self, req: Request, collection: str, accession_id raise ValueError("Object's data must be dictionary") return metax_id - async def delete_metax_dataset(self, req: Request, metax_id: str) -> None: + async def _delete_metax_dataset(self, req: Request, metax_id: str) -> None: """Handle deletion of Study or Dataset object from Metax service. :param req: HTTP request diff --git a/tests/test_handlers.py b/tests/test_handlers.py index 5cde851f6..db914d760 100644 --- a/tests/test_handlers.py +++ b/tests/test_handlers.py @@ -105,7 +105,7 @@ async def setUpAsync(self): RESTAPIHandler._handle_check_ownedby_user = make_mocked_coro(True) ObjectAPIHandler.create_or_update_metax_dataset = make_mocked_coro("111-222-333") - ObjectAPIHandler.delete_metax_dataset = make_mocked_coro() + ObjectAPIHandler._delete_metax_dataset = make_mocked_coro() async def tearDownAsync(self): """Cleanup mocked stuff."""