-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_select_through.py
More file actions
63 lines (43 loc) · 1.76 KB
/
Copy pathtest_select_through.py
File metadata and controls
63 lines (43 loc) · 1.76 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
import pytest
from sqlobject import ForeignKey, SQLMultipleJoin, SQLObject, SQLRelatedJoin, \
StringCol
from sqlobject.tests.dbtest import inserts, setupClass
# Tests retrieving objects through a join/fk on a selectResults
class SRThrough1(SQLObject):
three = ForeignKey('SRThrough3')
twos = SQLMultipleJoin('SRThrough2', joinColumn='oneID')
class SRThrough2(SQLObject):
one = ForeignKey('SRThrough1')
threes = SQLRelatedJoin('SRThrough3', addRemoveName='Three')
class SRThrough3(SQLObject):
name = StringCol()
ones = SQLMultipleJoin('SRThrough1', joinColumn='threeID')
twos = SQLRelatedJoin('SRThrough2')
def setup_module(mod):
global ones, twos, threes
setupClass([SRThrough3, SRThrough1, SRThrough2])
threes = inserts(SRThrough3,
[('a',), ('b',), ('c',)],
'name')
ones = inserts(SRThrough1,
[(threes[0].id,), (threes[0].id,), (threes[2].id,)],
'threeID')
twos = inserts(SRThrough2,
[(ones[0].id,), (ones[1].id,), (ones[2].id,)],
'oneID')
twos[0].addThree(threes[0])
twos[0].addThree(threes[1])
def testBadRef():
with pytest.raises(AttributeError):
threes[0].throughTo.four
def testThroughFK():
assert list(threes[0].ones.throughTo.three) == [threes[0]]
def testThroughMultipleJoin():
assert list(threes[0].ones.throughTo.twos) == [twos[0], twos[1]]
def testThroughRelatedJoin():
assert list(threes[0].twos.throughTo.threes) == [threes[0], threes[1]]
assert list(
SRThrough3.select(SRThrough3.q.id == threes[0].id).throughTo.twos) == \
list(threes[0].twos)
def testThroughFKAndJoin():
assert list(threes[0].ones.throughTo.three.throughTo.twos) == [twos[0]]