cli: add messages to assertTrue

1) Unify assertion of 'usage: service-name' from
   {cinder, glance, keystone, neutron} help tests
   into assertFirstLineStartsWith method, which provides
   more usefull failure message.
2) Add failure message to assertTrue in keystone-catalog
   test.

Change-Id: I3abba1d9509bee649aa1675beee4153341b1e170
This commit is contained in:
Pavel Sedlák
2013-08-22 21:29:45 +02:00
parent 7395517a5f
commit 4c18fa1bbf
5 changed files with 12 additions and 5 deletions

View File

@@ -134,6 +134,11 @@ class ClientTestBase(tempest.test.BaseTestCase):
for field in field_names: for field in field_names:
self.assertIn(field, item) self.assertIn(field, item)
def assertFirstLineStartsWith(self, lines, beginning):
self.assertTrue(lines[0].startswith(beginning),
msg=('Beginning of first line has invalid content: %s'
% lines[:3]))
class CommandFailed(subprocess.CalledProcessError): class CommandFailed(subprocess.CalledProcessError):
# adds output attribute for python2.6 # adds output attribute for python2.6

View File

@@ -87,7 +87,7 @@ class SimpleReadOnlyCinderClientTest(tempest.cli.ClientTestBase):
def test_admin_help(self): def test_admin_help(self):
help_text = self.cinder('help') help_text = self.cinder('help')
lines = help_text.split('\n') lines = help_text.split('\n')
self.assertTrue(lines[0].startswith('usage: cinder')) self.assertFirstLineStartsWith(lines, 'usage: cinder')
commands = [] commands = []
cmds_start = lines.index('Positional arguments:') cmds_start = lines.index('Positional arguments:')

View File

@@ -48,7 +48,7 @@ class SimpleReadOnlyGlanceClientTest(tempest.cli.ClientTestBase):
def test_glance_help(self): def test_glance_help(self):
help_text = self.glance('help') help_text = self.glance('help')
lines = help_text.split('\n') lines = help_text.split('\n')
self.assertTrue(lines[0].startswith('usage: glance')) self.assertFirstLineStartsWith(lines, 'usage: glance')
commands = [] commands = []
cmds_start = lines.index('Positional arguments:') cmds_start = lines.index('Positional arguments:')

View File

@@ -46,7 +46,9 @@ class SimpleReadOnlyKeystoneClientTest(tempest.cli.ClientTestBase):
out = self.keystone('catalog') out = self.keystone('catalog')
catalog = self.parser.details_multiple(out, with_label=True) catalog = self.parser.details_multiple(out, with_label=True)
for svc in catalog: for svc in catalog:
self.assertTrue(svc['__label'].startswith('Service:')) self.assertTrue(svc['__label'].startswith('Service:'),
msg=('Invalid beginning of service block: %s' %
svc['__label']))
def test_admin_endpoint_list(self): def test_admin_endpoint_list(self):
out = self.keystone('endpoint-list') out = self.keystone('endpoint-list')
@@ -94,7 +96,7 @@ class SimpleReadOnlyKeystoneClientTest(tempest.cli.ClientTestBase):
def test_admin_help(self): def test_admin_help(self):
help_text = self.keystone('help') help_text = self.keystone('help')
lines = help_text.split('\n') lines = help_text.split('\n')
self.assertTrue(lines[0].startswith('usage: keystone')) self.assertFirstLineStartsWith(lines, 'usage: keystone')
commands = [] commands = []
cmds_start = lines.index('Positional arguments:') cmds_start = lines.index('Positional arguments:')

View File

@@ -92,7 +92,7 @@ class SimpleReadOnlyNeutronClientTest(tempest.cli.ClientTestBase):
def test_neutron_help(self): def test_neutron_help(self):
help_text = self.neutron('help') help_text = self.neutron('help')
lines = help_text.split('\n') lines = help_text.split('\n')
self.assertTrue(lines[0].startswith('usage: neutron')) self.assertFirstLineStartsWith(lines, 'usage: neutron')
commands = [] commands = []
cmds_start = lines.index('Commands for API v2.0:') cmds_start = lines.index('Commands for API v2.0:')