def test_count(self, query, mock_count):
        mongo_db_accessor = MongoDbAccessor(COLL_NAME, self.mock_logger)
        self.mock_collection.count.return_value = mock_count

        exp_result = mock_count

        result = mongo_db_accessor.count(query)
        self.assertEqual(result, exp_result)
        self.mock_collection.count.assert_called_once_with(query)
    def test_find_one(self, query, projection, mock_document):
        mongo_db_accessor = MongoDbAccessor(COLL_NAME, self.mock_logger)
        self.mock_collection.find_one.return_value = mock_document

        exp_result = MongoDbAccessor.mongo_to_python(mock_document)

        result = mongo_db_accessor.find_one(query, projection)
        self.assertEqual(result, exp_result)
        self.mock_collection.find_one.assert_called_once_with(
            query, projection)
    def test_find(self, query, projection, mock_documents):
        mongo_db_accessor = MongoDbAccessor(COLL_NAME, self.mock_logger)
        self.mock_collection.find.return_value = mock_documents

        exp_result = [
            MongoDbAccessor.mongo_to_python(doc) for doc in mock_documents
        ]

        result = mongo_db_accessor.find(query, projection)
        self.assertEqual(result, exp_result)
        self.mock_collection.find.assert_called_once_with(query, projection)
    def test_aggregate(self, pipeline, mock_documents):
        mongo_db_accessor = MongoDbAccessor(COLL_NAME, self.mock_logger)
        self.mock_collection.aggregate.return_value = mock_documents

        exp_result = [
            MongoDbAccessor.mongo_to_python(doc) for doc in mock_documents
        ]

        result = mongo_db_accessor.aggregate(pipeline)
        self.assertEqual(result, exp_result)
        self.mock_collection.aggregate.assert_called_once_with(pipeline)
    def test_update_many(self, query, update, mock_update_return):
        """A trivial test:  Only tests that the collection's update_many function is called with the correct parameters
           and that its return value is what is returned from MongoDbAccessor.update_many.
        """
        mongo_db_accessor = MongoDbAccessor(COLL_NAME, self.mock_logger)
        self.mock_collection.update_many.return_value = mock_update_return

        exp_result = mock_update_return

        result = mongo_db_accessor.update_many(query, update)
        self.assertEqual(result, exp_result)
        self.mock_collection.update_many.assert_called_once_with(query, update)
    def test_init(self):
        """
        Simply verify the constructor does what it is supposed to do.
        """

        mongo_db_accessor = MongoDbAccessor(COLL_NAME, self.mock_logger)

        self.assertEqual(mongo_db_accessor.collection_name, COLL_NAME)
        self.assertEqual(mongo_db_accessor.db_name, DB)
        self.assertEqual(mongo_db_accessor.mongo_client,
                         self.mock_mongo_client.return_value)
        self.assertEqual(mongo_db_accessor.database,
                         self.mock_mongo_client.return_value[DB])
        self.assertEqual(mongo_db_accessor.collection, self.mock_collection)
        self.assertEqual(mongo_db_accessor.logger, self.mock_logger)
        self.mock_mongo_client.assert_called_once_with(URI)
Beispiel #7
0
 def __init__(self):
     MongoDbAccessor.__init__(self, 'treatmentArms', logging.getLogger(__name__))
 def test_mongo_to_python(self, orig_doc, exp_doc):
     converted_doc = MongoDbAccessor.mongo_to_python(orig_doc)
     self.assertEqual(converted_doc, exp_doc)