Skip to content

Commit a42e560

Browse files
committed
tests: Move assert helpers to utils.TestCommand
Move assertItemEqual() and assertListItemEqual() from fwaas/test_rule.py to openstackclient.tests.unit.utils.TestCommand so network tests can use them without inheriting from both utils.TestCommand and osc_lib.test.base.TestCommand. Add a TODO to eventually replace utils.TestCommand with osc_lib.test.base.TestCommand once osc-lib provides the same functionality as current openstackclient.tests.unit.utils.TestCommand class and once current one will be replaced with osc_lib one. Assisted-by: Cursor Composer 2.5 Change-Id: I88fdab495a486c1166023287936764f5cf2bc918 Signed-off-by: Slawek Kaplonski <skaplons@redhat.com>
1 parent caec5c3 commit a42e560

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

openstackclient/tests/unit/network/v2/fwaas/test_rule.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import re
1818
from unittest import mock
1919

20-
from cliff import columns as cliff_columns
2120
from openstack.network.v2 import firewall_rule
2221
from openstack.test import fakes as sdk_fakes
2322
from osc_lib import exceptions
@@ -79,26 +78,6 @@ def check_results(self, headers, data, exp_req=None, is_list=False):
7978
self.mocked.assert_called_once_with(**req_body)
8079
self.assertEqual(self.ordered_headers, headers)
8180

82-
# TODO(slaweq): remove this method once network_fakes.TestNetworkV2 will
83-
# inherit from the osc_lib.test.base.TestCommand
84-
def assertListItemEqual(self, expected, actual):
85-
self.assertEqual(len(expected), len(actual))
86-
for item_expected, item_actual in zip(expected, actual):
87-
self.assertItemEqual(item_expected, item_actual)
88-
89-
# TODO(slaweq): remove this method once network_fakes.TestNetworkV2 will
90-
# inherit from the osc_lib.test.base.TestCommand
91-
def assertItemEqual(self, expected, actual):
92-
self.assertEqual(len(expected), len(actual))
93-
for col_expected, col_actual in zip(expected, actual):
94-
if isinstance(col_expected, cliff_columns.FormattableColumn):
95-
self.assertIsInstance(col_actual, col_expected.__class__)
96-
self.assertEqual(
97-
col_expected.human_readable(), col_actual.human_readable()
98-
)
99-
else:
100-
self.assertEqual(col_expected, col_actual)
101-
10281
def setUp(self):
10382
super().setUp()
10483

openstackclient/tests/unit/utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io
1818
import os
1919

20+
from cliff import columns as cliff_columns
2021
import fixtures
2122
import testtools
2223

@@ -69,6 +70,28 @@ def assertNotCalled(self, m, msg=None):
6970
class TestCommand(TestCase):
7071
"""Test cliff command classes"""
7172

73+
# TODO(slaweq): Remove those methods in favour of the ones in
74+
# osc_lib.test.base.TestCommand once osc-lib TestCommand
75+
# provides all of the same functionality as this TestCommand
76+
# like e.g. the monkey patching for sys.stderr and this one can be
77+
# removed.
78+
79+
def assertListItemEqual(self, expected, actual):
80+
self.assertEqual(len(expected), len(actual))
81+
for item_expected, item_actual in zip(expected, actual):
82+
self.assertItemEqual(item_expected, item_actual)
83+
84+
def assertItemEqual(self, expected, actual):
85+
self.assertEqual(len(expected), len(actual))
86+
for col_expected, col_actual in zip(expected, actual):
87+
if isinstance(col_expected, cliff_columns.FormattableColumn):
88+
self.assertIsInstance(col_actual, col_expected.__class__)
89+
self.assertEqual(
90+
col_expected.human_readable(), col_actual.human_readable()
91+
)
92+
else:
93+
self.assertEqual(col_expected, col_actual)
94+
7295
def setUp(self):
7396
super().setUp()
7497
# Build up a fake app

0 commit comments

Comments
 (0)