Пример #1
0
 async def test_folder_object_remove_passes(self):
     """Test remove object method for folders works."""
     operator = FolderOperator(self.client)
     operator.db_service.remove.return_value = self.test_folder
     await operator.remove_object(self.test_folder, "study", self.accession_id)
     operator.db_service.remove.assert_called_once()
     self.assertEqual(len(operator.db_service.remove.mock_calls), 1)
Пример #2
0
 async def test_folder_update_fails_with_bad_patch(self):
     """Test folder update raises error with improper JSON Patch."""
     patch = [{"op": "replace", "path": "/nothing"}]
     operator = FolderOperator(self.client)
     operator.db_service.patch.return_value = False
     with self.assertRaises(HTTPBadRequest):
         await operator.update_folder(self.test_folder, patch)
Пример #3
0
 async def test_deleting_folder_passes(self):
     """Test folder is deleted correctly, if not published."""
     operator = FolderOperator(self.client)
     operator.db_service.published_folder.return_value = False
     operator.db_service.delete.return_value = True
     await operator.delete_folder(self.folder_id)
     operator.db_service.delete.assert_called_with("folder", self.folder_id)
Пример #4
0
 async def test_check_folder_exists_fails(self):
     """Test fails exists fails."""
     operator = FolderOperator(self.client)
     operator.db_service.exists.return_value = False
     with self.assertRaises(HTTPNotFound):
         await operator.check_folder_exists(self.folder_id)
         operator.db_service.exists.assert_called_once()
Пример #5
0
 async def test_query_folders_1_item(self):
     """Test query returns a list with item."""
     operator = FolderOperator(self.client)
     operator.db_service.query.return_value = AsyncIterator([{"name": "folder"}])
     folders = await operator.query_folders({})
     operator.db_service.query.assert_called_once()
     self.assertEqual(folders, [{"name": "folder"}])
Пример #6
0
 async def test_query_folders_empty_list(self):
     """Test query returns empty list."""
     operator = FolderOperator(self.client)
     operator.db_service.query.return_value = AsyncIterator([])
     folders = await operator.query_folders({})
     operator.db_service.query.assert_called_once()
     self.assertEqual(folders, [])
Пример #7
0
 async def test_create_folder_db_create_fails(self):
     """Test create method for folders db create fails."""
     operator = FolderOperator(self.client)
     data = {"name": "Mock folder", "description": "test mock folder"}
     operator.db_service.create.return_value = False
     with self.assertRaises(HTTPBadRequest):
         await operator.create_folder(data)
Пример #8
0
 async def test_create_folder_fails(self):
     """Test create method for folders fails."""
     operator = FolderOperator(self.client)
     data = {"name": "Mock folder", "description": "test mock folder"}
     operator.db_service.create.side_effect = ConnectionFailure
     with self.assertRaises(HTTPBadRequest):
         await operator.create_folder(data)
Пример #9
0
 async def test_reading_folder_works(self):
     """Test folder is read from db correctly."""
     operator = FolderOperator(self.client)
     operator.db_service.read.return_value = self.test_folder
     read_data = await operator.read_folder(self.folder_id)
     operator.db_service.read.assert_called_once_with("folder", self.folder_id)
     self.assertEqual(read_data, self.test_folder)
Пример #10
0
 async def test_create_folder_works_and_returns_folderId(self):
     """Test create method for folders work."""
     operator = FolderOperator(self.client)
     data = {"name": "Mock folder", "description": "test mock folder"}
     operator.db_service.create.return_value = True
     folder = await operator.create_folder(data)
     operator.db_service.create.assert_called_once()
     self.assertEqual(folder, self.folder_id)
Пример #11
0
 async def test_deleting_folder_fails_on_delete(self):
     """Test folder fails on db delete, if not published."""
     operator = FolderOperator(self.client)
     operator.db_service.published_folder.return_value = False
     operator.db_service.delete.return_value = False
     with self.assertRaises(HTTPBadRequest):
         await operator.delete_folder(self.folder_id)
         operator.db_service.delete.assert_called_with("folder", self.folder_id)
Пример #12
0
 async def test_folder_update_passes_and_returns_id(self):
     """Test update method for folders works."""
     patch = [{"op": "add", "path": "/name", "value": "test2"}]
     operator = FolderOperator(self.client)
     operator.db_service.patch.return_value = True
     folder = await operator.update_folder(self.test_folder, patch)
     operator.db_service.patch.assert_called_once()
     self.assertEqual(folder["folderId"], self.folder_id)
Пример #13
0
 async def test_check_object_folder_multiple_objects_fails(self):
     """Test check object folder returns multiple unique folders."""
     operator = FolderOperator(self.client)
     operator.db_service.query.return_value = AsyncIterator([self.test_folder, self.test_folder])
     with self.assertRaises(HTTPUnprocessableEntity):
         await operator.check_object_in_folder("study", self.accession_id)
         operator.db_service.query.assert_called_once_with(
             "folder", {"metadataObjects": {"$elemMatch": {"accessionId": self.accession_id, "schema": "study"}}}
         )
Пример #14
0
 async def test_check_object_folder_no_data(self):
     """Test check object folder returns no data."""
     operator = FolderOperator(self.client)
     operator.db_service.query.return_value = AsyncIterator([])
     result = await operator.check_object_in_folder("study", self.accession_id)
     operator.db_service.query.assert_called_once_with(
         "folder", {"metadataObjects": {"$elemMatch": {"accessionId": self.accession_id, "schema": "study"}}}
     )
     self.assertEqual(result, (False, "", False))
Пример #15
0
 async def test_get_objects_folder_no_data(self):
     """Test get objects from folder returns no data."""
     operator = FolderOperator(self.client)
     operator.db_service.query.return_value = AsyncIterator([])
     result = await operator.get_collection_objects(self.folder_id, "study")
     operator.db_service.query.assert_called_once_with(
         "folder", {"$and": [{"metadataObjects": {"$elemMatch": {"schema": "study"}}}, {"folderId": self.folder_id}]}
     )
     self.assertEqual(result, [])
Пример #16
0
 async def test_delete_folder_fails(self):
     """Test folder delete fails."""
     operator = FolderOperator(self.client)
     operator.db_service.published_folder.side_effect = ConnectionFailure
     with self.assertRaises(HTTPBadRequest):
         await operator.delete_folder(self.folder_id)
Пример #17
0
 async def test_check_object_folder_fails(self):
     """Test check object folder fails."""
     operator = FolderOperator(self.client)
     operator.db_service.query.side_effect = ConnectionFailure
     with self.assertRaises(HTTPBadRequest):
         await operator.check_object_in_folder("study", self.accession_id)
Пример #18
0
 async def test_folder_object_remove_fails(self):
     """Test folder remove object fails."""
     operator = FolderOperator(self.client)
     operator.db_service.remove.side_effect = ConnectionFailure
     with self.assertRaises(HTTPBadRequest):
         await operator.remove_object(self.test_folder, "study", self.accession_id)
Пример #19
0
 async def test_folder_object_update_fails(self):
     """Test folder update fails."""
     operator = FolderOperator(self.client)
     operator.db_service.patch.side_effect = ConnectionFailure
     with self.assertRaises(HTTPBadRequest):
         await operator.update_folder(self.test_folder, [])
Пример #20
0
 async def test_get_objects_folder_fails(self):
     """Test check object folder fails."""
     operator = FolderOperator(self.client)
     operator.db_service.query.side_effect = ConnectionFailure
     with self.assertRaises(HTTPBadRequest):
         await operator.get_collection_objects(self.folder_id, "study")
Пример #21
0
 async def test_folder_object_read_fails(self):
     """Test folder read fails."""
     operator = FolderOperator(self.client)
     operator.db_service.read.side_effect = ConnectionFailure
     with self.assertRaises(HTTPBadRequest):
         await operator.read_folder(self.folder_id)