Fix pool tests in py3

This fixes an assertion which was trying to sort dictionaries: it works
around it by comparing items instead.

Change-Id: Iaa9764102a18d4b4cd6c2042791991ae1ab114e3
This commit is contained in:
Thomas Herve 2017-06-29 09:48:03 +02:00
parent ff32da0bcc
commit e0a670a030
2 changed files with 22 additions and 22 deletions

View File

@ -74,10 +74,10 @@ def deep_sort_lists(obj):
"""Sort lists nested in dictionaries """Sort lists nested in dictionaries
""" """
if isinstance(obj, dict): if isinstance(obj, dict):
return {k: deep_sort_lists(obj[k]) for k in obj} return sorted((k, deep_sort_lists(obj[k])) for k in obj)
if isinstance(obj, list): if isinstance(obj, list):
return [deep_sort_lists(v) for v in sorted(obj)] return sorted(deep_sort_lists(v) for v in obj)
return obj return obj
@ -87,25 +87,26 @@ class poolTest(oslotest.base.BaseTestCase):
def test_init_from_config(self): def test_init_from_config(self):
pool = objects.Pool.from_config(mock_conf, pool = objects.Pool.from_config(mock_conf,
'769ca3fc-5924-4a44-8c1f-7efbe52fbd59') '769ca3fc-5924-4a44-8c1f-7efbe52fbd59')
expected = {'also_notifies': [{'host': '1.0.0.0', 'port': 1}, expected = [('also_notifies', [[('host', '1.0.0.0'), ('port', 1)],
{'host': '2.0.0.0', 'port': 2}], [('host', '2.0.0.0'), ('port', 2)]]),
'description': 'Pool built from configuration on foohost', ('description', 'Pool built from configuration on foohost'), # noqa
'id': '769ca3fc-5924-4a44-8c1f-7efbe52fbd59', ('id', '769ca3fc-5924-4a44-8c1f-7efbe52fbd59'),
'nameservers': [{'host': 'pool_host_1', ('nameservers', [[('host', 'pool_host_1'),
'id': '169ca3fc-5924-4a44-8c1f-7efbe52fbd59', # noqa ('id', '169ca3fc-5924-4a44-8c1f-7efbe52fbd59'), # noqa
'port': 123}, ('port', 123)],
{'host': 'pool_host_2', [('host', 'pool_host_2'),
'id': '269ca3fc-5924-4a44-8c1f-7efbe52fbd59', # noqa ('id', '269ca3fc-5924-4a44-8c1f-7efbe52fbd59'), # noqa
'port': 456}], ('port', 456)]]),
'targets': [{'id': '1588652b-50e7-46b9-b688-a9bad40a873e', ('targets', [[('id', '1588652b-50e7-46b9-b688-a9bad40a873e'), # noqa
'masters': [], ('masters', []),
'options': [{'key': 'a', 'value': '1'}, ('options', [[('key', 'a'), ('value', '1')],
{'key': 'b', 'value': '2'}], [('key', 'b'), ('value', '2')]]),
'type': 't1'}, ('type', 't1')],
{'id': '2588652b-50e7-46b9-b688-a9bad40a873e', [('id', '2588652b-50e7-46b9-b688-a9bad40a873e'), # noqa
'masters': [{'host': '1.1.1.1', 'port': 11}], ('masters', [[('host', '1.1.1.1'),
'options': [], ('port', 11)]]),
'type': 't2'}]} ('options', []),
('type', 't2')]])]
actual = deep_sort_lists(pool.to_dict()) actual = deep_sort_lists(pool.to_dict())
self.assertEqual(actual, expected) self.assertEqual(actual, expected)

View File

@ -1,3 +1,2 @@
# Blacklist of tests failing on Python 3 # Blacklist of tests failing on Python 3
designate.tests.unit.test_pool
designate.tests.unit.test_producer.test_tasks designate.tests.unit.test_producer.test_tasks