Esempio n. 1
0
    def test_find(self):
        def handle_find(expected, response, error=None):
            self.assertIsNone(error)
            self.assertEqual(response, expected)
            self.stop()

        # Insert some test data directly to the collection
        self.sync_db[self.collection_name].insert({"_id": "1", "num": 1})
        self.sync_db[self.collection_name].insert({"_id": "2", "num": 2})
        self.sync_db[self.collection_name].insert({"_id": "3", "num": 3})
        expected = [{u"num": 2}, {u"num": 3}]
        find_callback = functools.partial(handle_find, expected)

        model = DBLayer(self.async_db, self.collection_name)
        model.find({"num": {"$gte": 2}}, callback=find_callback)
        self.wait()
Esempio n. 2
0
    def test_find(self):
        def handle_find(expected, response, error=None):
            self.assertIsNone(error)
            self.assertEqual(response, expected)
            self.stop()

        # Insert some test data directly to the collection
        self.sync_db[self.collection_name].insert({"_id": "1", "num": 1})
        self.sync_db[self.collection_name].insert({"_id": "2", "num": 2})
        self.sync_db[self.collection_name].insert({"_id": "3", "num": 3})
        expected = [{u"num": 2}, {u"num": 3}]
        find_callback = functools.partial(handle_find, expected)

        model = DBLayer(self.async_db, self.collection_name)
        model.find({"num": {"$gte": 2}}, callback=find_callback)
        self.wait()
Esempio n. 3
0
 def test_find(self):
     # Arrange
     response = [{"_id": "2", "num": 2}, {"_id": "3", "num": 3}]
     expected = [{"_id": "2", "num": 2}, {"_id": "3", "num": 3}]
     query = {"num": {"$gte": 2},}
     collection_name = "collection_find"
     collection = Mock(name=collection_name)
     collection.find.return_value = None
     collection.find.side_effect = lambda *args, **kwargs: kwargs['callback'](response, error=None)
     client = {collection_name: collection}
     callback = Mock(name="find_callback")
     callback.side_effect = lambda response, error : self.stop()
     # Act
     model = DBLayer(client, collection_name)
     model.find(query, callback=callback)
     self.wait()
     # Assert
     self.assertEqual(collection.find.call_args[0], (query,))
     callback.assert_called_once_with(expected, error=None)
Esempio n. 4
0
 def test_find(self):
     # Arrange
     response = [{"_id": "2", "num": 2}, {"_id": "3", "num": 3}]
     expected = [{"_id": "2", "num": 2}, {"_id": "3", "num": 3}]
     query = {
         "num": {
             "$gte": 2
         },
     }
     collection_name = "collection_find"
     collection = Mock(name=collection_name)
     collection.find.return_value = None
     collection.find.side_effect = lambda *args, **kwargs: kwargs[
         'callback'](response, error=None)
     client = {collection_name: collection}
     callback = Mock(name="find_callback")
     callback.side_effect = lambda response, error: self.stop()
     # Act
     model = DBLayer(client, collection_name)
     model.find(query, callback=callback)
     self.wait()
     # Assert
     self.assertEqual(collection.find.call_args[0], (query, ))
     callback.assert_called_once_with(expected, error=None)