Make initialization test failure more explicit
A few changes to make the db initialization test failure mode more explicit. Change-Id: I533cd33476a57ecb854a1af1a5fb170c65daa825
This commit is contained in:
parent
d4a1d75bfc
commit
6145c57f4a
@ -22,6 +22,7 @@ from uuid import uuid4
|
|||||||
|
|
||||||
from swift.account.backend import AccountBroker
|
from swift.account.backend import AccountBroker
|
||||||
from swift.common.utils import normalize_timestamp
|
from swift.common.utils import normalize_timestamp
|
||||||
|
from swift.common.db import DatabaseConnectionError
|
||||||
|
|
||||||
|
|
||||||
class TestAccountBroker(unittest.TestCase):
|
class TestAccountBroker(unittest.TestCase):
|
||||||
@ -31,13 +32,18 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
# Test AccountBroker.__init__
|
# Test AccountBroker.__init__
|
||||||
broker = AccountBroker(':memory:', account='a')
|
broker = AccountBroker(':memory:', account='a')
|
||||||
self.assertEqual(broker.db_file, ':memory:')
|
self.assertEqual(broker.db_file, ':memory:')
|
||||||
got_exc = False
|
|
||||||
try:
|
try:
|
||||||
with broker.get() as conn:
|
with broker.get() as conn:
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except DatabaseConnectionError as e:
|
||||||
got_exc = True
|
self.assertTrue(hasattr(e, 'path'))
|
||||||
self.assert_(got_exc)
|
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'))
|
broker.initialize(normalize_timestamp('1'))
|
||||||
with broker.get() as conn:
|
with broker.get() as conn:
|
||||||
curs = conn.cursor()
|
curs = conn.cursor()
|
||||||
|
Loading…
Reference in New Issue
Block a user