-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathtest_client_utils.py
More file actions
37 lines (27 loc) · 1.15 KB
/
test_client_utils.py
File metadata and controls
37 lines (27 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import json
import types
import pytest
from graphql_server.test.client import BaseGraphQLTestClient
class DummyClient(BaseGraphQLTestClient):
def request(self, body, headers=None, files=None):
return types.SimpleNamespace(content=json.dumps(body).encode(), json=lambda: body)
def test_build_body_with_variables_and_files():
client = DummyClient(None)
variables = {"files": [None, None], "textFile": None, "other": "x"}
files = {"file1": object(), "file2": object(), "textFile": object()}
body = client._build_body("query", variables, files)
mapping = json.loads(body["map"])
assert mapping == {
"file1": ["variables.files.0"],
"file2": ["variables.files.1"],
"textFile": ["variables.textFile"],
}
def test_decode_multipart():
client = DummyClient(None)
response = types.SimpleNamespace(content=json.dumps({"a": 1}).encode())
assert client._decode(response, type="multipart") == {"a": 1}
def test_query_deprecated_arg_and_assertion():
client = DummyClient(None)
with pytest.deprecated_call():
resp = client.query("{a}", asserts_errors=False)
assert resp.errors is None