Exemple #1
0
    def test_insert(self):
        def handle_insert(response, error=None):
            self.assertIsNone(error)
            self.assertEqual(response[0]['ok'], 1.0)
            self.stop()

        model = DBLayer(self.async_db, self.collection_name)
        self.assertEqual(model.collection.full_collection_name,
                    self.async_db[self.collection_name].full_collection_name)
        model.insert(data={"id": "1", "two": 2},  callback=handle_insert)
        self.wait()
Exemple #2
0
    def test_insert(self):
        def handle_insert(response, error=None):
            self.assertIsNone(error)
            self.assertEqual(response[0]['ok'], 1.0)
            self.stop()

        model = DBLayer(self.async_db, self.collection_name)
        self.assertEqual(
            model.collection.full_collection_name,
            self.async_db[self.collection_name].full_collection_name)
        model.insert(data={"id": "1", "two": 2}, callback=handle_insert)
        self.wait()
Exemple #3
0
 def test_insert(self):
     # Arrange
     response = [{u'connectionId': 1, u'ok': 1.0, u'err': None, u'n': 0}]
     collection_name = "collection_insert"
     collection = Mock(name=collection_name)
     collection.insert.return_value = None
     collection.insert.side_effect = lambda *args, **kwargs: kwargs['callback'](response, error=None)
     client = {collection_name: collection}
     callback = Mock(name="insert_callback")
     callback.side_effect = lambda response, error : self.stop()
     ts = 1330921125000000
     data = {"id": "1", "ts": ts, "two": 2}
     expected = copy.copy(data)
     expected['_id'] = "1:"+str(ts)
     # Act
     model = DBLayer(client, collection_name)
     model.insert(data, callback=callback)
     self.wait()
     # Assert
     collection.insert.assert_called_once_with(expected,  callback=callback)
     callback.assert_called_once_with(response,  error=None)
Exemple #4
0
 def test_insert(self):
     # Arrange
     response = [{u'connectionId': 1, u'ok': 1.0, u'err': None, u'n': 0}]
     collection_name = "collection_insert"
     collection = Mock(name=collection_name)
     collection.insert.return_value = None
     collection.insert.side_effect = lambda *args, **kwargs: kwargs[
         'callback'](response, error=None)
     client = {collection_name: collection}
     callback = Mock(name="insert_callback")
     callback.side_effect = lambda response, error: self.stop()
     ts = 1330921125000000
     data = {"id": "1", "ts": ts, "two": 2}
     expected = copy.copy(data)
     expected['_id'] = "1:" + str(ts)
     # Act
     model = DBLayer(client, collection_name)
     model.insert(data, callback=callback)
     self.wait()
     # Assert
     collection.insert.assert_called_once_with(expected, callback=callback)
     callback.assert_called_once_with(response, error=None)