2020
2121from openstackclient .network .v2 import port
2222from openstackclient .tests .unit .compute .v2 import fakes as compute_fakes
23+ from openstackclient .tests .unit .identity .v3 import fakes as identity_fakes
2324from openstackclient .tests .unit .network .v2 import fakes as network_fakes
2425from openstackclient .tests .unit import utils as tests_utils
2526
@@ -31,6 +32,8 @@ def setUp(self):
3132
3233 # Get a shortcut to the network client
3334 self .network = self .app .client_manager .network
35+ # Get a shortcut to the ProjectManager Mock
36+ self .projects_mock = self .app .client_manager .identity .projects
3437
3538 def _get_common_cols_data (self , fake_port ):
3639 columns = (
@@ -741,6 +744,44 @@ def test_list_port_with_long(self):
741744 self .assertEqual (self .columns_long , columns )
742745 self .assertEqual (self .data_long , list (data ))
743746
747+ def test_port_list_project (self ):
748+ project = identity_fakes .FakeProject .create_one_project ()
749+ self .projects_mock .get .return_value = project
750+ arglist = [
751+ '--project' , project .id ,
752+ ]
753+ verifylist = [
754+ ('project' , project .id ),
755+ ]
756+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
757+
758+ columns , data = self .cmd .take_action (parsed_args )
759+ filters = {'tenant_id' : project .id , 'project_id' : project .id }
760+
761+ self .network .ports .assert_called_once_with (** filters )
762+ self .assertEqual (self .columns , columns )
763+ self .assertEqual (self .data , list (data ))
764+
765+ def test_port_list_project_domain (self ):
766+ project = identity_fakes .FakeProject .create_one_project ()
767+ self .projects_mock .get .return_value = project
768+ arglist = [
769+ '--project' , project .id ,
770+ '--project-domain' , project .domain_id ,
771+ ]
772+ verifylist = [
773+ ('project' , project .id ),
774+ ('project_domain' , project .domain_id ),
775+ ]
776+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
777+
778+ columns , data = self .cmd .take_action (parsed_args )
779+ filters = {'tenant_id' : project .id , 'project_id' : project .id }
780+
781+ self .network .ports .assert_called_once_with (** filters )
782+ self .assertEqual (self .columns , columns )
783+ self .assertEqual (self .data , list (data ))
784+
744785
745786class TestSetPort (TestPort ):
746787
0 commit comments