From f2e99ed6c7e77a50045fee859aa506d1bcb802d6 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Thu, 3 Sep 2015 08:57:21 +0200 Subject: [PATCH] test: remove duplicated code --- gnocchiclient/tests/functional/base.py | 23 ++++++++++++++++ .../tests/functional/test_archive_policy.py | 26 ------------------- .../functional/test_archive_policy_rule.py | 26 ------------------- .../tests/functional/test_resource.py | 25 ------------------ 4 files changed, 23 insertions(+), 77 deletions(-) diff --git a/gnocchiclient/tests/functional/base.py b/gnocchiclient/tests/functional/base.py index 8b54003..79bc58c 100644 --- a/gnocchiclient/tests/functional/base.py +++ b/gnocchiclient/tests/functional/base.py @@ -84,3 +84,26 @@ class ClientTestBase(base.ClientTestBase): def gnocchi(self, *args, **kwargs): return self.clients.gnocchi(*args, **kwargs) + + def details_multiple(self, output_lines, with_label=False): + """Return list of dicts with item details from cli output tables. + + If with_label is True, key '__label' is added to each items dict. + For more about 'label' see OutputParser.tables(). + + NOTE(sileht): come from tempest-lib just because cliff use + Field instead of Property as first columun header. + """ + items = [] + tables_ = self.parser.tables(output_lines) + for table_ in tables_: + if ('Field' not in table_['headers'] + or 'Value' not in table_['headers']): + raise exceptions.InvalidStructure() + item = {} + for value in table_['values']: + item[value[0]] = value[1] + if with_label: + item['__label'] = table_['label'] + items.append(item) + return items diff --git a/gnocchiclient/tests/functional/test_archive_policy.py b/gnocchiclient/tests/functional/test_archive_policy.py index f2237f2..47dd92c 100644 --- a/gnocchiclient/tests/functional/test_archive_policy.py +++ b/gnocchiclient/tests/functional/test_archive_policy.py @@ -10,36 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. -from tempest_lib import exceptions - from gnocchiclient.tests.functional import base class ArchivePolicyClientTest(base.ClientTestBase): - - def details_multiple(self, output_lines, with_label=False): - """Return list of dicts with item details from cli output tables. - - If with_label is True, key '__label' is added to each items dict. - For more about 'label' see OutputParser.tables(). - - NOTE(sileht): come from tempest-lib just because cliff use - Field instead of Property as first columun header. - """ - items = [] - tables_ = self.parser.tables(output_lines) - for table_ in tables_: - if ('Field' not in table_['headers'] - or 'Value' not in table_['headers']): - raise exceptions.InvalidStructure() - item = {} - for value in table_['values']: - item[value[0]] = value[1] - if with_label: - item['__label'] = table_['label'] - items.append(item) - return items - def test_archive_policy_scenario(self): # CREATE result = self.gnocchi( diff --git a/gnocchiclient/tests/functional/test_archive_policy_rule.py b/gnocchiclient/tests/functional/test_archive_policy_rule.py index 96af076..61a225a 100644 --- a/gnocchiclient/tests/functional/test_archive_policy_rule.py +++ b/gnocchiclient/tests/functional/test_archive_policy_rule.py @@ -10,36 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. -from tempest_lib import exceptions - from gnocchiclient.tests.functional import base class ArchivePolicyRuleClientTest(base.ClientTestBase): - - def details_multiple(self, output_lines, with_label=False): - """Return list of dicts with item details from cli output tables. - - If with_label is True, key '__label' is added to each items dict. - For more about 'label' see OutputParser.tables(). - - NOTE(sileht): come from tempest-lib just because cliff use - Field instead of Property as first columun header. - """ - items = [] - tables_ = self.parser.tables(output_lines) - for table_ in tables_: - if ('Field' not in table_['headers'] - or 'Value' not in table_['headers']): - raise exceptions.InvalidStructure() - item = {} - for value in table_['values']: - item[value[0]] = value[1] - if with_label: - item['__label'] = table_['label'] - items.append(item) - return items - def test_archive_policy_rule_scenario(self): # CREATE result = self.gnocchi( diff --git a/gnocchiclient/tests/functional/test_resource.py b/gnocchiclient/tests/functional/test_resource.py index 4349743..071c8d0 100644 --- a/gnocchiclient/tests/functional/test_resource.py +++ b/gnocchiclient/tests/functional/test_resource.py @@ -12,8 +12,6 @@ import uuid -from tempest_lib import exceptions - from gnocchiclient.tests.functional import base @@ -22,29 +20,6 @@ class ResourceClientTest(base.ClientTestBase): RESOURCE_ID2 = str(uuid.uuid4()) PROJECT_ID = str(uuid.uuid4()) - def details_multiple(self, output_lines, with_label=False): - """Return list of dicts with item details from cli output tables. - - If with_label is True, key '__label' is added to each items dict. - For more about 'label' see OutputParser.tables(). - - NOTE(sileht): come from tempest-lib just because cliff use - Field instead of Property as first columun header. - """ - items = [] - tables_ = self.parser.tables(output_lines) - for table_ in tables_: - if ('Field' not in table_['headers'] - or 'Value' not in table_['headers']): - raise exceptions.InvalidStructure() - item = {} - for value in table_['values']: - item[value[0]] = value[1] - if with_label: - item['__label'] = table_['label'] - items.append(item) - return items - def test_resource_scenario(self): # CREATE result = self.gnocchi(