From 6145c57f4a022507de35817f88296be3b0fbc7df Mon Sep 17 00:00:00 2001 From: Peter Portante Date: Mon, 24 Mar 2014 21:43:14 -0400 Subject: [PATCH] Make initialization test failure more explicit A few changes to make the db initialization test failure mode more explicit. Change-Id: I533cd33476a57ecb854a1af1a5fb170c65daa825 --- test/unit/account/test_backend.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/unit/account/test_backend.py b/test/unit/account/test_backend.py index 0a46cb63ac..f75dd9a08c 100644 --- a/test/unit/account/test_backend.py +++ b/test/unit/account/test_backend.py @@ -22,6 +22,7 @@ from uuid import uuid4 from swift.account.backend import AccountBroker from swift.common.utils import normalize_timestamp +from swift.common.db import DatabaseConnectionError class TestAccountBroker(unittest.TestCase): @@ -31,13 +32,18 @@ class TestAccountBroker(unittest.TestCase): # Test AccountBroker.__init__ broker = AccountBroker(':memory:', account='a') self.assertEqual(broker.db_file, ':memory:') - got_exc = False try: with broker.get() as conn: pass - except Exception: - got_exc = True - self.assert_(got_exc) + except DatabaseConnectionError as e: + self.assertTrue(hasattr(e, 'path')) + self.assertEquals(e.path, ':memory:') + self.assertTrue(hasattr(e, 'msg')) + self.assertEquals(e.msg, "DB doesn't exist") + except Exception as e: + self.fail("Unexpected exception raised: %r" % e) + else: + self.fail("Expected a DatabaseConnectionError exception") broker.initialize(normalize_timestamp('1')) with broker.get() as conn: curs = conn.cursor()