async def test_delete_deletes_data(self): """Test that delete method works and returns success.""" self.collection.delete_one.return_value = DeleteResult({"n": 1}, True) success = await self.test_service.delete("testcollection", self.id_stub) self.collection.delete_one.assert_called_once_with( {"accessionId": self.id_stub}) self.assertTrue(success)
def __init__(self, collection_name, **kwargs): super().__init__() self.name = collection_name find_one_result = kwargs.get("find_one_result", {"_id": 1}) inserted_id = kwargs.get("inserted_id", 1) create_indexes_result = kwargs.get("create_indexes_result", None) self.insert_one = AsyncMock(return_value=InsertOneResult( inserted_id=inserted_id, acknowledged=True)) self.delete_many = AsyncMock( return_value=DeleteResult(raw_result={}, acknowledged=True)) self.update_one = AsyncMock( return_value=UpdateResult(raw_result={}, acknowledged=True)) self.update_many = AsyncMock( return_value=UpdateResult(raw_result={}, acknowledged=True)) self.count_documents = AsyncMock(return_value=1) self.find_one = AsyncMock(return_value=find_one_result) self.create_indexes = AsyncMock(return_value=create_indexes_result)
def test_delete_http_exception(mocker): """Test: delete(self, id: int) -> int HTTPException: Deletion error.""" service = PhraseService( settings['db_name'], settings['cln_name'] ) delete_result = DeleteResult(None, False) mock_delete_many = mocker.patch.object(Collection, 'delete_many') mock_delete_many.return_value = delete_result service.phrases.delete_many = mock_delete_many with pytest.raises(HTTPException) as ex: service.delete(1) assert 400 == ex.value.status_code assert 'Deletion error' == ex.value.detail
def delete_many(self, filter, **kwargs): raw_response = yield self._delete(filter, multi=True, **kwargs) defer.returnValue(DeleteResult(raw_response, self.write_concern.acknowledged))
def delete_many(self, filter, session=None): res = self.__remove(filter, multi=True) return DeleteResult(res, True)
def mock_return(obj_id): return DeleteResult({'n': 1, 'ok': 1.0}, True)
def delete_one(self, filter): res = self.__remove(filter, multi=False) return DeleteResult(res, True)