Fix list VNF/Subscription UT error
This patch resolves the following error caused by using one data in multiple tests. ----- ft1.2: tackerclient.tests.unit.osc.v1.test_vnflcm_subsc. TestListLccnSubscription.test_take_action_with_ paginationtesttools.testresult.real._StringException: Traceback (most recent call last): File "/home/zuul/src/opendev.org/openstack/ python-tackerclient/tackerclient/tests/unit/osc/v1 /test_vnflcm_subsc.py", line 139, in test_take_action_with_ pagination expected_data.append(vnflcm_subsc_fakes.get_subscription_ data( File "/home/zuul/src/opendev.org/openstack /python-tackerclient/tackerclient/tests/unit/osc/v1 /vnflcm_subsc_fakes.py", line 166, in get_subscription_data subscription.pop(item) KeyError: 'filter' ----- Add test data for each test. (Three data are set for each test data so that the first, last, and other values can be checked.) And change not to modify test data directly in get method. Closes-Bug: #2007524 Change-Id: Id3919fc638f6b858c115a3a7d7e4ca60036217d4
This commit is contained in:
parent
156deea66c
commit
a41323dc1d
tackerclient/tests/unit/osc/v1
@ -157,25 +157,24 @@ class TestShowVnfLcm(TestVnfLcm):
|
||||
|
||||
class TestListVnfLcm(TestVnfLcm):
|
||||
|
||||
vnf_instances = vnflcm_fakes.create_vnf_instances(count=3)
|
||||
|
||||
def setUp(self):
|
||||
super(TestListVnfLcm, self).setUp()
|
||||
self.list_vnf_instance = vnflcm.ListVnfLcm(
|
||||
self.app, self.app_args, cmd_name='vnflcm list')
|
||||
|
||||
def test_take_action(self):
|
||||
vnf_instances = vnflcm_fakes.create_vnf_instances(count=3)
|
||||
parsed_args = self.check_parser(self.list_vnf_instance, [], [])
|
||||
self.requests_mock.register_uri(
|
||||
'GET', os.path.join(self.url, 'vnflcm/v1/vnf_instances'),
|
||||
json=self.vnf_instances, headers=self.header)
|
||||
json=vnf_instances, headers=self.header)
|
||||
actual_columns, data = self.list_vnf_instance.take_action(parsed_args)
|
||||
|
||||
headers, columns = tacker_osc_utils.get_column_definitions(
|
||||
vnflcm._attr_map, long_listing=True)
|
||||
|
||||
expected_data = []
|
||||
for vnf_instance_obj in self.vnf_instances:
|
||||
for vnf_instance_obj in vnf_instances:
|
||||
expected_data.append(vnflcm_fakes.get_vnflcm_data(
|
||||
vnf_instance_obj, columns=columns, list_action=True))
|
||||
|
||||
@ -184,6 +183,7 @@ class TestListVnfLcm(TestVnfLcm):
|
||||
self.assertCountEqual(expected_data, list(data))
|
||||
|
||||
def test_take_action_with_pagination(self):
|
||||
vnf_instances = vnflcm_fakes.create_vnf_instances(count=3)
|
||||
next_links_num = 3
|
||||
parsed_args = self.check_parser(self.list_vnf_instance, [], [])
|
||||
path = os.path.join(self.url, 'vnflcm/v1/vnf_instances')
|
||||
@ -195,18 +195,18 @@ class TestListVnfLcm(TestVnfLcm):
|
||||
links[i] = (
|
||||
'{base_url}?nextpage_opaque_marker={vnf_instance_id}'.format(
|
||||
base_url=path,
|
||||
vnf_instance_id=self.vnf_instances[i]['id']))
|
||||
vnf_instance_id=vnf_instances[i]['id']))
|
||||
link_headers[i] = copy.deepcopy(self.header)
|
||||
link_headers[i]['Link'] = '<{link_url}>; rel="next"'.format(
|
||||
link_url=links[i])
|
||||
|
||||
self.requests_mock.register_uri(
|
||||
'GET', path, json=[self.vnf_instances[0]], headers=link_headers[0])
|
||||
'GET', path, json=[vnf_instances[0]], headers=link_headers[0])
|
||||
self.requests_mock.register_uri(
|
||||
'GET', links[0], json=[self.vnf_instances[1]],
|
||||
'GET', links[0], json=[vnf_instances[1]],
|
||||
headers=link_headers[1])
|
||||
self.requests_mock.register_uri(
|
||||
'GET', links[1], json=[self.vnf_instances[2]],
|
||||
'GET', links[1], json=[vnf_instances[2]],
|
||||
headers=link_headers[2])
|
||||
self.requests_mock.register_uri(
|
||||
'GET', links[2], json=[], headers=self.header)
|
||||
@ -217,7 +217,7 @@ class TestListVnfLcm(TestVnfLcm):
|
||||
vnflcm._attr_map, long_listing=True)
|
||||
|
||||
expected_data = []
|
||||
for vnf_instance_obj in self.vnf_instances:
|
||||
for vnf_instance_obj in vnf_instances:
|
||||
expected_data.append(vnflcm_fakes.get_vnflcm_data(
|
||||
vnf_instance_obj, columns=columns, list_action=True))
|
||||
|
||||
|
@ -74,25 +74,24 @@ class TestCreateLccnSubscription(test_vnflcm.TestVnfLcm):
|
||||
|
||||
class TestListLccnSubscription(test_vnflcm.TestVnfLcm):
|
||||
|
||||
subscriptions = vnflcm_subsc_fakes.create_subscriptions(count=3)
|
||||
|
||||
def setUp(self):
|
||||
super(TestListLccnSubscription, self).setUp()
|
||||
self.list_subscription = vnflcm_subsc.ListLccnSubscription(
|
||||
self.app, self.app_args, cmd_name='vnflcm subsc list')
|
||||
|
||||
def test_take_action(self):
|
||||
subscriptions = vnflcm_subsc_fakes.create_subscriptions(count=3)
|
||||
parsed_args = self.check_parser(self.list_subscription, [], [])
|
||||
self.requests_mock.register_uri(
|
||||
'GET', os.path.join(self.url, 'vnflcm/v1/subscriptions'),
|
||||
json=self.subscriptions, headers=self.header)
|
||||
json=subscriptions, headers=self.header)
|
||||
actual_columns, data = self.list_subscription.take_action(parsed_args)
|
||||
|
||||
headers, columns = tacker_osc_utils.get_column_definitions(
|
||||
self.list_subscription.get_attributes(), long_listing=True)
|
||||
|
||||
expected_data = []
|
||||
for subscription_obj in self.subscriptions:
|
||||
for subscription_obj in subscriptions:
|
||||
expected_data.append(vnflcm_subsc_fakes.get_subscription_data(
|
||||
subscription_obj, columns=columns, list_action=True))
|
||||
|
||||
@ -101,6 +100,7 @@ class TestListLccnSubscription(test_vnflcm.TestVnfLcm):
|
||||
self.assertCountEqual(expected_data, list(data))
|
||||
|
||||
def test_take_action_with_pagination(self):
|
||||
subscriptions = vnflcm_subsc_fakes.create_subscriptions(count=3)
|
||||
next_links_num = 3
|
||||
path = os.path.join(self.url, 'vnflcm/v1/subscriptions')
|
||||
parsed_args = self.check_parser(self.list_subscription, [], [])
|
||||
@ -112,19 +112,19 @@ class TestListLccnSubscription(test_vnflcm.TestVnfLcm):
|
||||
links[i] = (
|
||||
'{base_url}?nextpage_opaque_marker={subscription_id}'.format(
|
||||
base_url=path,
|
||||
subscription_id=self.subscriptions[i]['id']))
|
||||
subscription_id=subscriptions[i]['id']))
|
||||
|
||||
link_headers[i] = copy.deepcopy(self.header)
|
||||
link_headers[i]['Link'] = '<{link_url}>; rel="next"'.format(
|
||||
link_url=links[i])
|
||||
|
||||
self.requests_mock.register_uri(
|
||||
'GET', path, json=[self.subscriptions[0]], headers=link_headers[0])
|
||||
'GET', path, json=[subscriptions[0]], headers=link_headers[0])
|
||||
self.requests_mock.register_uri(
|
||||
'GET', links[0], json=[self.subscriptions[1]],
|
||||
'GET', links[0], json=[subscriptions[1]],
|
||||
headers=link_headers[1])
|
||||
self.requests_mock.register_uri(
|
||||
'GET', links[1], json=[self.subscriptions[2]],
|
||||
'GET', links[1], json=[subscriptions[2]],
|
||||
headers=link_headers[2])
|
||||
self.requests_mock.register_uri(
|
||||
'GET', links[2], json=[], headers=self.header)
|
||||
@ -135,7 +135,7 @@ class TestListLccnSubscription(test_vnflcm.TestVnfLcm):
|
||||
self.list_subscription.get_attributes(), long_listing=True)
|
||||
|
||||
expected_data = []
|
||||
for subscription_obj in self.subscriptions:
|
||||
for subscription_obj in subscriptions:
|
||||
expected_data.append(vnflcm_subsc_fakes.get_subscription_data(
|
||||
subscription_obj, columns=columns, list_action=True))
|
||||
|
||||
|
@ -121,23 +121,24 @@ def get_vnflcm_data(vnf_instance, list_action=False, columns=None):
|
||||
:return:
|
||||
A tuple object sorted based on the name of the columns.
|
||||
"""
|
||||
vnf = vnf_instance.copy()
|
||||
complex_attributes = ['vimConnectionInfo', 'instantiatedVnfInfo', '_links']
|
||||
for attribute in complex_attributes:
|
||||
if vnf_instance.get(attribute):
|
||||
vnf_instance.update(
|
||||
if vnf.get(attribute):
|
||||
vnf.update(
|
||||
{attribute: tacker_osc_utils.FormatComplexDataColumn(
|
||||
vnf_instance[attribute])})
|
||||
vnf[attribute])})
|
||||
|
||||
if list_action:
|
||||
for item in ['vnfInstanceDescription', 'vnfdVersion']:
|
||||
vnf_instance.pop(item)
|
||||
vnf.pop(item)
|
||||
|
||||
# return the list of data as per column order
|
||||
if columns:
|
||||
return tuple([vnf_instance[key] for key in columns])
|
||||
return tuple([vnf[key] for key in columns])
|
||||
|
||||
return tuple([vnf_instance[key] for key in sorted(
|
||||
vnf_instance.keys())])
|
||||
return tuple([vnf[key] for key in sorted(
|
||||
vnf.keys())])
|
||||
|
||||
|
||||
def create_vnf_instances(count=2):
|
||||
|
@ -154,23 +154,24 @@ def get_subscription_data(subscription, list_action=False, columns=None):
|
||||
:return:
|
||||
A tuple object sorted based on the name of the columns.
|
||||
"""
|
||||
subsc = subscription.copy()
|
||||
complex_attributes = ['filter', '_links']
|
||||
for attribute in complex_attributes:
|
||||
if subscription.get(attribute):
|
||||
subscription.update(
|
||||
if subsc.get(attribute):
|
||||
subsc.update(
|
||||
{attribute: tacker_osc_utils.FormatComplexDataColumn(
|
||||
subscription[attribute])})
|
||||
subsc[attribute])})
|
||||
|
||||
if list_action:
|
||||
for item in ['filter', '_links']:
|
||||
subscription.pop(item)
|
||||
subsc.pop(item)
|
||||
|
||||
# return the list of data as per column order
|
||||
if columns:
|
||||
return tuple([subscription[key] for key in columns])
|
||||
return tuple([subsc[key] for key in columns])
|
||||
|
||||
return tuple([subscription[key] for key in sorted(
|
||||
subscription.keys())])
|
||||
return tuple([subsc[key] for key in sorted(
|
||||
subsc.keys())])
|
||||
|
||||
|
||||
def create_subscriptions(count=2):
|
||||
|
Loading…
x
Reference in New Issue
Block a user