| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a6fd190 commit aa3dd24
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,15 +47,74 @@ async def test_async_graphql_as_context_manager_aexits(): | |||
| 47 | 47 | def test_graphql_retries_on_429_response( | |
| 48 | 48 | gl_gql: gitlab.GraphQL, respx_mock: respx.MockRouter | |
| 49 | 49 | ): | |
| 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 | + """ | ||
| 50 | 84 | url = "https://gitlab.example.com/api/graphql" | |
| 51 | 85 | responses = [ | |
| 52 | 86 | httpx.Response(429, headers={"retry-after": "1"}), | |
| 53 | 87 | 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 | + }, | ||
| 55 | 102 | ), | |
| 56 | 103 | ] | |
| 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 | + """ | ||
| 57 | 116 | respx_mock.post(url).mock(side_effect=responses) | |
| 58 | - gl_gql.execute("query {currentUser {id}}") | ||
| 117 | + gl_gql.execute(query, variable_values=variable_values) | ||
| 59 | 118 | ||
| 60 | 119 | ||
| 61 | 120 | @pytest.mark.anyio | |
@@ -68,8 +127,21 @@ async def test_async_graphql_retries_on_429_response( | |||
| 68 | 127 | 200, json={"data": {"currentUser": {"id": "gid://gitlab/User/1"}}} | |
| 69 | 128 | ), | |
| 70 | 129 | ] | |
| 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 | + | ||
| 71 | 143 | 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) | ||
| 73 | 145 | ||
| 74 | 146 | ||
| 75 | 147 | def test_graphql_raises_when_max_retries_exceeded( | |
@@ -81,8 +153,21 @@ def test_graphql_raises_when_max_retries_exceeded( | |||
| 81 | 153 | gl_gql = gitlab.GraphQL( | |
| 82 | 154 | "https://gitlab.example.com", max_retries=1, retry_transient_errors=True | |
| 83 | 155 | ) | |
| 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 | + | ||
| 84 | 169 | with pytest.raises(gitlab.GitlabHttpError): | |
| 85 | - gl_gql.execute("query {currentUser {id}}") | ||
| 170 | + gl_gql.execute(query, variable_values=variable_values) | ||
| 86 | 171 | ||
| 87 | 172 | ||
| 88 | 173 | @pytest.mark.anyio | |
@@ -95,22 +180,62 @@ async def test_async_graphql_raises_when_max_retries_exceeded( | |||
| 95 | 180 | gl_async_gql = gitlab.AsyncGraphQL( | |
| 96 | 181 | "https://gitlab.example.com", max_retries=1, retry_transient_errors=True | |
| 97 | 182 | ) | |
| 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 | + | ||
| 98 | 196 | 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) | ||
| 100 | 198 | ||
| 101 | 199 | ||
| 102 | 200 | def test_graphql_raises_on_401_response( | |
| 103 | 201 | api_url: str, gl_gql: gitlab.GraphQL, respx_mock: respx.MockRouter | |
| 104 | 202 | ): | |
| 105 | 203 | 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 | + | ||
| 106 | 217 | with pytest.raises(gitlab.GitlabAuthenticationError): | |
| 107 | - gl_gql.execute("query {currentUser {id}}") | ||
| 218 | + gl_gql.execute(query, variable_values=variable_values) | ||
| 108 | 219 | ||
| 109 | 220 | ||
| 110 | 221 | @pytest.mark.anyio | |
| 111 | 222 | async def test_async_graphql_raises_on_401_response( | |
| 112 | 223 | api_url: str, gl_async_gql: gitlab.AsyncGraphQL, respx_mock: respx.MockRouter | |
| 113 | 224 | ): | |
| 114 | 225 | 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 | + | ||
| 115 | 240 | 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) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments