-
-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathtest_base.py
More file actions
70 lines (59 loc) · 2.13 KB
/
Copy pathtest_base.py
File metadata and controls
70 lines (59 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import asynch.errors
import sqlalchemy
import sqlalchemy.event
from sqlalchemy.engine.url import URL
from clickhouse_sqlalchemy.drivers.asynch.base import ClickHouseDialect_asynch
from tests.testcase import AsynchSessionTestCase, BaseTestCase
class TestConnectArgs(BaseTestCase):
def setUp(self):
self.dialect = ClickHouseDialect_asynch()
def test_simple_url(self):
url = URL.create(
drivername='clickhouse+asynch',
host='localhost',
database='default',
)
connect_args = self.dialect.create_connect_args(url)
self.assertEqual(
str(connect_args[0][0]), 'clickhouse://localhost/default'
)
def test_secure_false(self):
url = URL.create(
drivername='clickhouse+asynch',
username='default',
password='default',
host='localhost',
port=9001,
database='default',
query={'secure': 'False'}
)
connect_args = self.dialect.create_connect_args(url)
self.assertEqual(
str(connect_args[0][0]),
'clickhouse://default:default@localhost:9001/default?secure=False'
)
def test_no_auth(self):
url = URL.create(
drivername='clickhouse+asynch',
host='localhost',
port=9001,
database='default',
)
connect_args = self.dialect.create_connect_args(url)
self.assertEqual(
str(connect_args[0][0]), 'clickhouse://localhost:9001/default'
)
class DBApiTestCase(AsynchSessionTestCase):
async def test_error_handler(self):
class MockedException(Exception):
pass
def handle_error(e: sqlalchemy.engine.ExceptionContext):
if isinstance(
e.original_exception,
asynch.errors.ServerException,
):
raise MockedException()
engine = self.session.get_bind()
sqlalchemy.event.listen(engine, 'handle_error', handle_error)
with self.assertRaises(MockedException):
await self.session.execute(sqlalchemy.text('SELECT'))