/
test_postgres.py
93 lines (63 loc) · 1.97 KB
/
test_postgres.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os, unittest
import psycopg2
import asyncpg
import dqo
from test_sync import BaseSync
from test_async import BaseAsync, async_test
from test_evolve import BaseEvolve
class PostgresSync(BaseSync, unittest.TestCase):
@classmethod
def setUpClass(cls):
os.system('createdb dqo_test')
cls.db = dqo.Database(
sync_src=lambda: psycopg2.connect("dbname='dqo_test'"),
)
super().setUpClass()
@classmethod
def tearDownClass(cls):
os.system('dropdb dqo_test')
class PostgresAsync(BaseAsync, unittest.TestCase):
@classmethod
def setUpClass(cls):
os.system('createdb dqo_test')
cls.db = dqo.Database(
sync_src=lambda: psycopg2.connect("dbname='dqo_test'"),
async_src=lambda: asyncpg.connect(database='dqo_test')
)
super().setUpClass()
@classmethod
def tearDownClass(cls):
os.system('dropdb dqo_test')
class PostgresAsyncPooled(unittest.TestCase):
@classmethod
def setUpClass(cls):
os.system('createdb dqo_test')
@classmethod
def tearDownClass(cls):
os.system('dropdb dqo_test')
@async_test
async def test_first(self):
pool = asyncpg.create_pool(database='dqo_test')
dqo.DB = dqo.Database(async_src=pool, async_dialect=dqo.Dialect.POSTGRES(10, lib=asyncpg))
async with dqo.DB.connection() as conn:
await conn.async_execute('create table something (col1 integer, col2 text)', [])
@dqo.Table()
class Something:
col1 = dqo.Column(int)
col2 = dqo.Column(str)
await Something.ALL.insert(col1=1)
self.assertEqual((await Something.ALL.first()).col1, 1)
await pool.close()
class PostgresEvolve(BaseEvolve, unittest.TestCase):
pk_int = 'serial'
def setUp(self):
os.system('createdb dqo_test')
super().setUp()
def tearDown(self):
os.system('dropdb dqo_test')
def build_db(self):
return dqo.Database(
sync_src=lambda: psycopg2.connect("dbname='dqo_test'"),
)
if __name__ == '__main__':
unittest.main()