forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_selectors_scalar.py
More file actions
78 lines (56 loc) · 2.6 KB
/
Copy pathtest_selectors_scalar.py
File metadata and controls
78 lines (56 loc) · 2.6 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
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
67
68
69
70
71
72
73
74
75
76
77
78
import pytest
from graphql.language import ast
from graphql import GraphQLError
from scalars.selectors import Selectors, scalar_error_type, scalar_error_only_types
def test_valid_selectors_serialize_list():
test_selectors = ["selector1._domainkey", "selector2._domainkey"]
assert Selectors.serialize(test_selectors)
def test_valid_selectors_parse_value_list():
test_selectors = ["selector1._domainkey", "selector2._domainkey"]
assert Selectors.parse_value(test_selectors)
def test_valid_selectors_serialize_not_list():
test_selectors = "selector1._domainkey"
with pytest.raises(GraphQLError, match=scalar_error_type("List", test_selectors)):
assert Selectors.serialize(test_selectors)
def test_valid_selectors_parse_value_not_list():
test_selectors = "selector1._domainkey"
with pytest.raises(GraphQLError, match=scalar_error_type("List", test_selectors)):
assert Selectors.parse_value(test_selectors)
def test_valid_selectors_parse_literal():
assert Selectors.parse_literal(
ast.ListValue(
values=[
ast.StringValue(value="selector1._domainkey"),
ast.StringValue(value="selector2._domainkey"),
]
)
)
def test_invalid_selectors_serialize_not_selector():
test_list = ["This Will Fail"]
with pytest.raises(GraphQLError, match=scalar_error_type("Selector", test_list)):
Selectors.serialize(test_list)
def test_invalid_selectors_serialize_wrong_type():
test_list = [1234]
with pytest.raises(GraphQLError, match=scalar_error_type("String", test_list)):
Selectors.serialize(test_list)
def test_invalid_selectors_parse_value_not_selector():
test_list = ["This Will Fail"]
with pytest.raises(GraphQLError, match=scalar_error_type("Selector", test_list)):
Selectors.parse_value(test_list)
def test_invalid_selectors_parse_value_wrong_type():
test_list = [1234]
with pytest.raises(GraphQLError, match=scalar_error_type("String", test_list)):
Selectors.parse_value(test_list)
def test_invalid_selectors_parse_literal_not_selector():
test_list = ast.ListValue(values=[ast.StringValue(value="This Will Fail")])
with pytest.raises(
GraphQLError, match=scalar_error_type("Selector", test_list.values)
):
Selectors.parse_literal(test_list)
def test_invalid_selectors_parse_literal_wrong_ast_type():
test_list = ast.ListValue(values=[ast.IntValue(value=1234)])
with pytest.raises(
GraphQLError,
match=scalar_error_only_types("strings", "selectors", str(ast.Type)),
):
Selectors.parse_literal(test_list)