Skip to content

Commit

Permalink
Update pynetbox to new tags in Netbox 2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
fabi125 committed Sep 16, 2020
1 parent c45411a commit 1652f95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pynetbox/core/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


# List of fields that are lists but should be treated as sets.
LIST_AS_SET = ("tags", "tagged_vlans")
LIST_AS_SET = ("tagged_vlans")


def get_return(lookup, return_fields=None):
Expand Down
37 changes: 5 additions & 32 deletions tests/unit/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,19 @@ def test_serialize_list_of_ints(self):
test = test_obj.serialize()
self.assertEqual(test["units"], [12])

def test_serialize_tag_set(self):
test_values = {"id": 123, "tags": ["foo", "bar", "foo"]}
test = Record(test_values, None, None).serialize()
self.assertEqual(len(test["tags"]), 2)

def test_diff(self):
test_values = {
"id": 123,
"custom_fields": {"foo": "bar"},
"string_field": "foobar",
"int_field": 1,
"nested_dict": {"id": 222, "name": "bar"},
"tags": ["foo", "bar"],
"tags": [{"id": 55, "name": "foo"}, {"id": 66, "name": "bar"}],
"int_list": [123, 321, 231],
"local_context_data": {"data": ["one"]},
}
test = Record(test_values, None, None)
test.tags.append("baz")
test.tags.append({"name": "baz"})
test.nested_dict = 1
test.string_field = "foobaz"
test.local_context_data["data"].append("two")
Expand Down Expand Up @@ -121,7 +116,7 @@ def test_dict(self):
"string_field": "foobar",
"int_field": 1,
"nested_dict": {"id": 222, "name": "bar"},
"tags": ["foo", "bar"],
"tags": [{"name": "foo"}, {"name":"bar"}],
"int_list": [123, 321, 231],
"empty_list": [],
"record_list": [
Expand All @@ -131,15 +126,15 @@ def test_dict(self):
"str_attr": "foo",
"int_attr": 123,
"custom_fields": {"foo": "bar"},
"tags": ["foo", "bar"],
"tags": [{"name": "foo"}, {"name":"bar"}],
},
{
"id": 321,
"name": "Test 1",
"str_attr": "bar",
"int_attr": 321,
"custom_fields": {"foo": "bar"},
"tags": ["foo", "bar"],
"tags": [{"name": "foo"}, {"name":"bar"}],
},
],
}
Expand Down Expand Up @@ -239,25 +234,3 @@ 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 1652f95

Please sign in to comment.