Catch correct oslo.db exception

Now oslo.db wraps all the database exceptions into specific oslo.db
exceptions. A test expects for IntegrityError where now returns
DBDuplicateEntry. We should catch DBDuplicateEntry to keep test
correctness.

Change-Id: I4576f19c4fd3db6742a6a2fbbca0e0e5400b792d
Closes-Bug: #1214341
This commit is contained in:
Ilya Pekelny 2014-07-23 12:32:48 +03:00
parent b6efac529f
commit 9231482360
1 changed files with 12 additions and 3 deletions

View File

@ -1195,9 +1195,18 @@ class SqlUpgradeTests(SqlMigrateBase):
add_region(region_unique_table)
self.assertEqual(1, session.query(region_unique_table).count())
# verify the unique constraint is enforced
self.assertRaises(sqlalchemy.exc.IntegrityError,
add_region,
table=region_unique_table)
self.assertRaises(
# FIXME (I159): Since oslo.db wraps all the database exceptions
# into more specific exception objects, we should catch both of
# sqlalchemy and oslo.db exceptions. If an old oslo.db version
# is installed, IntegrityError is raised. If >=0.4.0 version of
# oslo.db is installed, DBDuplicateEntry is raised.
# When the global requirements is updated with
# the version fixes exceptions wrapping, IntegrityError must be
# removed from the tuple.
(sqlalchemy.exc.IntegrityError, db_exception.DBDuplicateEntry),
add_region,
table=region_unique_table)
# migrate to 43, unique constraint should be dropped
self.upgrade(43)