1 # Copyright 2022 Canonical Ltd.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 from unittest
.mock
import Mock
, patch
18 from click
.testing
import CliRunner
19 from osmclient
.common
.exceptions
import ClientException
20 from osmclient
.scripts
import osm
23 @patch("osmclient.scripts.osm.client.Client")
24 class TestNS(unittest
.TestCase
):
26 self
.runner
= CliRunner()
29 def test_ns_create_with_vim_account(self
, mock_client
):
30 mock_client
.return_value
= self
.ctx_obj
31 result
= self
.runner
.invoke(
43 self
.ctx_obj
.ns
.create
.assert_called_with(
48 vim_account
="vim_account",
50 admin_status
="ENABLED",
54 assert not result
.exception
56 def test_ns_create_with_paas_account(self
, mock_client
):
57 mock_client
.return_value
= self
.ctx_obj
58 result
= self
.runner
.invoke(
70 self
.ctx_obj
.ns
.create
.assert_called_with(
76 paas_account
="paas_account",
77 admin_status
="ENABLED",
81 assert not result
.exception
83 def test_ns_create_with_paas_and_vim_account_raises_exception(self
, mock_client
):
84 mock_client
.return_value
= self
.ctx_obj
85 result
= self
.runner
.invoke(
99 self
.ctx_obj
.ns
.create
.assert_not_called()
100 expected_msg
= '"vim_account" and "paas_account" can not be used together, use only one of them'
101 assert result
.exception
102 assert isinstance(result
.exception
, ClientException
)
103 assert expected_msg
in str(result
.exception
)
105 def test_ns_creat_without_paas_or_vim_account_raises_exception(self
, mock_client
):
106 mock_client
.return_value
= self
.ctx_obj
107 result
= self
.runner
.invoke(
108 osm
.cli_osm
, ["ns-create", "--ns_name", "ns_name", "--nsd_name", "nsd_name"]
110 self
.ctx_obj
.ns
.create
.assert_not_called()
112 'specify "vim_account" or "paas_account", both options can not be empty'
114 assert result
.exception
115 assert isinstance(result
.exception
, ClientException
)
116 assert expected_msg
in str(result
.exception
)