mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-04-26 12:03:47 +03:00
Adds variables arg to GraphQLTestCase.query (#699)
* add variables arg in GraphQLTestCase.query * update GraphQLTestCase.query docstring and remove type check
This commit is contained in:
parent
ac79b38cf0
commit
254e59c36f
|
@ -37,6 +37,28 @@ Usage:
|
||||||
# Add some more asserts if you like
|
# Add some more asserts if you like
|
||||||
...
|
...
|
||||||
|
|
||||||
|
def test_query_with_variables(self):
|
||||||
|
response = self.query(
|
||||||
|
'''
|
||||||
|
query myModel($id: Int!){
|
||||||
|
myModel(id: $id) {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
''',
|
||||||
|
op_name='myModel',
|
||||||
|
variables={'id': 1}
|
||||||
|
)
|
||||||
|
|
||||||
|
content = json.loads(response.content)
|
||||||
|
|
||||||
|
# This validates the status code and if you get errors
|
||||||
|
self.assertResponseNoErrors(response)
|
||||||
|
|
||||||
|
# Add some more asserts if you like
|
||||||
|
...
|
||||||
|
|
||||||
def test_some_mutation(self):
|
def test_some_mutation(self):
|
||||||
response = self.query(
|
response = self.query(
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -24,7 +24,7 @@ class GraphQLTestCase(TestCase):
|
||||||
|
|
||||||
cls._client = Client()
|
cls._client = Client()
|
||||||
|
|
||||||
def query(self, query, op_name=None, input_data=None):
|
def query(self, query, op_name=None, input_data=None, variables=None):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
query (string) - GraphQL query to run
|
query (string) - GraphQL query to run
|
||||||
|
@ -32,7 +32,11 @@ class GraphQLTestCase(TestCase):
|
||||||
supply the op_name. For annon queries ("{ ... }"),
|
supply the op_name. For annon queries ("{ ... }"),
|
||||||
should be None (default).
|
should be None (default).
|
||||||
input_data (dict) - If provided, the $input variable in GraphQL will be set
|
input_data (dict) - If provided, the $input variable in GraphQL will be set
|
||||||
to this value
|
to this value. If both ``input_data`` and ``variables``,
|
||||||
|
are provided, the ``input`` field in the ``variables``
|
||||||
|
dict will be overwritten with this value.
|
||||||
|
variables (dict) - If provided, the "variables" field in GraphQL will be
|
||||||
|
set to this value.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Response object from client
|
Response object from client
|
||||||
|
@ -40,7 +44,12 @@ class GraphQLTestCase(TestCase):
|
||||||
body = {"query": query}
|
body = {"query": query}
|
||||||
if op_name:
|
if op_name:
|
||||||
body["operation_name"] = op_name
|
body["operation_name"] = op_name
|
||||||
|
if variables:
|
||||||
|
body["variables"] = variables
|
||||||
if input_data:
|
if input_data:
|
||||||
|
if variables in body:
|
||||||
|
body["variables"]["input"] = input_data
|
||||||
|
else:
|
||||||
body["variables"] = {"input": input_data}
|
body["variables"] = {"input": input_data}
|
||||||
|
|
||||||
resp = self._client.post(
|
resp = self._client.post(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user