Skip to content

Commit

Permalink
Merge pull request #271 from digitalocean/fix-tag-ordering
Browse files Browse the repository at this point in the history
Fix tag ordering
  • Loading branch information
Zach Moody authored Jul 15, 2020
2 parents bb93c8e + 7e8365a commit d7754e8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pynetbox/core/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
limitations under the License.
"""
import copy
from collections import OrderedDict

import pynetbox.core.app
from six.moves.urllib.parse import urlsplit
Expand Down Expand Up @@ -341,7 +342,7 @@ def serialize(self, nested=False, init=False):
v.id if isinstance(v, Record) else v for v in current_val
]
if i in LIST_AS_SET:
current_val = list(set(current_val))
current_val = list(OrderedDict.fromkeys(current_val))
ret[i] = current_val
return ret

Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,25 @@ def test_endpoint_from_url(self):
)
ret = test._endpoint_from_url(test.url)
self.assertEqual(ret.name, "test-endpoint")

def test_serialize_tag_list_order(self):
"""Add tests to ensure we're preserving tag order
This test could still give false-negatives, but making the tag list
longer helps mitigate that.
"""

test_tags = [
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
]
test = Record({"id": 123, "tags": test_tags}, None, None).serialize()
self.assertEqual(test["tags"], test_tags)

0 comments on commit d7754e8

Please sign in to comment.