Skip to content

Commit

Permalink
Merge pull request nautobot#259 from tsm1th/u/tsm1th-add-dynamic-grou…
Browse files Browse the repository at this point in the history
…p-json-field

Added json field of filter to dynamic groups
  • Loading branch information
joewesch authored Nov 25, 2024
2 parents 91a1d0e + 90f8a2a commit a6d9c9e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pynautobot/models/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def run(self, *args, **kwargs):


class DynamicGroups(Record):
filter = JsonField

def __str__(self):
parent_record_string = super().__str__()
return parent_record_string or str(self.id)
Expand Down
28 changes: 28 additions & 0 deletions tests/integration/test_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,31 @@ def test_graphql_query_run_with_variable(self, create_graphql_query):
data = query.run(variables={"devicename": "dev-1"})
assert len(data.get("data", {}).get("devices")) == 1
assert data.get("data", {}).get("devices")[0].get("name") == "dev-1"


class TestDynamicGroup:
"""Dynamic group tests."""

def test_dynamic_group_filter_field(self, nb_client):
"""Verify we can create a dynamic group and return the filter field."""

# Define filter field
obj_filter = {"q": "foobar"}

# Create dynamic group
nb_client.extras.dynamic_groups.create(
[
{
"name": "TestDynamicGroup",
"content_type": "dcim.device",
"group_type": "dynamic-filter",
"filter": obj_filter,
}
]
)

# Get dynamic group
dynamic_group = nb_client.extras.dynamic_groups.get(name="TestDynamicGroup")

# Assert filter field is returned
assert dynamic_group.filter == obj_filter

0 comments on commit a6d9c9e

Please sign in to comment.