forked from DiamondLightSource/daq-config-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_graphql.py
More file actions
129 lines (103 loc) · 3.19 KB
/
test_graphql.py
File metadata and controls
129 lines (103 loc) · 3.19 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from fastapi.testclient import TestClient
from daq_config_server.app import app
client = TestClient(app)
GRAPHQL_ENDPOINT = "/graphql"
def graphql_query(query: str, variables: dict | None = None):
"""Helper function to send GraphQL queries."""
if variables is None:
variables = {}
response = client.post(
GRAPHQL_ENDPOINT, json={"query": query, "variables": variables}
)
return response.json()
def test_fetch_single_beamline_parameter():
query = """
query ($key: String!) {
beamlineParameter(key: $key) {
key
value
}
}
"""
variables = {"key": "energy"}
response = graphql_query(query, variables)
assert "errors" not in response
assert response["data"]["beamlineParameter"]["key"] == "energy"
assert response["data"]["beamlineParameter"]["value"] is not None
def test_fetch_all_beamline_parameters():
query = """
query {
allBeamlineParameters {
key
value
}
}
"""
response = graphql_query(query)
assert "errors" not in response
assert isinstance(response["data"]["allBeamlineParameters"], list)
assert len(response["data"]["allBeamlineParameters"]) > 0
def test_fetch_feature_flags():
query = """
query {
featureFlags {
name
}
}
"""
response = graphql_query(query)
assert "errors" not in response
assert isinstance(response["data"]["featureFlags"], list)
def test_fetch_feature_flags_with_values():
query = """
query {
featureFlags(getValues: true) {
name
value
}
}
"""
response = graphql_query(query)
assert "errors" not in response
assert isinstance(response["data"]["featureFlags"], list)
for flag in response["data"]["featureFlags"]:
assert isinstance(flag["name"], str)
assert isinstance(flag["value"], bool)
def test_create_feature_flag():
mutation = """
mutation ($name: String!, $value: Boolean!) {
createFeatureFlag(name: $name, value: $value) {
name
value
}
}
"""
variables = {"name": "dark_mode", "value": True}
response = graphql_query(mutation, variables)
assert "errors" not in response
assert response["data"]["createFeatureFlag"]["name"] == "dark_mode"
assert response["data"]["createFeatureFlag"]["value"] is True
def test_update_feature_flag():
mutation = """
mutation ($name: String!, $value: Boolean!) {
updateFeatureFlag(name: $name, value: $value) {
name
value
}
}
"""
variables = {"name": "dark_mode", "value": False}
response = graphql_query(mutation, variables)
assert "errors" not in response
assert response["data"]["updateFeatureFlag"]["name"] == "dark_mode"
assert response["data"]["updateFeatureFlag"]["value"] is False
def test_delete_feature_flag():
mutation = """
mutation ($name: String!) {
deleteFeatureFlag(name: $name)
}
"""
variables = {"name": "dark_mode"}
response = graphql_query(mutation, variables)
assert "errors" not in response
assert response["data"]["deleteFeatureFlag"] is True