Skip to content

Commit 3a42a53

Browse files
committed
test: Add UTs for list fields
1 parent 9e9b0b4 commit 3a42a53

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/test_lists.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from graphql import build_schema
2+
3+
from graphql_complexity import SimpleEstimator, get_complexity
4+
from graphql_complexity.config import Config
5+
from tests.ut_utils import schema
6+
7+
8+
def _evaluate_complexity_with_simple_estimator(query: str, field_complexity=1):
9+
estimator = SimpleEstimator(field_complexity)
10+
return get_complexity(query, build_schema(schema), estimator)
11+
12+
13+
def test_complexity_reads_count_from_query_args():
14+
query = """query {
15+
droid {
16+
friends(first: 10) {
17+
name
18+
}
19+
}
20+
}"""
21+
22+
complexity = _evaluate_complexity_with_simple_estimator(query, 1)
23+
24+
assert complexity == 12
25+
26+
27+
def test_complexity_reads_count_from_query_args_with_different_name():
28+
query = """query {
29+
droid {
30+
friends(count: 10) {
31+
name
32+
}
33+
}
34+
}"""
35+
36+
complexity = get_complexity(query, build_schema(schema), SimpleEstimator(), Config(count_arg_name="count"))
37+
38+
assert complexity == 12
39+
40+
41+
def test_complexity_config_allows_penalizing_missing_count_argument():
42+
query = """query {
43+
droid {
44+
friends {
45+
name
46+
}
47+
}
48+
}"""
49+
50+
complexity = get_complexity(query, build_schema(schema), SimpleEstimator(), Config(count_missing_arg_value=100))
51+
52+
assert complexity == 102

0 commit comments

Comments
 (0)