@@ -69,6 +69,14 @@ def fake_resolve_authconfig(authconfig, registry=None):
6969 return None
7070
7171
72+ def fake_inspect_container (self , container , tty = False ):
73+ return fake_api .get_fake_inspect_container (tty = tty )[1 ]
74+
75+
76+ def fake_inspect_container_tty (self , container ):
77+ return fake_inspect_container (self , container , tty = True )
78+
79+
7280def fake_resp (url , data = None , ** kwargs ):
7381 status_code , content = fake_api .fake_responses [url ]()
7482 return response (status_code = status_code , content = content )
@@ -1546,7 +1554,9 @@ def test_url_compatibility_tcp(self):
15461554
15471555 def test_logs (self ):
15481556 try :
1549- logs = self .client .logs (fake_api .FAKE_CONTAINER_ID )
1557+ with mock .patch ('docker.Client.inspect_container' ,
1558+ fake_inspect_container ):
1559+ logs = self .client .logs (fake_api .FAKE_CONTAINER_ID )
15501560 except Exception as e :
15511561 self .fail ('Command should not raise exception: {0}' .format (e ))
15521562
@@ -1565,7 +1575,9 @@ def test_logs(self):
15651575
15661576 def test_logs_with_dict_instead_of_id (self ):
15671577 try :
1568- logs = self .client .logs ({'Id' : fake_api .FAKE_CONTAINER_ID })
1578+ with mock .patch ('docker.Client.inspect_container' ,
1579+ fake_inspect_container ):
1580+ logs = self .client .logs ({'Id' : fake_api .FAKE_CONTAINER_ID })
15691581 except Exception as e :
15701582 self .fail ('Command should not raise exception: {0}' .format (e ))
15711583
@@ -1584,7 +1596,9 @@ def test_logs_with_dict_instead_of_id(self):
15841596
15851597 def test_log_streaming (self ):
15861598 try :
1587- self .client .logs (fake_api .FAKE_CONTAINER_ID , stream = True )
1599+ with mock .patch ('docker.Client.inspect_container' ,
1600+ fake_inspect_container ):
1601+ self .client .logs (fake_api .FAKE_CONTAINER_ID , stream = True )
15881602 except Exception as e :
15891603 self .fail ('Command should not raise exception: {0}' .format (e ))
15901604
@@ -1598,7 +1612,10 @@ def test_log_streaming(self):
15981612
15991613 def test_log_tail (self ):
16001614 try :
1601- self .client .logs (fake_api .FAKE_CONTAINER_ID , stream = False , tail = 10 )
1615+ with mock .patch ('docker.Client.inspect_container' ,
1616+ fake_inspect_container ):
1617+ self .client .logs (fake_api .FAKE_CONTAINER_ID , stream = False ,
1618+ tail = 10 )
16021619 except Exception as e :
16031620 self .fail ('Command should not raise exception: {0}' .format (e ))
16041621
@@ -1610,6 +1627,27 @@ def test_log_tail(self):
16101627 stream = False
16111628 )
16121629
1630+ def test_log_tty (self ):
1631+ try :
1632+ m = mock .Mock ()
1633+ with mock .patch ('docker.Client.inspect_container' ,
1634+ fake_inspect_container_tty ):
1635+ with mock .patch ('docker.Client._stream_raw_result' ,
1636+ m ):
1637+ self .client .logs (fake_api .FAKE_CONTAINER_ID ,
1638+ stream = True )
1639+ except Exception as e :
1640+ self .fail ('Command should not raise exception: {0}' .format (e ))
1641+
1642+ self .assertTrue (m .called )
1643+ fake_request .assert_called_with (
1644+ url_prefix + 'containers/3cc2351ab11b/logs' ,
1645+ params = {'timestamps' : 0 , 'follow' : 1 , 'stderr' : 1 , 'stdout' : 1 ,
1646+ 'tail' : 'all' },
1647+ timeout = DEFAULT_TIMEOUT_SECONDS ,
1648+ stream = True
1649+ )
1650+
16131651 def test_diff (self ):
16141652 try :
16151653 self .client .diff (fake_api .FAKE_CONTAINER_ID )
0 commit comments