-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_cyclic_reference.py
More file actions
55 lines (46 loc) · 1.95 KB
/
Copy pathtest_cyclic_reference.py
File metadata and controls
55 lines (46 loc) · 1.95 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
import pytest
from sqlobject import BLOBCol, DateTimeCol, ForeignKey, IntCol, SQLObject, \
StringCol, sqlmeta
from sqlobject.tests.dbtest import getConnection, supports
class SOTestCyclicRefA(SQLObject):
class sqlmeta(sqlmeta):
idName = 'test_id_here'
table = 'test_cyclic_ref_a_table'
name = StringCol()
number = IntCol()
so_time = DateTimeCol()
short = StringCol(length=10)
blobcol = BLOBCol()
fkeyb = ForeignKey('SOTestCyclicRefB')
class SOTestCyclicRefB(SQLObject):
class sqlmeta(sqlmeta):
idName = 'test_id_here'
table = 'test_cyclic_ref_b_table'
name = StringCol()
number = IntCol()
so_time = DateTimeCol()
short = StringCol(length=10)
blobcol = BLOBCol()
fkeya = ForeignKey('SOTestCyclicRefA')
def test_cyclic_reference():
if not supports('dropTableCascade'):
pytest.skip("dropTableCascade isn't supported")
conn = getConnection()
SOTestCyclicRefA.setConnection(conn)
SOTestCyclicRefB.setConnection(conn)
SOTestCyclicRefA.dropTable(ifExists=True, cascade=True)
assert not conn.tableExists(SOTestCyclicRefA.sqlmeta.table)
SOTestCyclicRefB.dropTable(ifExists=True, cascade=True)
assert not conn.tableExists(SOTestCyclicRefB.sqlmeta.table)
constraints = SOTestCyclicRefA.createTable(ifNotExists=True,
applyConstraints=False)
assert conn.tableExists(SOTestCyclicRefA.sqlmeta.table)
constraints += SOTestCyclicRefB.createTable(ifNotExists=True,
applyConstraints=False)
assert conn.tableExists(SOTestCyclicRefB.sqlmeta.table)
for constraint in constraints:
conn.query(constraint)
SOTestCyclicRefA.dropTable(ifExists=True, cascade=True)
assert not conn.tableExists(SOTestCyclicRefA.sqlmeta.table)
SOTestCyclicRefB.dropTable(ifExists=True, cascade=True)
assert not conn.tableExists(SOTestCyclicRefB.sqlmeta.table)