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
This commit is contained in:
@@ -11,8 +11,13 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import argparse
|
||||
import mock
|
||||
|
||||
from openstackclient.api import network_v2
|
||||
from openstackclient.tests import fakes
|
||||
from openstackclient.tests import utils
|
||||
|
||||
extension_name = 'Matrix'
|
||||
extension_namespace = 'http://docs.openstack.org/network/'
|
||||
extension_description = 'Simulated reality'
|
||||
@@ -33,3 +38,20 @@ NETEXT = {
|
||||
class FakeNetworkV2Client(object):
|
||||
def __init__(self, **kwargs):
|
||||
self.list_extensions = mock.Mock(return_value={'extensions': [NETEXT]})
|
||||
|
||||
|
||||
class TestNetworkV2(utils.TestCommand):
|
||||
def setUp(self):
|
||||
super(TestNetworkV2, self).setUp()
|
||||
|
||||
self.namespace = argparse.Namespace()
|
||||
|
||||
self.app.client_manager.network = FakeNetworkV2Client(
|
||||
endpoint=fakes.AUTH_URL,
|
||||
token=fakes.AUTH_TOKEN,
|
||||
)
|
||||
|
||||
self.app.client_manager.network.api = network_v2.APIv2(
|
||||
session=mock.Mock(),
|
||||
service_type="network",
|
||||
)
|
||||
|
@@ -20,6 +20,7 @@ from openstackclient.tests import fakes
|
||||
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes_v2
|
||||
from openstackclient.tests.identity.v3 import fakes as identity_fakes_v3
|
||||
from openstackclient.tests.network import common
|
||||
from openstackclient.tests.network.v2 import fakes as network_fakes
|
||||
|
||||
RESOURCE = 'network'
|
||||
RESOURCES = 'networks'
|
||||
@@ -59,6 +60,18 @@ FILTERED = [
|
||||
]
|
||||
|
||||
|
||||
class TestNetwork(network_fakes.TestNetworkV2):
|
||||
|
||||
def setUp(self):
|
||||
super(TestNetwork, self).setUp()
|
||||
|
||||
# Get a shortcut to the network client
|
||||
self.network = self.app.client_manager.network
|
||||
|
||||
# Get a shortcut to the APIManager
|
||||
self.api = self.app.client_manager.network.api
|
||||
|
||||
|
||||
class TestCreateNetwork(common.TestNetworkBase):
|
||||
def test_create_no_options(self):
|
||||
arglist = [
|
||||
|
Reference in New Issue
Block a user