Skip to content

Commit 8d5d981

Browse files
author
Zach Moody
authored
Merge pull request #128 from digitalocean/fix-list-of-records
Fixes #127 - Record iter doesn't handle list of records
2 parents 0547b3c + 2c4d4f4 commit 8d5d981

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2+
v4.0.3 (2018-12-07)
3+
4+
## Bug Fixes
5+
* [#127](https://github.com/digitalocean/pynetbox/issues/127) - Fixes `__iter__` method on Record object so that it properly return lists record objects. Like tagged_vlans on for Interfaces.
6+
7+
---
8+
19
v4.0.2 (2018-12-06)
210

311
## Bug Fixes

pynetbox/core/response.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ def __iter__(self):
183183
cur_attr = getattr(self, i)
184184
if isinstance(cur_attr, Record):
185185
yield i, dict(cur_attr)
186+
elif isinstance(cur_attr, list) and isinstance(
187+
cur_attr[0], Record
188+
):
189+
yield i, [dict(x) for x in cur_attr]
186190
else:
187191
yield i, cur_attr
188192

tests/unit/test_response.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,56 @@ def test_diff(self):
7777
test.nested_dict = 1
7878
test.string_field = 'foobaz'
7979
self.assertEqual(test._diff(), {'tags', 'nested_dict', 'string_field'})
80+
81+
def test_dict(self):
82+
test_values = {
83+
'id': 123,
84+
'custom_fields': {
85+
'foo': 'bar'
86+
},
87+
'string_field': 'foobar',
88+
'int_field': 1,
89+
"nested_dict": {
90+
"id": 222,
91+
"name": 'bar',
92+
},
93+
'tags': [
94+
'foo',
95+
'bar',
96+
],
97+
'int_list': [
98+
123,
99+
321,
100+
231,
101+
],
102+
'record_list': [
103+
{
104+
'id': 123,
105+
'name': 'Test',
106+
'str_attr': 'foo',
107+
'int_attr': 123,
108+
'custom_fields': {
109+
'foo': 'bar'
110+
},
111+
'tags': [
112+
'foo',
113+
'bar',
114+
],
115+
},
116+
{
117+
'id': 321,
118+
'name': 'Test 1',
119+
'str_attr': 'bar',
120+
'int_attr': 321,
121+
'custom_fields': {
122+
'foo': 'bar'
123+
},
124+
'tags': [
125+
'foo',
126+
'bar',
127+
],
128+
},
129+
]
130+
}
131+
test = Record(test_values, None, None)
132+
self.assertEqual(dict(test), test_values)

0 commit comments

Comments
 (0)