def test_bulk_update_records(self): with patch("pynetbox.core.query.Request._make_call", return_value=Mock()) as mock: from pynetbox.core.response import Record ids = [1, 3, 5] mock.return_value = True api = Mock(base_url="http://localhost:8000/api") app = Mock(name="test") test_obj = Endpoint(api, app, "test") objects = [ Record( { "id": i, "name": "dummy" + str(i), "unchanged": "yes" }, api, test_obj, ) for i in ids ] for o in objects: o.name = "fluffy" + str(o.id) mock.return_value = [o.serialize() for o in objects] test = test_obj.update(objects) mock.assert_called_with(verb="patch", data=[{ "id": i, "name": "fluffy" + str(i) } for i in ids]) self.assertTrue(test)
def test_bulk_update_json(self): with patch("pynetbox.core.query.Request._make_call", return_value=Mock()) as mock: ids = [1, 3, 5] changes = [{"id": i, "name": "puffy" + str(i)} for i in ids] mock.return_value = True api = Mock(base_url="http://localhost:8000/api") app = Mock(name="test") mock.return_value = changes test_obj = Endpoint(api, app, "test") test = test_obj.update(changes) mock.assert_called_with(verb="patch", data=changes) self.assertTrue(test)