Skip to content

Commit 86cbefa

Browse files
author
Zach Moody
authored
Merge pull request #89 from digitalocean/fixes-config-context
Fixes config context
2 parents 70b88e8 + d38d978 commit 86cbefa

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

pynetbox/lib/response.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
from pynetbox.lib.query import Request
2020

21+
# List of fields that contain a dict but are not to be converted into
22+
# Record objects.
23+
JSON_FIELDS = ('custom_fields', 'data', 'config_context')
24+
2125

2226
def get_return(lookup, return_fields=None):
2327
'''Returns simple representations for items passed to lookup.
@@ -147,7 +151,8 @@ def _parse_values(self, values):
147151
values within.
148152
"""
149153
for k, v in values.items():
150-
if k != 'custom_fields':
154+
155+
if k not in JSON_FIELDS:
151156
if isinstance(v, dict):
152157
lookup = getattr(self.__class__, k, None)
153158
if lookup:

tests/fixtures/dcim/device.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,8 @@
6565
},
6666
"primary_ip6": null,
6767
"comments": "",
68-
"custom_fields": {}
68+
"custom_fields": {},
69+
"config_context": {
70+
"test_key": "test_val"
71+
}
6972
}

tests/test_dcim.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ def test_get(self, mock):
161161
self.assertTrue(isinstance(ret, self.ret))
162162
self.assertTrue(isinstance(ret.primary_ip, pynetbox.ipam.IpAddresses))
163163
self.assertTrue(isinstance(ret.primary_ip4, pynetbox.ipam.IpAddresses))
164+
self.assertTrue(isinstance(ret.config_context, dict))
165+
self.assertTrue(isinstance(ret.custom_fields, dict))
164166
mock.assert_called_with(
165167
'http://localhost:8000/api/{}/{}/1/'.format(
166168
self.app,

0 commit comments

Comments
 (0)