-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_lists.py
66 lines (47 loc) · 1.62 KB
/
test_lists.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from graphql import build_schema
from graphql_complexity import SimpleEstimator, get_complexity
from graphql_complexity.config import Config
from tests.ut_utils import schema
def _evaluate_complexity_with_simple_estimator(query: str, field_complexity=1):
estimator = SimpleEstimator(field_complexity)
return get_complexity(query, build_schema(schema), estimator)
def test_complexity_reads_count_from_query_args():
query = """query {
droid {
friends(first: 10) {
name
}
}
}"""
complexity = _evaluate_complexity_with_simple_estimator(query, 1)
assert complexity == 12
def test_complexity_reads_count_from_query_args_with_different_name():
query = """query {
droid {
friends(count: 10) {
name
}
}
}"""
complexity = get_complexity(query, build_schema(schema), SimpleEstimator(), Config(count_arg_name="count"))
assert complexity == 12
def test_complexity_with_arg_name_unset_ignores_lists():
query = """query {
droid {
friends(first: 10) {
name
}
}
}"""
complexity = get_complexity(query, build_schema(schema), SimpleEstimator(), Config(count_arg_name=None))
assert complexity == 3
def test_complexity_config_allows_penalizing_missing_count_argument():
query = """query {
droid {
friends {
name
}
}
}"""
complexity = get_complexity(query, build_schema(schema), SimpleEstimator(), Config(count_missing_arg_value=100))
assert complexity == 102