@@ -87,26 +87,37 @@ def _instrument(client, payload, status=200):
87
87
class TestHttpRetry (object ):
88
88
"""Unit tests for the default HTTP retry configuration."""
89
89
90
+ ENTITY_ENCLOSING_METHODS = ['post' , 'put' , 'patch' ]
91
+ ALL_METHODS = ENTITY_ENCLOSING_METHODS + ['get' , 'delete' , 'head' , 'options' ]
92
+
90
93
@classmethod
91
94
def setup_class (cls ):
92
95
# Turn off exponential backoff for faster execution
93
96
_http_client .DEFAULT_RETRY_CONFIG .backoff_factor = 0
94
97
95
- def test_retry_on_503 (self , httpserver ):
98
+ @pytest .mark .parametrize ('method' , ALL_METHODS )
99
+ def test_retry_on_503 (self , httpserver , method ):
96
100
httpserver .serve_content ({}, 503 )
97
101
client = _http_client .JsonHttpClient (
98
102
credential = testutils .MockGoogleCredential (), base_url = httpserver .url )
103
+ body = None
104
+ if method in self .ENTITY_ENCLOSING_METHODS :
105
+ body = {'key' : 'value' }
99
106
with pytest .raises (req
AC82
uests .exceptions .HTTPError ) as excinfo :
100
- client .request ('get' , '/' )
107
+ client .request (method , '/' , json = body )
101
108
assert excinfo .value .response .status_code == 503
102
109
assert len (httpserver .requests ) == 5
103
110
104
- def test_retry_on_500 (self , httpserver ):
111
+ @pytest .mark .parametrize ('method' , ALL_METHODS )
112
+ def test_retry_on_500 (self , httpserver , method ):
105
113
httpserver .serve_content ({}, 500 )
106
114
client = _http_client .JsonHttpClient (
107
115
credential = testutils .MockGoogleCredential (), base_url = httpserver .url )
116
+ body = None
117
+ if method in self .ENTITY_ENCLOSING_METHODS :
118
+ body = {'key' : 'value' }
108
119
with pytest .raises (requests .exceptions .HTTPError ) as excinfo :
109
- client .request ('get' , '/' )
120
+ client .request (method , '/' , json = body )
110
121
assert excinfo .value .response .status_code == 500
111
122
assert len (httpserver .requests ) == 5
112
123
0 commit comments