FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlobject/sqlobject/tests/test_joins.py at master · sqlobject/sqlobject · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
sqlobject
/
sqlobject
Public
Notifications
You must be signed in to change notification settings
Fork
26
Star
156
Code
Issues
2
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
sqlobject
/
sqlobject
/
tests
/
test_joins.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
160 lines (114 loc) · 4.67 KB
Breadcrumbs
sqlobject
/
sqlobject
/
tests
/
test_joins.py
Copy path
File metadata and controls
160 lines (114 loc) · 4.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from
sqlobject
import
ForeignKey
,
MultipleJoin
,
RelatedJoin
,
SQLObject
, \
StringCol
from
sqlobject
.
tests
.
dbtest
import
setupClass
########################################
# Joins
########################################
class
PersonJoiner
(
SQLObject
):
name
=
StringCol
(
length
=
40
,
alternateID
=
True
)
addressJoiners
=
RelatedJoin
(
'AddressJoiner'
)
class
AddressJoiner
(
SQLObject
):
zip
=
StringCol
(
length
=
5
,
alternateID
=
True
)
personJoiners
=
RelatedJoin
(
'PersonJoiner'
)
class
ImplicitJoiningSO
(
SQLObject
):
foo
=
RelatedJoin
(
'Bar'
)
class
ExplicitJoiningSO
(
SQLObject
):
foo
=
MultipleJoin
(
'Bar'
,
joinMethodName
=
'foo'
)
class
TestJoin
:
def
setup_method
(
self
,
meth
):
setupClass
(
PersonJoiner
)
setupClass
(
AddressJoiner
)
for
n
in
[
'bob'
,
'tim'
,
'jane'
,
'joe'
,
'fred'
,
'barb'
]:
PersonJoiner
(
name
=
n
)
for
z
in
[
'11111'
,
'22222'
,
'33333'
,
'44444'
]:
AddressJoiner
(
zip
=
z
)
def
test_join
(
self
):
b
=
PersonJoiner
.
byName
(
'bob'
)
assert
b
.
addressJoiners
==
[]
z
=
AddressJoiner
.
byZip
(
'11111'
)
b
.
addAddressJoiner
(
z
)
self
.
assertZipsEqual
(
b
.
addressJoiners
, [
'11111'
])
self
.
assertNamesEqual
(
z
.
personJoiners
, [
'bob'
])
z2
=
AddressJoiner
.
byZip
(
'22222'
)
b
.
addAddressJoiner
(
z2
)
self
.
assertZipsEqual
(
b
.
addressJoiners
, [
'11111'
,
'22222'
])
self
.
assertNamesEqual
(
z2
.
personJoiners
, [
'bob'
])
b
.
removeAddressJoiner
(
z
)
self
.
assertZipsEqual
(
b
.
addressJoiners
, [
'22222'
])
self
.
assertNamesEqual
(
z
.
personJoiners
, [])
def
assertZipsEqual
(
self
,
zips
,
dest
):
assert
[
a
.
zip
for
a
in
zips
]
==
dest
def
assertNamesEqual
(
self
,
people
,
dest
):
assert
[
p
.
name
for
p
in
people
]
==
dest
def
test_joinAttributeWithUnderscores
(
self
):
# Make sure that the implicit setting of joinMethodName works
assert
hasattr
(
ImplicitJoiningSO
,
'foo'
)
assert
not
hasattr
(
ImplicitJoiningSO
,
'bars'
)
# And make sure explicit setting also works
assert
hasattr
(
ExplicitJoiningSO
,
'foo'
)
assert
not
hasattr
(
ExplicitJoiningSO
,
'bars'
)
class
PersonJoiner2
(
SQLObject
):
name
=
StringCol
(
'name'
,
length
=
40
,
alternateID
=
True
)
addressJoiner2s
=
MultipleJoin
(
'AddressJoiner2'
)
class
AddressJoiner2
(
SQLObject
):
class
sqlmeta
:
defaultOrder
=
[
'-zip'
,
'plus4'
]
zip
=
StringCol
(
length
=
5
)
plus4
=
StringCol
(
length
=
4
,
default
=
None
)
personJoiner2
=
ForeignKey
(
'PersonJoiner2'
)
class
TestJoin2
:
def
setup_method
(
self
,
meth
):
setupClass
([
PersonJoiner2
,
AddressJoiner2
])
p1
=
PersonJoiner2
(
name
=
'bob'
)
p2
=
PersonJoiner2
(
name
=
'sally'
)
for
z
in
[
'11111'
,
'22222'
,
'33333'
]:
AddressJoiner2
(
zip
=
z
,
personJoiner2
=
p1
)
AddressJoiner2
(
zip
=
'00000'
,
personJoiner2
=
p2
)
def
test_basic
(
self
):
bob
=
PersonJoiner2
.
byName
(
'bob'
)
sally
=
PersonJoiner2
.
byName
(
'sally'
)
assert
len
(
bob
.
addressJoiner2s
)
==
3
assert
len
(
sally
.
addressJoiner2s
)
==
1
bob
.
addressJoiner2s
[
0
].
destroySelf
()
assert
len
(
bob
.
addressJoiner2s
)
==
2
z
=
bob
.
addressJoiner2s
[
0
]
z
.
zip
=
'xxxxx'
id
=
z
.
id
del
z
z
=
AddressJoiner2
.
get
(
id
)
assert
z
.
zip
==
'xxxxx'
def
test_defaultOrder
(
self
):
p1
=
PersonJoiner2
.
byName
(
'bob'
)
assert
([
i
.
zip
for
i
in
p1
.
addressJoiner2s
]
==
[
'33333'
,
'22222'
,
'11111'
])
_personJoiner3_getters
=
[]
_personJoiner3_setters
=
[]
class
PersonJoiner3
(
SQLObject
):
name
=
StringCol
(
'name'
,
length
=
40
,
alternateID
=
True
)
addressJoiner3s
=
MultipleJoin
(
'AddressJoiner3'
)
class
AddressJoiner3
(
SQLObject
):
zip
=
StringCol
(
length
=
5
)
personJoiner3
=
ForeignKey
(
'PersonJoiner3'
)
def
_get_personJoiner3
(
self
):
value
=
self
.
_SO_get_personJoiner3
()
_personJoiner3_getters
.
append
((
self
,
value
))
return
value
def
_set_personJoiner3
(
self
,
value
):
self
.
_SO_set_personJoiner3
(
value
)
_personJoiner3_setters
.
append
((
self
,
value
))
class
TestJoin3
:
def
setup_method
(
self
,
meth
):
setupClass
([
PersonJoiner3
,
AddressJoiner3
])
p1
=
PersonJoiner3
(
name
=
'bob'
)
p2
=
PersonJoiner3
(
name
=
'sally'
)
for
z
in
[
'11111'
,
'22222'
,
'33333'
]:
AddressJoiner3
(
zip
=
z
,
personJoiner3
=
p1
)
AddressJoiner3
(
zip
=
'00000'
,
personJoiner3
=
p2
)
def
test_accessors
(
self
):
assert
len
(
_personJoiner3_getters
)
==
0
assert
len
(
_personJoiner3_setters
)
==
4
bob
=
PersonJoiner3
.
byName
(
'bob'
)
for
addressJoiner3
in
bob
.
addressJoiner3s
:
addressJoiner3
.
personJoiner3
assert
len
(
_personJoiner3_getters
)
==
3
assert
len
(
_personJoiner3_setters
)
==
4
Back
|
FazBrowse Home
|
New Git URL