-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testing and fixed bug when spacing issue
- Loading branch information
1 parent
d5a1fdc
commit 52e9eda
Showing
5 changed files
with
127 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
[ | ||
{ | ||
"query": { | ||
"serial": null, | ||
"asset_tag": null | ||
}, | ||
"expected": "serial\nasset_tag" | ||
}, | ||
{ | ||
"query": { | ||
"serial": null, | ||
"asset_tag": null, | ||
"site": { | ||
"name": null, | ||
"contact_name": null, | ||
"description": null, | ||
"region": { | ||
"name": null, | ||
"parent": { | ||
"name": null | ||
} | ||
} | ||
} | ||
}, | ||
"expected": "serial\nasset_tag\nsite {\n name\n contact_name\n description\n region {\n name\n parent {\n name\n }\n }\n}" | ||
}, | ||
{ | ||
"query": { | ||
"serial": null, | ||
"asset_tag": null, | ||
"site": { | ||
"filters": { | ||
"role": "core", | ||
"tenant": "den" | ||
}, | ||
"name": null, | ||
"contact_name": null, | ||
"description": null, | ||
"region": { | ||
"filters": { | ||
"$tenant": "den" | ||
}, | ||
"name": null, | ||
"parent": { | ||
"name": null | ||
} | ||
} | ||
} | ||
}, | ||
"expected": "serial\nasset_tag\nsite (role: \"core\", tenant: \"den\") {\n name\n contact_name\n description\n region ($tenant: den) {\n name\n parent {\n name\n }\n }\n}" | ||
}, | ||
{ | ||
"query": { | ||
"device": { | ||
"name": null, | ||
"platform": "napalm_driver", | ||
"status": "name", | ||
"primary_ip4": "address", | ||
"device_role": "name", | ||
"site": "name" | ||
} | ||
}, | ||
"expected": "device {\n name\n platform {\n napalm_driver\n }\n status {\n name\n }\n primary_ip4 {\n address\n }\n device_role {\n name\n }\n site {\n name\n }\n}" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Tests for Nautobot GraphQL filter plugins.""" | ||
|
||
import json | ||
import pytest | ||
from ansible_collections.networktocode.nautobot.plugins.filter.graphql import ( | ||
convert_to_graphql_string, | ||
build_graphql_filter_string, | ||
) | ||
|
||
|
||
def load_test_data(test): | ||
with open(f"tests/unit/filter/test_data/{test}.json", "r") as f: | ||
data = json.loads(f.read()) | ||
return data | ||
|
||
|
||
@pytest.mark.parametrize(("test_data"), load_test_data("graphql_string")) | ||
def test_convert_to_graphql_string(test_data): | ||
result = convert_to_graphql_string(test_data["query"]) | ||
assert result == test_data["expected"] | ||
|
||
|
||
def test_build_graphql_filter_string(): | ||
gql_filters = {"role": "core", "$tenant": "den", "device_type": "c9300"} | ||
assert build_graphql_filter_string(gql_filters) == "(role: 'core', $tenant: den, device_type: 'c9300')" |