def test_update(self): # Arrange response = [{ u'updatedExisting': True, u'connectionId': 1, u'ok': 1.0, u'err': None, u'n': 1 }] query = {"id": 1} data = {"num": 2} collection_name = "collection_update" collection = Mock(name=collection_name) collection.update.return_value = None collection.update.side_effect = lambda *args, **kwargs: kwargs[ 'callback'](response, error=None) client = {collection_name: collection} callback = Mock(name="update_callback") callback.side_effect = lambda response, error: self.stop() # Act model = DBLayer(client, collection_name) model.update(query, data, callback=callback) self.wait() # Assert collection.update.assert_called_once_with({'id': 1}, data, callback=callback) callback.assert_called_once_with(response, error=None)
def test_update(self): def handle_update(response, error=None): self.assertIsNone(error) self.assertEqual(response[0]['ok'], 1.0) self.stop() self.sync_db[self.collection_name].insert({"num": 1}) model = DBLayer(self.async_db, self.collection_name) model.update({"num": 1}, {"num": 2}, callback=handle_update) self.wait()
def test_update(self): # Arrange response = [{u'updatedExisting': True, u'connectionId': 1, u'ok': 1.0, u'err': None, u'n': 1}] query = {"id": 1} data = {"num": 2} collection_name = "collection_update" collection = Mock(name=collection_name) collection.update.return_value = None collection.update.side_effect = lambda *args, **kwargs: kwargs['callback'](response, error=None) client = {collection_name: collection} callback = Mock(name="update_callback") callback.side_effect = lambda response, error : self.stop() # Act model = DBLayer(client, collection_name) model.update(query, data, callback=callback) self.wait() # Assert collection.update.assert_called_once_with({'id': 1}, data, callback=callback) callback.assert_called_once_with(response, error=None)