@@ -87,26 +87,37 @@ def _instrument(client, payload, status=200):
8787class TestHttpRetry (object ):
8888 """Unit tests for the default HTTP retry configuration."""
8989
90+ ENTITY_ENCLOSING_METHODS = ['post' , 'put' , 'patch' ]
91+ ALL_METHODS = ENTITY_ENCLOSING_METHODS + ['get' , 'delete' , 'head' , 'options' ]
92+
9093 @classmethod
9194 def setup_class (cls ):
9295 # Turn off exponential backoff for faster execution
9396 _http_client .DEFAULT_RETRY_CONFIG .backoff_factor = 0
9497
95- def test_retry_on_503 (self , httpserver ):
98+ @pytest .mark .parametrize ('method' , ALL_METHODS )
99+ def test_retry_on_503 (self , httpserver , method ):
96100 httpserver .serve_content ({}, 503 )
97101 client = _http_client .JsonHttpClient (
98102 credential = testutils .MockGoogleCredential (), base_url = httpserver .url )
103+ body = None
104+ if method in self .ENTITY_ENCLOSING_METHODS :
105+ body = {'key' : 'value' }
99106 with pytest .raises (requests .exceptions .HTTPError ) as excinfo :
100- client .request ('get' , '/' )
107+ client .request (method , '/' , json = body )
101108 assert excinfo .value .response .status_code == 503
102109 assert len (httpserver .requests ) == 5
103110
104- def test_retry_on_500 (self , httpserver ):
111+ @pytest .mark .parametrize ('method' , ALL_METHODS )
112+ def test_retry_on_500 (self , httpserver , method ):
105113 httpserver .serve_content ({}, 500 )
106114 client = _http_client .JsonHttpClient (
107115 credential = testutils .MockGoogleCredential (), base_url = httpserver .url )
116+ body = None
117+ if method in self .ENTITY_ENCLOSING_METHODS :
118+ body = {'key' : 'value' }
108119 with pytest .raises (requests .exceptions .HTTPError ) as excinfo :
109- client .request ('get' , '/' )
120+ client .request (method , '/' , json = body )
110121 assert excinfo .value .response .status_code == 500
111122 assert len (httpserver .requests ) == 5
112123
0 commit comments