|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | +# |
| 13 | + |
| 14 | +from osc_lib import exceptions |
| 15 | + |
| 16 | +from openstackclient.network.v2 import floating_ip_pool |
| 17 | +from openstackclient.tests.compute.v2 import fakes as compute_fakes |
| 18 | +from openstackclient.tests.network.v2 import fakes as network_fakes |
| 19 | + |
| 20 | + |
| 21 | +# Tests for Network API v2 |
| 22 | +# |
| 23 | +class TestFloatingIPPoolNetwork(network_fakes.TestNetworkV2): |
| 24 | + |
| 25 | + def setUp(self): |
| 26 | + super(TestFloatingIPPoolNetwork, self).setUp() |
| 27 | + |
| 28 | + # Get a shortcut to the network client |
| 29 | + self.network = self.app.client_manager.network |
| 30 | + |
| 31 | + |
| 32 | +class TestListFloatingIPPoolNetwork(TestFloatingIPPoolNetwork): |
| 33 | + |
| 34 | + def setUp(self): |
| 35 | + super(TestListFloatingIPPoolNetwork, self).setUp() |
| 36 | + |
| 37 | + # Get the command object to test |
| 38 | + self.cmd = floating_ip_pool.ListFloatingIPPool(self.app, |
| 39 | + self.namespace) |
| 40 | + |
| 41 | + def test_floating_ip_list(self): |
| 42 | + arglist = [] |
| 43 | + verifylist = [] |
| 44 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 45 | + |
| 46 | + self.assertRaises(exceptions.CommandError, self.cmd.take_action, |
| 47 | + parsed_args) |
| 48 | + |
| 49 | + |
| 50 | +# Tests for Compute network |
| 51 | +# |
| 52 | +class TestFloatingIPPoolCompute(compute_fakes.TestComputev2): |
| 53 | + |
| 54 | + def setUp(self): |
| 55 | + super(TestFloatingIPPoolCompute, self).setUp() |
| 56 | + |
| 57 | + # Get a shortcut to the compute client |
| 58 | + self.compute = self.app.client_manager.compute |
| 59 | + |
| 60 | + |
| 61 | +class TestListFloatingIPPoolCompute(TestFloatingIPPoolCompute): |
| 62 | + |
| 63 | + # The floating ip pools to list up |
| 64 | + floating_ip_pools = \ |
| 65 | + compute_fakes.FakeFloatingIPPool.create_floating_ip_pools(count=3) |
| 66 | + |
| 67 | + columns = ( |
| 68 | + 'Name', |
| 69 | + ) |
| 70 | + |
| 71 | + data = [] |
| 72 | + for pool in floating_ip_pools: |
| 73 | + data.append(( |
| 74 | + pool.name, |
| 75 | + )) |
| 76 | + |
| 77 | + def setUp(self): |
| 78 | + super(TestListFloatingIPPoolCompute, self).setUp() |
| 79 | + |
| 80 | + self.app.client_manager.network_endpoint_enabled = False |
| 81 | + |
| 82 | + self.compute.floating_ip_pools.list.return_value = \ |
| 83 | + self.floating_ip_pools |
| 84 | + |
| 85 | + # Get the command object to test |
| 86 | + self.cmd = floating_ip_pool.ListFloatingIPPool(self.app, None) |
| 87 | + |
| 88 | + def test_floating_ip_list(self): |
| 89 | + arglist = [] |
| 90 | + verifylist = [] |
| 91 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 92 | + |
| 93 | + columns, data = self.cmd.take_action(parsed_args) |
| 94 | + |
| 95 | + self.compute.floating_ip_pools.list.assert_called_once_with() |
| 96 | + self.assertEqual(self.columns, columns) |
| 97 | + self.assertEqual(self.data, list(data)) |
0 commit comments