Skip to content

Commit 29b9945

Browse files
committed
Refactor network test: Introduce TestNetworkv2 and TestNetwork to improve unit test of network
The class inherit architecture in network unit test is different from other test classes, which leads to lots of redundant code. This patch will make it the same as the other test classes. And it will be more convenience for the coming up refactor. Change-Id: I6f239dd54b9401ff2bbcf7ffdeb18769a450f573 Implements: blueprint osc-network-unit-test-refactor Related-to: blueprint neutron-client
1 parent ff48f92 commit 29b9945

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

openstackclient/tests/network/v2/fakes.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111
# under the License.
1212
#
1313

14+
import argparse
1415
import mock
1516

17+
from openstackclient.api import network_v2
18+
from openstackclient.tests import fakes
19+
from openstackclient.tests import utils
20+
1621
extension_name = 'Matrix'
1722
extension_namespace = 'http://docs.openstack.org/network/'
1823
extension_description = 'Simulated reality'
@@ -33,3 +38,20 @@
3338
class FakeNetworkV2Client(object):
3439
def __init__(self, **kwargs):
3540
self.list_extensions = mock.Mock(return_value={'extensions': [NETEXT]})
41+
42+
43+
class TestNetworkV2(utils.TestCommand):
44+
def setUp(self):
45+
super(TestNetworkV2, self).setUp()
46+
47+
self.namespace = argparse.Namespace()
48+
49+
self.app.client_manager.network = FakeNetworkV2Client(
50+
endpoint=fakes.AUTH_URL,
51+
token=fakes.AUTH_TOKEN,
52+
)
53+
54+
self.app.client_manager.network.api = network_v2.APIv2(
55+
session=mock.Mock(),
56+
service_type="network",
57+
)

openstackclient/tests/network/v2/test_network.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes_v2
2121
from openstackclient.tests.identity.v3 import fakes as identity_fakes_v3
2222
from openstackclient.tests.network import common
23+
from openstackclient.tests.network.v2 import fakes as network_fakes
2324

2425
RESOURCE = 'network'
2526
RESOURCES = 'networks'
@@ -59,6 +60,18 @@
5960
]
6061

6162

63+
class TestNetwork(network_fakes.TestNetworkV2):
64+
65+
def setUp(self):
66+
super(TestNetwork, self).setUp()
67+
68+
# Get a shortcut to the network client
69+
self.network = self.app.client_manager.network
70+
71+
# Get a shortcut to the APIManager
72+
self.api = self.app.client_manager.network.api
73+
74+
6275
class TestCreateNetwork(common.TestNetworkBase):
6376
def test_create_no_options(self):
6477
arglist = [

0 commit comments

Comments
 (0)