1111# under the License.
1212#
1313
14+ import copy
1415import mock
1516
1617from openstackclient .network .v2 import security_group
1718from openstackclient .tests .compute .v2 import fakes as compute_fakes
19+ from openstackclient .tests import fakes
20+ from openstackclient .tests .identity .v3 import fakes as identity_fakes
1821from openstackclient .tests .network .v2 import fakes as network_fakes
1922from openstackclient .tests import utils as tests_utils
2023
@@ -65,6 +68,30 @@ def setUp(self):
6568 self .network .create_security_group = mock .Mock (
6669 return_value = self ._security_group )
6770
71+ # Set identity client v3. And get a shortcut to Identity client.
72+ identity_client = identity_fakes .FakeIdentityv3Client (
73+ endpoint = fakes .AUTH_URL ,
74+ token = fakes .AUTH_TOKEN ,
75+ )
76+ self .app .client_manager .identity = identity_client
77+ self .identity = self .app .client_manager .identity
78+
79+ # Get a shortcut to the ProjectManager Mock
80+ self .projects_mock = self .identity .projects
81+ self .projects_mock .get .return_value = fakes .FakeResource (
82+ None ,
83+ copy .deepcopy (identity_fakes .PROJECT ),
84+ loaded = True ,
85+ )
86+
87+ # Get a shortcut to the DomainManager Mock
88+ self .domains_mock = self .identity .domains
89+ self .domains_mock .get .return_value = fakes .FakeResource (
90+ None ,
91+ copy .deepcopy (identity_fakes .DOMAIN ),
92+ loaded = True ,
93+ )
94+
6895 # Get the command object to test
6996 self .cmd = security_group .CreateSecurityGroup (self .app , self .namespace )
7097
@@ -93,11 +120,15 @@ def test_create_min_options(self):
93120 def test_create_all_options (self ):
94121 arglist = [
95122 '--description' , self ._security_group .description ,
123+ '--project' , identity_fakes .project_name ,
124+ '--project-domain' , identity_fakes .domain_name ,
96125 self ._security_group .name ,
97126 ]
98127 verifylist = [
99128 ('description' , self ._security_group .description ),
100129 ('name' , self ._security_group .name ),
130+ ('project' , identity_fakes .project_name ),
131+ ('project_domain' , identity_fakes .domain_name ),
101132 ]
102133 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
103134
@@ -106,6 +137,7 @@ def test_create_all_options(self):
106137 self .network .create_security_group .assert_called_once_with (** {
107138 'description' : self ._security_group .description ,
108139 'name' : self ._security_group .name ,
140+ 'tenant_id' : identity_fakes .project_id ,
109141 })
110142 self .assertEqual (tuple (self .columns ), columns )
111143 self .assertEqual (self .data , data )
@@ -147,6 +179,15 @@ def test_create_no_options(self):
147179 self .assertRaises (tests_utils .ParserException ,
148180 self .check_parser , self .cmd , [], [])
149181
182+ def test_create_network_options (self ):
183+ arglist = [
184+ '--project' , identity_fakes .project_name ,
185+ '--project-domain' , identity_fakes .domain_name ,
186+ self ._security_group .name ,
187+ ]
188+ self .assertRaises (tests_utils .ParserException ,
189+ self .check_parser , self .cmd , arglist , [])
190+
150191 def test_create_min_options (self ):
151192 arglist = [
152193 self ._security_group .name ,
0 commit comments