Fix incorrect unit test for router
Command "router show" will display router's "tenant_id" as "project_id". But in the unit test, it checks "tenant_id", which is incorrect. This patch fix this problem, and add a _get_columns() helper function to simplify the code. Change-Id: I0087ef7dfd0130b6c47222495848c4f2b9804b1b
This commit is contained in:
@@ -41,6 +41,14 @@ _formatters = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _get_columns(item):
|
||||||
|
columns = item.keys()
|
||||||
|
if 'tenant_id' in columns:
|
||||||
|
columns.remove('tenant_id')
|
||||||
|
columns.append('project_id')
|
||||||
|
return tuple(sorted(columns))
|
||||||
|
|
||||||
|
|
||||||
def _get_attrs(client_manager, parsed_args):
|
def _get_attrs(client_manager, parsed_args):
|
||||||
attrs = {}
|
attrs = {}
|
||||||
if parsed_args.name is not None:
|
if parsed_args.name is not None:
|
||||||
@@ -129,14 +137,10 @@ class CreateRouter(command.ShowOne):
|
|||||||
attrs = _get_attrs(self.app.client_manager, parsed_args)
|
attrs = _get_attrs(self.app.client_manager, parsed_args)
|
||||||
obj = client.create_router(**attrs)
|
obj = client.create_router(**attrs)
|
||||||
|
|
||||||
columns = sorted(obj.keys())
|
columns = _get_columns(obj)
|
||||||
data = utils.get_item_properties(obj, columns, formatters=_formatters)
|
data = utils.get_item_properties(obj, columns, formatters=_formatters)
|
||||||
|
|
||||||
if 'tenant_id' in columns:
|
return columns, data
|
||||||
# Rename "tenant_id" to "project_id".
|
|
||||||
index = columns.index('tenant_id')
|
|
||||||
columns[index] = 'project_id'
|
|
||||||
return (tuple(columns), data)
|
|
||||||
|
|
||||||
|
|
||||||
class DeleteRouter(command.Command):
|
class DeleteRouter(command.Command):
|
||||||
@@ -312,6 +316,6 @@ class ShowRouter(command.ShowOne):
|
|||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
client = self.app.client_manager.network
|
client = self.app.client_manager.network
|
||||||
obj = client.find_router(parsed_args.router, ignore_missing=False)
|
obj = client.find_router(parsed_args.router, ignore_missing=False)
|
||||||
columns = sorted(obj.keys())
|
columns = _get_columns(obj)
|
||||||
data = utils.get_item_properties(obj, columns, formatters=_formatters)
|
data = utils.get_item_properties(obj, columns, formatters=_formatters)
|
||||||
return (tuple(columns), data)
|
return columns, data
|
||||||
|
@@ -370,6 +370,10 @@ class FakeRouter(object):
|
|||||||
router = fakes.FakeResource(info=copy.deepcopy(router_attrs),
|
router = fakes.FakeResource(info=copy.deepcopy(router_attrs),
|
||||||
methods=copy.deepcopy(router_methods),
|
methods=copy.deepcopy(router_methods),
|
||||||
loaded=True)
|
loaded=True)
|
||||||
|
|
||||||
|
# Set attributes with special mapping in OpenStack SDK.
|
||||||
|
router.project_id = router_attrs['tenant_id']
|
||||||
|
|
||||||
return router
|
return router
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@@ -383,7 +383,7 @@ class TestShowRouter(TestRouter):
|
|||||||
'ha',
|
'ha',
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name',
|
||||||
'tenant_id',
|
'project_id',
|
||||||
)
|
)
|
||||||
|
|
||||||
data = (
|
data = (
|
||||||
@@ -392,7 +392,7 @@ class TestShowRouter(TestRouter):
|
|||||||
_router.ha,
|
_router.ha,
|
||||||
_router.id,
|
_router.id,
|
||||||
_router.name,
|
_router.name,
|
||||||
_router.tenant_id,
|
_router.project_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
Reference in New Issue
Block a user