예제 #1
0
 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)
예제 #2
0
    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)
예제 #3
0
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
예제 #4
0
 def delete_many(self, filter, **kwargs):
     raw_response = yield self._delete(filter, multi=True, **kwargs)
     defer.returnValue(DeleteResult(raw_response, self.write_concern.acknowledged))
예제 #5
0
 def delete_many(self, filter, session=None):
     res = self.__remove(filter, multi=True)
     return DeleteResult(res, True)
예제 #6
0
 def mock_return(obj_id):
     return DeleteResult({'n': 1, 'ok': 1.0}, True)
예제 #7
0
 def delete_one(self, filter):
     res = self.__remove(filter, multi=False)
     return DeleteResult(res, True)