@@ -907,17 +907,20 @@ def runTest(self):
907
907
class TestRestartingContainer (BaseTestCase ):
908
908
def runTest (self ):
909
909
container = self .client .create_container (
910
- 'busybox' , ['false ' ], host_config = create_host_config (
911
- restart_policy = {"Name" : "on-failure " , "MaximumRetryCount" : 1 }
910
+ 'busybox' , ['sleep' , '2 ' ], host_config = create_host_config (
911
+ restart_policy = {"Name" : "always " , "MaximumRetryCount" : 0 }
912
912
)
913
913
)
914
914
id = container ['Id' ]
915
915
self .client .start (id )
916
916
self .client .wait (id )
917
- self .client .remove_container (id )
918
- containers = self .client .containers (all = True )
919
- res = [x for x in containers if 'Id' in x and x ['Id' ].startswith (id )]
920
- self .assertEqual (len (res ), 0 )
917
+ with self .assertRaises (docker .errors .APIError ) as exc :
918
+ self .client .remove_container (id )
919
+ err = exc .exception .response .text
920
+ self .assertTrue (
921
+ err .startswith ('You cannot remove a running container' )
922
+ )
923
+ self .client .remove_container (id , force = True )
921
924
922
925
923
926
class TestExecuteCommand (BaseTestCase ):
@@ -1121,7 +1124,7 @@ def runTest(self):
1121
1124
self .assertIn ('Id' , res )
1122
1125
img_id = res ['Id' ]
1123
1126
self .tmp_imgs .append (img_id )
1124
- self .client .remove_image (img_id )
1127
+ self .client .remove_image (img_id , force = True )
1125
1128
images = self .client .images (all = True )
1126
1129
res = [x for x in images if x ['Id' ].startswith (img_id )]
1127
1130
self .assertEqual (len (res ), 0 )
@@ -1203,32 +1206,6 @@ def runTest(self):
1203
1206
self .assertNotEqual (logs , '' )
1204
1207
1205
1208
1206
- class TestBuildWithAuth (BaseTestCase ):
1207
- def runTest (self ):
1208
- if compare_version (self .client ._version , '1.9' ) >= 0 :
1209
- return
1210
-
1211
- k = 'K4104GON3P4Q6ZUJFZRRC2ZQTBJ5YT0UMZD7TGT7ZVIR8Y05FAH2TJQI6Y90SMIB'
1212
- self .client .login ('quay+fortesting' , k , registry = 'https://quay.io/v1/' ,
1213
- email = '' )
1214
-
1215
- script = io .BytesIO ('\n ' .join ([
1216
- 'FROM quay.io/quay/teststuff' ,
1217
- 'MAINTAINER docker-py' ,
1218
- 'RUN mkdir -p /tmp/test' ,
1219
- ]).encode ('ascii' ))
1220
-
1221
- stream = self .client .build (fileobj = script , stream = True )
1222
- logs = ''
1223
- for chunk in stream :
1224
- if six .PY3 :
1225
- chunk = chunk .decode ('utf-8' )
1226
- logs += chunk
1227
-
1228
- self .assertNotEqual (logs , '' )
1229
- self .assertEqual (logs .find ('HTTP code: 403' ), - 1 )
1230
-
1231
-
1232
1209
class TestBuildWithDockerignore (Cleanup , BaseTestCase ):
1233
1210
def runTest (self ):
1234
1211
if compare_version (self .client ._version , '1.8' ) >= 0 :
@@ -1384,9 +1361,12 @@ def setUp(self):
1384
1361
self .client = docker .client .Client (timeout = 5 )
1385
1362
1386
1363
def test_443 (self ):
1364
+ dfile = io .BytesIO ()
1387
1365
with self .assertRaises (docker .errors .APIError ) as exc :
1388
- self .client .build (fileobj = io .BytesIO (), tag = "a/b/c" )
1389
- self .assertEqual (exc .response .status_code , 500 )
1366
+ for line in self .client .build (fileobj = dfile , tag = "a/b/c" ):
1367
+ pass
1368
+ self .assertEqual (exc .exception .response .status_code , 500 )
1369
+ dfile .close ()
1390
1370
1391
1371
1392
1372
if __name__ == '__main__' :
0 commit comments