Skip to content

Commit

Permalink
Merge pull request #89 from digitalocean/fixes-config-context
Browse files Browse the repository at this point in the history
Fixes config context
  • Loading branch information
Zach Moody committed Aug 7, 2018
2 parents 70b88e8 + d38d978 commit 86cbefa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pynetbox/lib/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

from pynetbox.lib.query import Request

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


def get_return(lookup, return_fields=None):
'''Returns simple representations for items passed to lookup.
Expand Down Expand Up @@ -147,7 +151,8 @@ def _parse_values(self, values):
values within.
"""
for k, v in values.items():
if k != 'custom_fields':

if k not in JSON_FIELDS:
if isinstance(v, dict):
lookup = getattr(self.__class__, k, None)
if lookup:
Expand Down
5 changes: 4 additions & 1 deletion tests/fixtures/dcim/device.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,8 @@
},
"primary_ip6": null,
"comments": "",
"custom_fields": {}
"custom_fields": {},
"config_context": {
"test_key": "test_val"
}
}
2 changes: 2 additions & 0 deletions tests/test_dcim.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def test_get(self, mock):
self.assertTrue(isinstance(ret, self.ret))
self.assertTrue(isinstance(ret.primary_ip, pynetbox.ipam.IpAddresses))
self.assertTrue(isinstance(ret.primary_ip4, pynetbox.ipam.IpAddresses))
self.assertTrue(isinstance(ret.config_context, dict))
self.assertTrue(isinstance(ret.custom_fields, dict))
mock.assert_called_with(
'http://localhost:8000/api/{}/{}/1/'.format(
self.app,
Expand Down

0 comments on commit 86cbefa

Please sign in to comment.