@@ -69,6 +69,14 @@ def fake_resolve_authconfig(authconfig, registry=None):
69
69
return None
70
70
71
71
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
+
72
80
def fake_resp (url , data = None , ** kwargs ):
73
81
status_code , content = fake_api .fake_responses [url ]()
74
82
return response (status_code = status_code , content = content )
@@ -1546,7 +1554,9 @@ def test_url_compatibility_tcp(self):
1546
1554
1547
1555
def test_logs (self ):
1548
1556
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 )
1550
1560
except Exception as e :
1551
1561
self .fail ('Command should not raise exception: {0}' .format (e ))
1552
1562
@@ -1565,7 +1575,9 @@ def test_logs(self):
1565
1575
1566
1576
def test_logs_with_dict_instead_of_id (self ):
1567
1577
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 })
1569
1581
except Exception as e :
1570
1582
self .fail ('Command should not raise exception: {0}' .format (e ))
1571
1583
@@ -1584,7 +1596,9 @@ def test_logs_with_dict_instead_of_id(self):
1584
1596
1585
1597
def test_log_streaming (self ):
1586
1598
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 )
1588
1602
except Exception as e :
1589
1603
self .fail ('Command should not raise exception: {0}' .format (e ))
1590
1604
@@ -1598,7 +1612,10 @@ def test_log_streaming(self):
1598
1612
1599
1613
def test_log_tail (self ):
1600
1614
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 )
1602
1619
except Exception as e :
1603
1620
self .fail ('Command should not raise exception: {0}' .format (e ))
1604
1621
@@ -1610,6 +1627,27 @@ def test_log_tail(self):
1610
1627
stream = False
1611
1628
)
1612
1629
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
+
1613
1651
def test_diff (self ):
1614
1652
try :
1615
1653
self .client .diff (fake_api .FAKE_CONTAINER_ID )
0 commit comments