@@ -222,3 +222,34 @@ def test_fetch_remote_nodecluster(self, mock_fetch, mock_list):
222222 mock_list .side_effect = [ApiError , ApiError ]
223223 self .assertRaises (ApiError , dockercloud .Utils .fetch_remote_nodecluster , 'uuid_or_name' , True )
224224 self .assertRaises (ApiError , dockercloud .Utils .fetch_remote_nodecluster , 'uuid_or_name' , False )
225+
226+ @mock .patch ('dockercloud.Swarm.list' )
227+ @mock .patch ('dockercloud.Swarm.fetch' )
228+ def test_fetch_remote_swarm (self , mock_fetch , mock_list ):
229+ # test the identifier w/ and w/o namespace
230+ mock_fetch .return_value = 'returned'
231+ self .assertEqual (dockercloud .Utils .fetch_remote_swarm ('abc' , True ), 'returned' )
232+ mock_fetch .assert_called_with ("abc" , namespace = "" )
233+
234+ self .assertEqual (dockercloud .Utils .fetch_remote_swarm ('tifayuki/abc' , True ), 'returned' )
235+ mock_fetch .assert_called_with ("abc" , namespace = "tifayuki" )
236+
237+ self .assertEqual (dockercloud .Utils .fetch_remote_swarm ('tifayuki/abc/xyz' , True ), 'returned' )
238+ mock_fetch .assert_called_with ("abc/xyz" , namespace = "tifayuki" )
239+
240+ # test no swarm found
241+ mock_fetch .side_effect = ObjectNotFound
242+ self .assertRaises (ObjectNotFound , dockercloud .Utils .fetch_remote_swarm , 'swarm_id' , True )
243+ self .assertIsInstance (dockercloud .Utils .fetch_remote_swarm ('swarm_id' , False ), ObjectNotFound )
244+
245+ # test multi-swarm found
246+ mock_fetch .return_value = 'returned'
247+ mock_list .side_effect = [['swarm1' , 'swarm2' ], []]
248+ self .assertRaises (NonUniqueIdentifier , dockercloud .Utils .fetch_remote_swarm , 'swarm_id' , True )
249+ mock_list .side_effect = [['swarm1' , 'swarm2' ], []]
250+ self .assertIsInstance (dockercloud .Utils .fetch_remote_swarm ('swarm_id' , False ), NonUniqueIdentifier )
251+
252+ # test api error
253+ mock_list .side_effect = [ApiError , ApiError ]
254+ self .assertRaises (ApiError , dockercloud .Utils .fetch_remote_swarm , 'swarm_id' , True )
255+ self .assertRaises (ApiError , dockercloud .Utils .fetch_remote_swarm , 'swarm_id' , False )
0 commit comments