diff options
author | pkholkin <pkholkin@mirantis.com> | 2014-07-21 19:36:42 +0400 |
---|---|---|
committer | pkholkin <pkholkin@mirantis.com> | 2014-07-28 13:31:57 +0400 |
commit | 4685631abaf4ab52f6510014b34b26da36150421 (patch) | |
tree | 32c72d3c474dbd439a6c42c6adb9416f77062617 /tests | |
parent | 8839e43b2a094faa12d8d9c947422d47a4c8c613 (diff) | |
download | oslo-db-4685631abaf4ab52f6510014b34b26da36150421.tar.gz |
Extension of DBDuplicateEntry exception
Added new field 'value' for DBDuplicateEntry exception.
It shows duplicated value for mysql and postresql 9.x engines
and is read from the error message using regular expressions.
The duplicated value can't be extracted from SQLite error messages,
so we do our best here for other db backends that we support.
Change-Id: I647e314cafe8ceb570bf18948d6ab83ab6afef97
Diffstat (limited to 'tests')
-rw-r--r-- | tests/sqlalchemy/test_exc_filters.py | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/tests/sqlalchemy/test_exc_filters.py b/tests/sqlalchemy/test_exc_filters.py index 1955c8a..42e4365 100644 --- a/tests/sqlalchemy/test_exc_filters.py +++ b/tests/sqlalchemy/test_exc_filters.py @@ -267,13 +267,14 @@ class TestRaiseReferenceError(TestsExceptionFilter): class TestDuplicate(TestsExceptionFilter): def _run_dupe_constraint_test(self, dialect_name, message, - expected_columns=['a', 'b']): + expected_columns=['a', 'b'], expected_value=None): matched = self._run_test( dialect_name, "insert into table some_values", self.IntegrityError(message), exception.DBDuplicateEntry ) self.assertEqual(expected_columns, matched.columns) + self.assertEqual(expected_value, matched.value) def _not_dupe_constraint_test(self, dialect_name, statement, message, expected_cls, expected_message): @@ -294,19 +295,36 @@ class TestDuplicate(TestsExceptionFilter): def test_mysql_mysqldb(self): self._run_dupe_constraint_test("mysql", '(1062, "Duplicate entry ' - '\'2-3\' for key \'uniq_tbl0a0b\'")') + '\'2-3\' for key \'uniq_tbl0a0b\'")', expected_value='2-3') def test_mysql_mysqlconnector(self): self._run_dupe_constraint_test("mysql", '1062 (23000): Duplicate entry ' - '\'2-3\' for key \'uniq_tbl0a0b\'")') + '\'2-3\' for key \'uniq_tbl0a0b\'")', expected_value='2-3') def test_postgresql(self): self._run_dupe_constraint_test( 'postgresql', 'duplicate key value violates unique constraint' '"uniq_tbl0a0b"' - '\nDETAIL: Key (a, b)=(2, 3) already exists.\n' + '\nDETAIL: Key (a, b)=(2, 3) already exists.\n', + expected_value='2, 3' + ) + + def test_mysql_single(self): + self._run_dupe_constraint_test("mysql", + "1062 (23000): Duplicate entry '2' for key 'b'", + expected_columns=['b'], + expected_value='2' + ) + + def test_postgresql_single(self): + self._run_dupe_constraint_test( + 'postgresql', + 'duplicate key value violates unique constraint "uniq_tbl0b"\n' + 'DETAIL: Key (b)=(2) already exists.\n', + expected_columns=['b'], + expected_value='2' ) def test_unsupported_backend(self): |