-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtest_asdict.py
More file actions
48 lines (35 loc) · 1.65 KB
/
Copy pathtest_asdict.py
File metadata and controls
48 lines (35 loc) · 1.65 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
from sqlobject import StringCol
from sqlobject.inheritance import InheritableSQLObject
from sqlobject.tests.dbtest import setupClass
########################################
# sqlmeta.asDict
########################################
class InheritablePersonAD(InheritableSQLObject):
firstName = StringCol()
lastName = StringCol(alternateID=True, length=100)
class ManagerAD(InheritablePersonAD):
department = StringCol()
class EmployeeAD(InheritablePersonAD):
_inheritable = False
so_position = StringCol()
def test_getColumns():
setupClass([InheritablePersonAD, ManagerAD, EmployeeAD])
for klass, columns in (
(InheritablePersonAD, ['firstName', 'lastName']),
(ManagerAD, ['department', 'firstName', 'lastName']),
(EmployeeAD, ['firstName', 'lastName', 'so_position'])):
_columns = sorted(klass.sqlmeta.getColumns().keys())
assert _columns == columns
def test_asDict():
setupClass([InheritablePersonAD, ManagerAD, EmployeeAD], force=True)
InheritablePersonAD(firstName='Oneof', lastName='Authors')
ManagerAD(firstName='ManagerAD', lastName='The', department='Dep')
EmployeeAD(firstName='Project', lastName='Leader',
so_position='Project leader')
assert InheritablePersonAD.get(1).sqlmeta.asDict() == \
dict(firstName='Oneof', lastName='Authors', id=1)
assert InheritablePersonAD.get(2).sqlmeta.asDict() == \
dict(firstName='ManagerAD', lastName='The', department='Dep', id=2)
assert InheritablePersonAD.get(3).sqlmeta.asDict() == \
dict(firstName='Project', lastName='Leader',
so_position='Project leader', id=3)