Skip to content

Commit

Permalink
Changed query_id to be a positional argument and adjusted unit test e…
Browse files Browse the repository at this point in the history
…rror to reflect changes
  • Loading branch information
tsm1th committed Sep 3, 2024
1 parent c892ce2 commit 0fb0623
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
6 changes: 1 addition & 5 deletions pynautobot/core/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def run(self, *args, api_version=None, **kwargs):
class GraphqlEndpoint(Endpoint):
"""Extend Endpoint class to support run method for graphql queries."""

def run(self, *args, query_id=None, **kwargs):
def run(self, query_id, *args, **kwargs):
"""Runs a saved graphql query based on the query_id provided.
Takes a kwarg of `query_id` to specify the query that should be run.
Expand Down Expand Up @@ -728,11 +728,7 @@ def run(self, *args, query_id=None, **kwargs):
{"variables":{"foo":"bar"}}
)
"""

if not query_id:
raise ValueError('Keyword Argument "query_id" is required to run a query.')
query_run_url = f"{self.url}/{query_id}/run/"

return Request(
base=query_run_url,
token=self.token,
Expand Down
2 changes: 1 addition & 1 deletion pynautobot/models/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def run(self, **kwargs):
class GraphqlQueries(Record):
def run(self, *args, **kwargs):
"""Run a graphql query from a saved graphql instance."""
return GraphqlEndpoint(self.api, self.api.extras, "graphql_queries").run(query_id=self.id, *args, **kwargs)
return GraphqlEndpoint(self.api, self.api.extras, "graphql_queries").run(self.id, *args, **kwargs)


class DynamicGroups(Record):
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ def test_run_greater_v1_3(self):

class GraphqlEndPointTestCase(unittest.TestCase):
def test_invalid_arg(self):
with self.assertRaises(ValueError, msg='Keyword Argument "query_id" is required to run a query.'):
with self.assertRaises(
TypeError, msg="GraphqlEndpoint.run() missing 1 required positional argument: 'query_id'"
):
api = Mock(base_url="http://localhost:8000/api")
app = Mock(name="test")
test_obj = GraphqlEndpoint(api, app, "test")
Expand Down

0 comments on commit 0fb0623

Please sign in to comment.