diff --git a/tests/test_database.py b/tests/test_database.py index a2bb8d7..48688b0 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -166,12 +166,12 @@ class DatabaseTestCase(TestCaseWithData): Database(self.database.db_name, username='default', password='wrong') exc = cm.exception - print(exc.code, exc.message) - self.assertIn(exc.code, (193, 516)) - if exc.code == 193: - self.assertTrue('Wrong password for user default' in exc.message) + if exc.code == 193: # ClickHouse version < 20.3 + self.assertTrue(exc.message.startswith('Wrong password for user default')) + elif exc.code == 516: # ClickHouse version >= 20.3 + self.assertTrue(exc.message.startswith('default: Authentication failed')) else: - self.assertTrue('default: Authentication failed: password is incorrect' in exc.message) + raise Exception('Unexpected error code - %s' % exc.code) def test_nonexisting_db(self): db = Database('db_not_here', autocreate=False) diff --git a/tests/test_join.py b/tests/test_join.py index e3d5d12..ce0ce03 100644 --- a/tests/test_join.py +++ b/tests/test_join.py @@ -30,8 +30,8 @@ class JoinTest(unittest.TestCase): self.print_res("SELECT b FROM $db.{} ALL LEFT JOIN $db.{} USING id".format(Foo.table_name(), Bar.table_name())) def test_with_subquery(self): - self.print_res("SELECT b FROM {} ALL LEFT JOIN (SELECT * from {}) USING id".format(Foo.table_name(), Bar.table_name())) - self.print_res("SELECT b FROM $db.{} ALL LEFT JOIN (SELECT * from $db.{}) USING id".format(Foo.table_name(), Bar.table_name())) + self.print_res("SELECT b FROM {} ALL LEFT JOIN (SELECT * from {}) subquery USING id".format(Foo.table_name(), Bar.table_name())) + self.print_res("SELECT b FROM $db.{} ALL LEFT JOIN (SELECT * from $db.{}) subquery USING id".format(Foo.table_name(), Bar.table_name())) class Foo(models.Model): diff --git a/tests/test_readonly.py b/tests/test_readonly.py index 816c701..f7c8f49 100644 --- a/tests/test_readonly.py +++ b/tests/test_readonly.py @@ -26,7 +26,9 @@ class ReadonlyTestCase(TestCaseWithData): self.database.drop_database() self._check_db_readonly_err(cm.exception, drop_table=True) except ServerError as e: - if e.code == 192 and e.message.startswith('Unknown user'): + if e.code == 192 and e.message.startswith('Unknown user'): # ClickHouse version < 20.3 + raise unittest.SkipTest('Database user "%s" is not defined' % username) + elif e.code == 516 and e.message.startswith('readonly: Authentication failed'): # ClickHouse version >= 20.3 raise unittest.SkipTest('Database user "%s" is not defined' % username) else: raise @@ -35,7 +37,10 @@ class ReadonlyTestCase(TestCaseWithData): def _check_db_readonly_err(self, exc, drop_table=None): self.assertEqual(exc.code, 164) - if drop_table: + print(exc.message) + if self.database.server_version >= (20, 3): + self.assertTrue('Cannot execute query in readonly mode' in exc.message) + elif drop_table: self.assertTrue(exc.message.startswith('Cannot drop table in readonly mode')) else: self.assertTrue(exc.message.startswith('Cannot insert into table in readonly mode'))