|
18 | 18 | from openstackclient.tests import utils |
19 | 19 |
|
20 | 20 |
|
| 21 | +def _add_common_argument(parser): |
| 22 | + parser.add_argument( |
| 23 | + 'common', |
| 24 | + metavar='<common>', |
| 25 | + help='Common argument', |
| 26 | + ) |
| 27 | + return parser |
| 28 | + |
| 29 | + |
| 30 | +def _add_network_argument(parser): |
| 31 | + parser.add_argument( |
| 32 | + 'network', |
| 33 | + metavar='<network>', |
| 34 | + help='Network argument', |
| 35 | + ) |
| 36 | + return parser |
| 37 | + |
| 38 | + |
| 39 | +def _add_compute_argument(parser): |
| 40 | + parser.add_argument( |
| 41 | + 'compute', |
| 42 | + metavar='<compute>', |
| 43 | + help='Compute argument', |
| 44 | + ) |
| 45 | + return parser |
| 46 | + |
| 47 | + |
21 | 48 | class FakeNetworkAndComputeCommand(common.NetworkAndComputeCommand): |
22 | 49 | def update_parser_common(self, parser): |
23 | | - parser.add_argument( |
24 | | - 'common', |
25 | | - metavar='<common>', |
26 | | - help='Common argument', |
27 | | - ) |
28 | | - return parser |
| 50 | + return _add_common_argument(parser) |
29 | 51 |
|
30 | 52 | def update_parser_network(self, parser): |
31 | | - parser.add_argument( |
32 | | - 'network', |
33 | | - metavar='<network>', |
34 | | - help='Network argument', |
35 | | - ) |
36 | | - return parser |
| 53 | + return _add_network_argument(parser) |
37 | 54 |
|
38 | 55 | def update_parser_compute(self, parser): |
39 | | - parser.add_argument( |
40 | | - 'compute', |
41 | | - metavar='<compute>', |
42 | | - help='Compute argument', |
43 | | - ) |
44 | | - return parser |
| 56 | + return _add_compute_argument(parser) |
45 | 57 |
|
46 | 58 | def take_action_network(self, client, parsed_args): |
47 | | - client.network_action(parsed_args) |
48 | | - return 'take_action_network' |
| 59 | + return client.network_action(parsed_args) |
49 | 60 |
|
50 | 61 | def take_action_compute(self, client, parsed_args): |
51 | | - client.compute_action(parsed_args) |
52 | | - return 'take_action_compute' |
| 62 | + return client.compute_action(parsed_args) |
| 63 | + |
53 | 64 |
|
| 65 | +class FakeNetworkAndComputeLister(common.NetworkAndComputeLister): |
| 66 | + def update_parser_common(self, parser): |
| 67 | + return _add_common_argument(parser) |
| 68 | + |
| 69 | + def update_parser_network(self, parser): |
| 70 | + return _add_network_argument(parser) |
54 | 71 |
|
55 | | -class TestNetworkAndComputeCommand(utils.TestCommand): |
| 72 | + def update_parser_compute(self, parser): |
| 73 | + return _add_compute_argument(parser) |
| 74 | + |
| 75 | + def take_action_network(self, client, parsed_args): |
| 76 | + return client.network_action(parsed_args) |
| 77 | + |
| 78 | + def take_action_compute(self, client, parsed_args): |
| 79 | + return client.compute_action(parsed_args) |
| 80 | + |
| 81 | + |
| 82 | +class FakeNetworkAndComputeShowOne(common.NetworkAndComputeShowOne): |
| 83 | + def update_parser_common(self, parser): |
| 84 | + return _add_common_argument(parser) |
| 85 | + |
| 86 | + def update_parser_network(self, parser): |
| 87 | + return _add_network_argument(parser) |
| 88 | + |
| 89 | + def update_parser_compute(self, parser): |
| 90 | + return _add_compute_argument(parser) |
| 91 | + |
| 92 | + def take_action_network(self, client, parsed_args): |
| 93 | + return client.network_action(parsed_args) |
| 94 | + |
| 95 | + def take_action_compute(self, client, parsed_args): |
| 96 | + return client.compute_action(parsed_args) |
| 97 | + |
| 98 | + |
| 99 | +class TestNetworkAndCompute(utils.TestCommand): |
56 | 100 | def setUp(self): |
57 | | - super(TestNetworkAndComputeCommand, self).setUp() |
| 101 | + super(TestNetworkAndCompute, self).setUp() |
58 | 102 |
|
59 | 103 | self.namespace = argparse.Namespace() |
60 | 104 |
|
61 | 105 | # Create network client mocks. |
62 | 106 | self.app.client_manager.network = mock.Mock() |
63 | 107 | self.network = self.app.client_manager.network |
64 | | - self.network.network_action = mock.Mock(return_value=None) |
| 108 | + self.network.network_action = mock.Mock( |
| 109 | + return_value='take_action_network') |
65 | 110 |
|
66 | 111 | # Create compute client mocks. |
67 | 112 | self.app.client_manager.compute = mock.Mock() |
68 | 113 | self.compute = self.app.client_manager.compute |
69 | | - self.compute.compute_action = mock.Mock(return_value=None) |
| 114 | + self.compute.compute_action = mock.Mock( |
| 115 | + return_value='take_action_compute') |
70 | 116 |
|
71 | | - # Get the command object to test |
| 117 | + # Subclasses can override the command object to test. |
72 | 118 | self.cmd = FakeNetworkAndComputeCommand(self.app, self.namespace) |
73 | 119 |
|
74 | 120 | def test_take_action_network(self): |
@@ -101,3 +147,21 @@ def test_take_action_compute(self): |
101 | 147 | result = self.cmd.take_action(parsed_args) |
102 | 148 | self.compute.compute_action.assert_called_with(parsed_args) |
103 | 149 | self.assertEqual('take_action_compute', result) |
| 150 | + |
| 151 | + |
| 152 | +class TestNetworkAndComputeCommand(TestNetworkAndCompute): |
| 153 | + def setUp(self): |
| 154 | + super(TestNetworkAndComputeCommand, self).setUp() |
| 155 | + self.cmd = FakeNetworkAndComputeCommand(self.app, self.namespace) |
| 156 | + |
| 157 | + |
| 158 | +class TestNetworkAndComputeLister(TestNetworkAndCompute): |
| 159 | + def setUp(self): |
| 160 | + super(TestNetworkAndComputeLister, self).setUp() |
| 161 | + self.cmd = FakeNetworkAndComputeLister(self.app, self.namespace) |
| 162 | + |
| 163 | + |
| 164 | +class TestNetworkAndComputeShowOne(TestNetworkAndCompute): |
| 165 | + def setUp(self): |
| 166 | + super(TestNetworkAndComputeShowOne, self).setUp() |
| 167 | + self.cmd = FakeNetworkAndComputeShowOne(self.app, self.namespace) |
0 commit comments