class DLManager(): def __init__(self, database, collection): self.connector = MongoConnection(database=database, collection=collection) def raise_exception(self, msg): """ :param msg: :return: """ raise Exception(msg) def update(self, query, document): """ :param query: :param document: :return: """ self.connector.update_document(query, document) def create(self, document): """ :param document: :param options: :return: """ logger.info("creating document", extra={'document': document}) self.connector.create_document(document) def get_document(self, field, value): """ :param model_name: :return: """ query = {field: value} model = self.connector.find_document_by_id(query) return model def get_all_documents(self): """ :return: """ documents = [doc for doc in self.connector.get_docs_collection()] return documents
def test_create_document(mocker): db_name = "test_db" coll_name = "test_coll" document = {'document', 'document_value'} mongo_client = mongomock.MongoClient() conn = MongoConnection(db_name, coll_name) conn.collection = mongo_client.collection mocker.patch.object(conn.collection, 'insert_one', return_value=False) conn.create_document(document) conn.collection.insert_one.assert_called_once_with(document)