Skip to content

Commit

Permalink
Merge pull request #214 from digitalocean/nested-writes
Browse files Browse the repository at this point in the history
Fixes Nested Record Write methods
  • Loading branch information
Zach Moody authored Jan 12, 2020
2 parents 479f0db + a0a093b commit 6a9190a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions pynetbox/core/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def __init__(
private_key=None,
session_key=None,
ssl_verify=True,
url=None,
):
"""
Instantiates a new Request object
Expand Down
8 changes: 4 additions & 4 deletions pynetbox/core/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ def save(self):
if diff:
serialized = self.serialize()
req = Request(
key=self.id,
base=self.endpoint.url,
key=self.id if not self.url else None,
base=self.url or self.endpoint.url,
token=self.api.token,
session_key=self.api.session_key,
ssl_verify=self.api.ssl_verify,
Expand Down Expand Up @@ -433,8 +433,8 @@ def delete(self):
>>>
"""
req = Request(
key=self.id,
base=self.endpoint.url,
key=self.id if not self.url else None,
base=self.url or self.endpoint.url,
token=self.api.token,
session_key=self.api.session_key,
ssl_verify=self.api.ssl_verify,
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,21 @@ def test_compare(self):
test2 = Record({}, None, endpoint2)
test2.id = 1
self.assertEqual(test1, test2)

def test_nested_write(self):
app = Mock()
app.token = 'abc123'
endpoint = Mock()
endpoint.name = "test-endpoint"
test = Record({
'id': 123,
'name': 'test',
'child': {
'id': 321,
'name': 'test123',
'url': 'http://localhost:8080/test',
},
}, app, endpoint)
test.child.name = 'test321'
test.child.save()
self.assertEqual(app.http_session.patch.call_args[0][0], "http://localhost:8080/test/")

0 comments on commit 6a9190a

Please sign in to comment.