@@ -30,14 +30,81 @@ def resp_cont(url, request):
30
30
def test_http_request_404 (gl ):
31
31
@urlmatch (scheme = "http" , netloc = "localhost" , path = "/api/v4/not_there" , method = "get" )
32
32
def resp_cont (url , request ):
33
- content = {"Here is wh it failed" }
33
+ content = {"Here is why it failed" }
34
34
return response (404 , content , {}, None , 5 , request )
35
35
36
36
with HTTMock (resp_cont ):
37
37
with pytest .raises (GitlabHttpError ):
38
38
gl .http_request ("get" , "/not_there" )
39
39
40
40
41
+ @pytest .mark .parametrize ('status_code' , [500 , 502 , 503 , 504 ])
42
+ def test_http_request_with_only_failures (gl , status_code ):
43
+ call_count = 0
44
+ @urlmatch (scheme = "http" , netloc = "localhost" , path = "/api/v4/projects" , method = "get" )
45
+ def resp_cont (url , request ):
46
+ nonlocal call_count
47
+ call_count += 1
48
+ return response (status_code , {"Here is why it failed" }, {}, None , 5 , request )
49
+
50
+ with HTTMock (resp_cont ):
51
+ with pytest .raises (GitlabHttpError ):
52
+ gl .http_request ("get" , "/projects" )
53
+
54
+ assert call_count == 1
55
+
56
+
57
+ def test_http_request_with_retry_on_method_for_transient_failures (gl ):
58
+ call_count = 0
59
+ calls_before_success = 3
60
+ @urlmatch (scheme = "http" , netloc = "localhost" , path = "/api/v4/projects" , method = "get" )
61
+ def resp_cont (url , request ):
62
+ nonlocal call_count
63
+ call_count += 1
64
+ status_code = 200 if call_count == calls_before_success else 500
65
+ return response (status_code , {"Failure is the stepping stone to success" }, {}, None , 5 , request )
66
+
67
+ with HTTMock (resp_cont ):
68
+ http_r = gl .http_request ("get" , "/projects" , retry_transient_errors = True )
69
+
70
+ assert http_r .status_code == 200
71
+ assert call_count == calls_before_success
72
+
73
+
74
+ def test_http_request_with_retry_on_class_for_transient_failures (gl_retry ):
75
+ call_count = 0
76
+ calls_before_success = 3
77
+ @urlmatch (scheme = "http" , netloc = "localhost" , path = "/api/v4/projects" , method = "get" )
78
+ def resp_cont (url , request ):
79
+ nonlocal call_count
80
+ call_count += 1
81
+ status_code = 200 if call_count == calls_before_success else 500
82
+ return response (status_code , {"Failure is the stepping stone to success" }, {}, None , 5 , request )
83
+
84
+ with HTTMock (resp_cont ):
85
+ http_r = gl_retry .http_request ("get" , "/projects" )
86
+
87
+ assert http_r .status_code == 200
88
+ assert call_count == calls_before_success
89
+
90
+
91
+ def test_http_request_with_retry_on_class_and_method_for_transient_failures (gl_retry ):
92
+ call_count = 0
93
+ calls_before_success = 3
94
+ @urlmatch (scheme = "http" , netloc = "localhost" , path = "/api/v4/projects" , method = "get" )
95
+ def resp_cont (url , request ):
96
+ nonlocal call_count
97
+ call_count += 1
98
+ status_code = 200 if call_count == calls_before_success else 500
99
+ return response (status_code , {"Here is why it failed" }, {}, None , 5 , request )
100
+
101
+ with HTTMock (resp_cont ):
102
+ with pytest .raises (GitlabHttpError ):
103
+ gl_retry .http_request ("get" , "/projects" , retry_transient_errors = False )
104
+
105
+ assert call_count == 1
106
+
107
+
41
108
def test_get_request (gl ):
42
109
@urlmatch (scheme = "http" , netloc = "localhost" , path = "/api/v4/projects" , method = "get" )
43
110
def resp_cont (url , request ):
@@ -66,7 +133,7 @@ def resp_cont(url, request):
66
133
def test_get_request_404 (gl ):
67
134
@urlmatch (scheme = "http" , netloc = "localhost" , path = "/api/v4/not_there" , method = "get" )
68
135
def resp_cont (url , request ):
69
- content = {"Here is wh it failed" }
136
+ content = {"Here is why it failed" }
70
137
return response (404 , content , {}, None , 5 , request )
71
138
72
139
with HTTMock (resp_cont ):
@@ -150,7 +217,7 @@ def test_post_request_404(gl):
150
217
scheme = "http" , netloc = "localhost" , path = "/api/v4/not_there" , method = "post"
151
218
)
152
219
def resp_cont (url , request ):
153
- content = {"Here is wh it failed" }
220
+ content = {"Here is why it failed" }
154
221
return response (404 , content , {}, None , 5 , request )
155
222
156
223
with HTTMock (resp_cont ):
@@ -186,7 +253,7 @@ def resp_cont(url, request):
186
253
def test_put_request_404 (gl ):
187
254
@urlmatch (scheme = "http" , netloc = "localhost" , path = "/api/v4/not_there" , method = "put" )
188
255
def resp_cont (url , request ):
189
- content = {"Here is wh it failed" }
256
+ content = {"Here is why it failed" }
190
257
return response (404 , content , {}, None , 5 , request )
191
258
192
259
with HTTMock (resp_cont ):
@@ -226,7 +293,7 @@ def test_delete_request_404(gl):
226
293
scheme = "http" , netloc = "localhost" , path = "/api/v4/not_there" , method = "delete"
227
294
)
228
295
def resp_cont (url , request ):
229
- content = {"Here is wh it failed" }
296
+ content = {"Here is why it failed" }
230
297
return response (404 , content , {}, None , 5 , request )
231
298
232
299
with HTTMock (resp_cont ):
0 commit comments