test.py 525 B

123456789101112131415161718
  1. import json
  2. class GraphQLTestClient:
  3. def __init__(self, client, url):
  4. self.client = client
  5. self.url = url
  6. def query(self, query, variables=None):
  7. data = {"query": query}
  8. if variables:
  9. data["variables"] = variables
  10. response = self.client.post(
  11. self.url, json.dumps(data), content_type="application/json"
  12. )
  13. json_data = response.json()
  14. assert not json_data.get("errors"), json_data.get("errors")
  15. return json_data["data"]