Skip to content

Commit

Permalink
Added backwards compatibility support to Endpoint.update() method
Browse files Browse the repository at this point in the history
  • Loading branch information
tsm1th committed Feb 5, 2024
1 parent 9149e92 commit e5cd0b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions pynautobot/core/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,21 @@ def update(self, *args, **kwargs):
objects = args[0] if args else []
if not isinstance(objects, list):
raise ValueError("objects must be a list[dict()|Record] not " + str(type(objects)))

if "data" in kwargs and "id" in kwargs:
kwargs["data"]["id"] = kwargs["id"]
objects.append(kwargs["data"])
uuid = kwargs["id"]
data = kwargs["data"]

req = Request(
key=uuid,
base=self.url,
token=self.api.token,
http_session=self.api.http_session,
api_version=self.api.api_version,
)
if req.patch(data):
return True
return False

data = []
for o in objects:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def test_update_with_id_and_data(self):
api = Mock(base_url="http://localhost:8000/api")
app = Mock(name="test")
test_obj = Endpoint(api, app, "test")
mock.return_value = [{"id": "db8770c4-61e5-4999-8372-e7fa576a4f65", "name": "test"}]
mock.return_value = [{"name": "test"}]
test = test_obj.update(id="db8770c4-61e5-4999-8372-e7fa576a4f65", data={"name": "test"})
mock.assert_called_with(verb="patch", data=[{"id": "db8770c4-61e5-4999-8372-e7fa576a4f65", "name": "test"}])
mock.assert_called_with(verb="patch", data={"name": "test"})
self.assertTrue(test)

def test_update_with_dict(self):
Expand Down

0 comments on commit e5cd0b0

Please sign in to comment.