Add new filter for DBDataError exception

For sqlite database if insert or update command fails
due to unicode value then it raises DBError whereas
for mysql using filter it raises DBDataError.

To maintain consistency, added new filter which will
raise DBDataError for sqlite database as well.

Related-Bug: #1393871
Related-Bug: #1531400

Change-Id: Ibb61a69b1b0c6ce6172f290848f44f89e2b41d3b
This commit is contained in:
bhagyashris
2016-03-18 13:54:43 +00:00
parent f98cb90f2b
commit b1de3f71a8
2 changed files with 38 additions and 0 deletions

View File

@@ -282,6 +282,8 @@ def _raise_mysql_table_doesnt_exist_asis(
r".*1264.*Out of range value for column.*")
@filters("mysql", sqla_exc.InternalError,
r"^.*1366.*Incorrect string value:*")
@filters("sqlite", sqla_exc.ProgrammingError,
r"(?i).*You must not use 8-bit bytestrings*")
def _raise_data_error(error, match, engine_name, is_disconnect):
"""Raise DBDataError exception for different data errors."""

View File

@@ -452,6 +452,42 @@ class TestReferenceErrorMySQL(TestReferenceErrorSQLite,
self.assertEqual("resource_foo", matched.key_table)
class TestDBDataErrorSQLite(_SQLAExceptionMatcher, test_base.DbTestCase):
def setUp(self):
super(TestDBDataErrorSQLite, self).setUp()
if six.PY3:
self.skip("SQLite database supports unicode value for python3")
meta = sqla.MetaData(bind=self.engine)
self.table_1 = sqla.Table(
"resource_foo", meta,
sqla.Column("name", sqla.String),
)
self.table_1.create()
def test_raise(self):
matched = self.assertRaises(
exception.DBDataError,
self.engine.execute,
self.table_1.insert({'name': u'\u2713'.encode('utf-8')})
)
self.assertInnerException(
matched,
"ProgrammingError",
"You must not use 8-bit bytestrings unless you use a "
"text_factory that can interpret 8-bit bytestrings "
"(like text_factory = str). It is highly recommended that "
"you instead just switch your application to Unicode strings.",
"INSERT INTO resource_foo (name) VALUES (?)",
(u'\u2713'.encode('utf-8'),)
)
class TestConstraint(TestsExceptionFilter):
def test_postgresql(self):
matched = self._run_test(