@@ -68,16 +68,15 @@ class TestClientApiInterface(TestClientApiBase):
6868 If a test should be run only in this class, please override the method there.
6969 """
7070
71- @mock .patch ("urllib3.request.RequestMethods.request" )
72- def test_machines (self , mocker ):
71+ def test_machines (self ):
7372 """Can request machines"""
7473 data = [
7574 "http://127.0.0.1:4001" ,
7675 "http://127.0.0.1:4002" ,
7776 "http://127.0.0.1:4003" ,
7877 ]
7978 d = "," .join (data )
80- mocker . return_value = self ._prepare_response (200 , d )
79+ self . client . http . request = mock . MagicMock ( return_value = self ._prepare_response (200 , d ) )
8180 self .assertEqual (data , self .client .machines )
8281
8382 @mock .patch ("etcd.Client.machines" , new_callable = mock .PropertyMock )
@@ -121,9 +120,7 @@ def test_members(self):
121120 ]
122121 }
123122 self ._mock_api (200 , data )
124- self .assertEqual (
125- self .client .members ["ce2a822cea30bfca" ]["id" ], "ce2a822cea30bfca"
126- )
123+ self .assertEqual (self .client .members ["ce2a822cea30bfca" ]["id" ], "ce2a822cea30bfca" )
127124
128125 def test_self_stats (self ):
129126 """Request for stats"""
@@ -156,9 +153,7 @@ def test_leader(self, mocker):
156153 """Can request the leader"""
157154 members = {"ce2a822cea30bfca" : {"id" : "ce2a822cea30bfca" , "name" : "default" }}
158155 mocker .return_value = members
159- self ._mock_api (
160- 200 , {"leaderInfo" : {"leader" : "ce2a822cea30bfca" , "followers" : {}}}
161- )
156+ self ._mock_api (200 , {"leaderInfo" : {"leader" : "ce2a822cea30bfca" , "followers" : {}}})
162157 self .assertEqual (self .client .leader , members ["ce2a822cea30bfca" ])
163158
164159 def test_set_plain (self ):
@@ -257,9 +252,7 @@ def test_compare_and_swap(self):
257252 def test_compare_and_swap_failure (self ):
258253 """Exception will be raised if prevValue != value in test_set"""
259254 self ._mock_exception (ValueError , "Test Failed : [ 1!=3 ]" )
260- self .assertRaises (
261- ValueError , self .client .write , "/testKey" , "test" , prevValue = "oldbog"
262- )
255+ self .assertRaises (ValueError , self .client .write , "/testKey" , "test" , prevValue = "oldbog" )
263256
264257 def test_set_append (self ):
265258 """Can append a new key"""
@@ -278,9 +271,7 @@ def test_set_append(self):
278271
279272 def test_set_dir_with_value (self ):
280273 """Creating a directory with a value raises an error."""
281- self .assertRaises (
282- etcd .EtcdException , self .client .write , "/bar" , "testvalye" , dir = True
283- )
274+ self .assertRaises (etcd .EtcdException , self .client .write , "/bar" , "testvalye" , dir = True )
284275
285276 def test_delete (self ):
286277 """Can delete a value"""
@@ -312,11 +303,7 @@ def test_pop(self):
312303 self ._mock_api (200 , d )
313304 res = self .client .pop (d ["node" ]["key" ])
314305 self .assertEqual (
315- {
316- attr : getattr (res , attr )
317- for attr in dir (res )
318- if attr in etcd .EtcdResult ._node_props
319- },
306+ {attr : getattr (res , attr ) for attr in dir (res ) if attr in etcd .EtcdResult ._node_props },
320307 d ["prevNode" ],
321308 )
322309 self .assertEqual (res .value , d ["prevNode" ]["value" ])
@@ -398,34 +385,24 @@ def _mock_api(self, status, d, cluster_id=None):
398385 self .client .http .request_encode_body = mock .MagicMock (return_value = resp )
399386 self .client .http .request = mock .MagicMock (return_value = resp )
400387
401- def _mock_error (
402- self , error_code , msg , cause , method = "PUT" , fields = None , cluster_id = None
403- ):
404- resp = self ._prepare_response (
405- 500 , {"errorCode" : error_code , "message" : msg , "cause" : cause }
406- )
388+ def _mock_error (self , error_code , msg , cause , method = "PUT" , fields = None , cluster_id = None ):
389+ resp = self ._prepare_response (500 , {"errorCode" : error_code , "message" : msg , "cause" : cause })
407390 resp .getheader .return_value = cluster_id or "abcdef1234"
408391 self .client .http .request_encode_body = mock .create_autospec (
409392 self .client .http .request_encode_body , return_value = resp
410393 )
411- self .client .http .request = mock .create_autospec (
412- self .client .http .request , return_value = resp
413- )
394+ self .client .http .request = mock .create_autospec (self .client .http .request , return_value = resp )
414395
415396 def test_compare_and_swap_failure (self ):
416397 """Exception will be raised if prevValue != value in test_set"""
417398 self ._mock_error (200 , "Test Failed" , "[ 1!=3 ]" , fields = {"prevValue" : "oldbog" })
418- self .assertRaises (
419- ValueError , self .client .write , "/testKey" , "test" , prevValue = "oldbog"
420- )
399+ self .assertRaises (ValueError , self .client .write , "/testKey" , "test" , prevValue = "oldbog" )
421400
422401 def test_watch_timeout (self ):
423402 """Exception will be raised if prevValue != value in test_set"""
424403 self .client .http .request = mock .create_autospec (
425404 self .client .http .request ,
426- side_effect = urllib3 .exceptions .ReadTimeoutError (
427- self .client .http , "foo" , "Read timed out"
428- ),
405+ side_effect = urllib3 .exceptions .ReadTimeoutError (self .client .http , "foo" , "Read timed out" ),
429406 )
430407 self .assertRaises (
431408 etcd .EtcdWatchTimedOut ,
@@ -435,15 +412,11 @@ def test_watch_timeout(self):
435412
436413 def test_path_without_trailing_slash (self ):
437414 """Exception will be raised if a path without a trailing slash is used"""
438- self .assertRaises (
439- ValueError , self .client .api_execute , "testpath/bar" , self .client ._MPUT
440- )
415+ self .assertRaises (ValueError , self .client .api_execute , "testpath/bar" , self .client ._MPUT )
441416
442417 def test_api_method_not_supported (self ):
443418 """Exception will be raised if an unsupported HTTP method is used"""
444- self .assertRaises (
445- etcd .EtcdException , self .client .api_execute , "/testpath/bar" , "TRACE"
446- )
419+ self .assertRaises (etcd .EtcdException , self .client .api_execute , "/testpath/bar" , "TRACE" )
447420
448421 def test_read_cluster_id_changed (self ):
449422 """Read timeout set to the default"""
@@ -462,14 +435,10 @@ def test_read_cluster_id_changed(self):
462435 self .client .read ("/testkey" )
463436
464437 def test_read_connection_error (self ):
465- self .client .http .request = mock .create_autospec (
466- self .client .http .request , side_effect = socket .error ()
467- )
438+ self .client .http .request = mock .create_autospec (self .client .http .request , side_effect = socket .error ())
468439 self .assertRaises (etcd .EtcdConnectionFailed , self .client .read , "/something" )
469440 # Direct GET request
470- self .assertRaises (
471- etcd .EtcdConnectionFailed , self .client .api_execute , "/a" , "GET"
472- )
441+ self .assertRaises (etcd .EtcdConnectionFailed , self .client .api_execute , "/a" , "GET" )
473442
474443 def test_not_in (self ):
475444 pass
0 commit comments