8000 feat(test): Using variable_values · python-gitlab/python-gitlab@aa3dd24 · GitHub
[go: up one dir, main page]

Skip to content

Commit aa3dd24

Browse files
committed
feat(test): Using variable_values
1 parent a6fd190 commit aa3dd24

File tree

1 file changed

+132
-7
lines changed

1 file changed

+132
-7
lines changed

tests/unit/test_graphql.py

Lines changed: 132 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,74 @@ async def test_async_graphql_as_context_manager_aexits():
4747
def test_graphql_retries_on_429_response(
4848
gl_gql: gitlab.GraphQL, respx_mock: respx.MockRouter
4949
):
50+
"""Test graphql_retries_on_429_response.
51+
52+
query:
53+
54+
query get_projects($first: Int = 2) {
55+
group(fullPath: "treeocean") {
56+
projects(first: $first, includeSubgroups: true) {
57+
nodes {
58+
id
59+
}
60+
}
61+
}
62+
}
63+
64+
reply:
65+
66+
{
67+
"data": {
68+
"group": {
69+
"projects": {
70+
"nodes": [
71+
{
72+
"id": "gid://gitlab/Project/491"
73+
},
74+
{
75+
"id": "gid://gitlab/Project/485"
76+
}
77+
]
78+
}
79+
}
80+
},
81+
"correlationId": "01JSJ7ERZ7N5PKA5RCBJQNG9CS"
82+
}
83+
"""
5084
url = "https://gitlab.example.com/api/graphql"
5185
responses = [
5286
httpx.Response(429, headers={"retry-after": "1"}),
5387
httpx.Response(
54-
200, json={"data": {"currentUser": {"id": "gid://gitlab/User/1"}}}
88+
200,
89+
json={
90+
"data": {
91+
"group": {
92+
"projects": {
93+
"nodes": [
94+
{"id": "gid://gitlab/Project/491"},
95+
{"id": "gid://gitlab/Project/485"},
96+
]
97+
}
98+
}
99+
},
100+
"correlationId": "01JSJ7ERZ7N5PKA5RCBJQNG9CS",
101+
},
55102
),
56103
]
104+
variable_values = {"first": 2}
105+
query = """
106+
query get_projects($first: Int) {
107+
group(fullPath: "python-gitlab") {
108+
projects(first: $first, includeSubgroups: true) {
109+
nodes {
110+
id
111+
}
112+
}
113+
}
114+
}
115+
"""
57116
respx_mock.post(url).mock(side_effect=responses)
58-
gl_gql.execute("query {currentUser {id}}")
117+
gl_gql.execute(query, variable_values=variable_values)
59118

60119

61120
@pytest.mark.anyio
@@ -68,8 +127,21 @@ async def test_async_graphql_retries_on_429_response(
68127
200, json={"data": {"currentUser": {"id": "gid://gitlab/User/1"}}}
69128
),
70129
]
130+
variable_values = {"first": 2}
131+
query = """
132+
query get_projects($first: Int) {
133+
group(fullPath: "python-gitlab") {
134+
projects(first: $first, includeSubgroups: true) {
135+
nodes {
136+
id
137+
}
138+
}
139+
}
140+
}
141+
"""
142+
71143
respx_mock.post(api_url).mock(side_effect=responses)
72-
await gl_async_gql.execute("query {currentUser {id}}")
144+
await gl_async_gql.execute(query, variable_values=variable_values)
73145

74146

75147
def test_graphql_raises_when_max_retries_exceeded(
@@ -81,8 +153,21 @@ def test_graphql_raises_when_max_retries_exceeded(
81153
gl_gql = gitlab.GraphQL(
82154
"https://gitlab.example.com", max_retries=1, retry_transient_errors=True
83155
)
156+
variable_values = {"first": 2}
157+
query = """
158+
query get_projects($first: Int) {
159+
group(fullPath: "python-gitlab") {
160+
projects(first: $first, includeSubgroups: true) {
161+
nodes {
162+
id
163+
}
164+
}
165+
}
166+
}
167+
"""
168+
84169
with pytest.raises(gitlab.GitlabHttpError):
85-
gl_gql.execute("query {currentUser {id}}")
170+
gl_gql.execute(query, variable_values=variable_values)
86171

87172

88173
@pytest.mark.anyio
@@ -95,22 +180,62 @@ async def test_async_graphql_raises_when_max_retries_exceeded(
95180
gl_async_gql = gitlab.AsyncGraphQL(
96181
"https://gitlab.example.com", max_retries=1, retry_transient_errors=True
97182
)
183+
variable_values = {"first": 2}
184+
query = """
185+
query get_projects($first: Int) {
186+
group(fullPath: "python-gitlab") {
187+
projects(first: $first, includeSubgroups: true) {
188+
nodes {
189+
id
190+
}
191+
}
192+
}
193+
}
194+
"""
195+
98196
with pytest.raises(gitlab.GitlabHttpError):
99-
await gl_async_gql.execute("query {currentUser {id}}")
197+
await gl_async_gql.execute(query, variable_values=variable_values)
100198

101199

102200
def test_graphql_raises_on_401_response(
103201
api_url: str, gl_gql: gitlab.GraphQL, respx_mock: respx.MockRouter
104202
):
105203
respx_mock.post(api_url).mock(return_value=httpx.Response(401))
204+
variable_values = {"first": 2}
205+
query = """
206+
query get_projects($first: Int) {
207+
group(fullPath: "python-gitlab") {
208+
projects(first: $first, includeSubgroups: true) {
209+
nodes {
210+
id
211+
}
212+
}
213+
}
214+
}
215+
"""
216+
106217
with pytest.raises(gitlab.GitlabAuthenticationError):
107-
gl_gql.execute("query {currentUser {id}}")
218+
gl_gql.execute(query, variable_values=variable_values)
108219

109220

110221
@pytest.mark.anyio
111222
async def test_async_graphql_raises_on_401_response(
112223
api_url: str, gl_async_gql: gitlab.AsyncGraphQL, respx_mock: respx.MockRouter
113224
):
114225
respx_mock.post(api_url).mock(return_value=httpx.Response(401))
226+
227+
variable_values = {"first": 2}
228+
query = """
229+
query get_projects($first: Int) {
230+
group(fullPath: "python-gitlab") {
231+
projects(first: $first, includeSubgroups: true) {
232+
nodes {
233+
id
234+
}
235+
}
236+
}
237+
}
238+
"""
239+
115240
with pytest.raises(gitlab.GitlabAuthenticationError):
116-
await gl_async_gql.execute("query {currentUser {id}}")
241+
await gl_async_gql.execute(query, variable_values=variable_values)

0 commit comments

Comments
 (0)
0