@@ -77,6 +77,40 @@ def test_push_image(self, mock_client):
77
77
pusher .run ()
78
78
mock_client ().push .assert_called_once_with (
79
79
self .image .canonical_name , decode = True , stream = True )
80
+ self .assertTrue (pusher .success )
81
+
82
+ @mock .patch ('docker.version' , '3.0.0' )
83
+ @mock .patch .dict (os .environ , clear = True )
84
+ @mock .patch ('docker.APIClient' )
85
+ def test_push_image_failure (self , mock_client ):
86
+ self .dc = mock_client
87
+ mock_client ().push .side_effect = Exception
88
+ pusher = build .PushTask (self .conf , self .image )
89
+ pusher .run ()
90
+ mock_client ().push .assert_called_once_with (
91
+ self .image .canonical_name , decode = True , stream = True )
92
+ self .assertFalse (pusher .success )
93
+ self .assertEqual (build .STATUS_PUSH_ERROR , self .image .status )
94
+
95
+ @mock .patch ('docker.version' , '3.0.0' )
96
+ @mock .patch .dict (os .environ , clear = True )
97
+ @mock .patch ('docker.APIClient' )
98
+ def test_push_image_failure_retry (self , mock_client ):
99
+ self .dc = mock_client
100
+ mock_client ().push .side_effect = [Exception , []]
101
+ pusher = build .PushTask (self .conf , self .image )
102
+ pusher .run ()
103
+ mock_client ().push .assert_called_once_with (
104
+ self .image .canonical_name , decode = True , stream = True )
105
+ self .assertFalse (pusher .success )
106
+ self .assertEqual (build .STATUS_PUSH_ERROR , self .image .status )
107
+
108
+ # Try again, this time without exception.
109
+ pusher .reset ()
110
+ pusher .run ()
111
+ self .assertEqual (2 , mock_client ().push .call_count )
112
+ self .assertTrue (pusher .success )
113
+ self .assertEqual (build .STATUS_BUILT , self .image .status )
80
114
81
115
@mock .patch .dict (os .environ , clear = True )
82
116
@mock .patch ('docker.APIClient' )
0 commit comments