test: remove duplicated code
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user