@@ -611,6 +611,87 @@ def test_server_image_create_name(self):
611611 self .assertEqual (datalist , data )
612612
613613
614+ class TestServerList (TestServer ):
615+
616+ # Columns to be listed up.
617+ columns = (
618+ 'ID' ,
619+ 'Name' ,
620+ 'Status' ,
621+ 'Networks' ,
622+ )
623+
624+ # Data returned by corresponding Nova API. The elements in this list are
625+ # tuples filled with server attributes.
626+ data = []
627+
628+ # Default search options, in the case of no commandline option specified.
629+ search_opts = {
630+ 'reservation_id' : None ,
631+ 'ip' : None ,
632+ 'ip6' : None ,
633+ 'name' : None ,
634+ 'instance_name' : None ,
635+ 'status' : None ,
636+ 'flavor' : None ,
637+ 'image' : None ,
638+ 'host' : None ,
639+ 'tenant_id' : None ,
640+ 'all_tenants' : False ,
641+ 'user_id' : None ,
642+ }
643+
644+ # Default params of the core function of the command in the case of no
645+ # commandline option specified.
646+ kwargs = {
647+ 'search_opts' : search_opts ,
648+ 'marker' : None ,
649+ 'limit' : None ,
650+ }
651+
652+ def setUp (self ):
653+ super (TestServerList , self ).setUp ()
654+
655+ # The fake servers' attributes.
656+ self .attrs = {
657+ 'status' : 'ACTIVE' ,
658+ 'networks' : {
659+ u'public' : [u'10.20.30.40' , u'2001:db8::5' ]
660+ },
661+ }
662+
663+ # The servers to be listed.
664+ self .servers = self .setup_servers_mock (3 )
665+
666+ self .servers_mock .list .return_value = self .servers
667+
668+ # Get the command object to test
669+ self .cmd = server .ListServer (self .app , None )
670+
671+ # Prepare data returned by fake Nova API.
672+ for s in self .servers :
673+ self .data .append ((
674+ s .id ,
675+ s .name ,
676+ s .status ,
677+ u'public=10.20.30.40, 2001:db8::5' ,
678+ ))
679+
680+ def test_server_list_no_option (self ):
681+ arglist = []
682+ verifylist = [
683+ ('all_projects' , False ),
684+ ('long' , False ),
685+ ]
686+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
687+
688+ columns , data = self .cmd .take_action (parsed_args )
689+
690+ self .servers_mock .list .assert_called_with (** self .kwargs )
691+ self .assertEqual (self .columns , columns )
692+ self .assertEqual (tuple (self .data ), tuple (data ))
693+
694+
614695class TestServerLock (TestServer ):
615696
616697 def setUp (self ):
0 commit comments