From def5df2760b38b1493548722ddd49082f3773c31 Mon Sep 17 00:00:00 2001
From: Adam Gandelman <adamg@canonical.com>
Date: Wed, 29 May 2013 14:20:43 -0700
Subject: [PATCH] Fix shell tests for older prettytable versions.

Fix the shell tests so they pass for all supported prettytable
versions, as per requirements.txt (>=0.6,<0.8).

Fixes bug: #1185580.

Change-Id: I8dca23faa3c178494656ebc8088b6d1994e9869f
---
 novaclient/tests/test_shell.py | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/novaclient/tests/test_shell.py b/novaclient/tests/test_shell.py
index 91c34bccc..3530a6820 100644
--- a/novaclient/tests/test_shell.py
+++ b/novaclient/tests/test_shell.py
@@ -1,7 +1,10 @@
 import cStringIO
+import prettytable
 import re
 import sys
 
+from distutils.version import StrictVersion
+
 import fixtures
 import mock
 from testtools import matchers
@@ -148,13 +151,21 @@ class ShellTest(utils.TestCase):
     @mock.patch('sys.stdin', side_effect=mock.MagicMock)
     @mock.patch('getpass.getpass', return_value='password')
     def test_password(self, mock_getpass, mock_stdin):
+        # default output of empty tables differs depending between prettytable
+        # versions
+        if (hasattr(prettytable, '__version__') and
+            StrictVersion(prettytable.__version__) < StrictVersion('0.7.2')):
+            ex = '\n'
+        else:
+            ex = (
+              '+----+------+--------+------------+-------------+----------+\n'
+              '| ID | Name | Status | Task State | Power State | Networks |\n'
+              '+----+------+--------+------------+-------------+----------+\n'
+              '+----+------+--------+------------+-------------+----------+\n'
+            )
         self.make_env(exclude='OS_PASSWORD')
         stdout, stderr = self.shell('list')
-        self.assertEqual((stdout + stderr),
-            '+----+------+--------+------------+-------------+----------+\n'
-            '| ID | Name | Status | Task State | Power State | Networks |\n'
-            '+----+------+--------+------------+-------------+----------+\n'
-            '+----+------+--------+------------+-------------+----------+\n')
+        self.assertEqual((stdout + stderr), ex)
 
     @mock.patch('sys.stdin', side_effect=mock.MagicMock)
     @mock.patch('getpass.getpass', side_effect=EOFError)