author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Mon, 25 May 2009 12:20:25 +0200 | |
changeset 1911 | 16af47588d41 |
parent 1802 | d628defebc17 |
child 1977 | 606923dff11b |
permissions | -rw-r--r-- |
0 | 1 |
from cubicweb.goa.testlib import * |
2 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
3 |
class Article(db.Model): |
0 | 4 |
content = db.TextProperty() |
5 |
synopsis = db.StringProperty(default='hello') |
|
6 |
||
7 |
class Blog(db.Model): |
|
8 |
diem = db.DateProperty(required=True, auto_now_add=True) |
|
9 |
title = db.StringProperty(required=True) |
|
10 |
content = db.TextProperty() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
11 |
talks_about = db.ReferenceProperty(Article) |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
12 |
cites = db.SelfReferenceProperty() |
0 | 13 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
14 |
|
0 | 15 |
class SomeViewsTC(GAEBasedTC): |
16 |
MODEL_CLASSES = (Article, Blog) |
|
17 |
||
18 |
def test_entities_and_relation(self): |
|
19 |
schema = self.schema |
|
20 |
self.assertSetEquals(set(str(e) for e in schema.entities()), |
|
21 |
set(('Boolean', 'Bytes', 'Date', 'Datetime', 'Float', |
|
22 |
'Decimal', |
|
23 |
'Int', 'Interval', 'Password', 'String', 'Time', |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
24 |
'CWEType', 'CWGroup', 'CWPermission', 'CWProperty', 'CWRType', |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
25 |
'CWUser', 'EmailAddress', |
0 | 26 |
'RQLExpression', 'State', 'Transition', 'TrInfo', |
27 |
'Article', 'Blog', 'YamsEntity'))) |
|
28 |
self.assertSetEquals(set(str(e) for e in schema.relations()), |
|
29 |
set(('add_permission', 'address', 'alias', 'allowed_transition', |
|
30 |
'ambiguous_relation', 'canonical', 'cites', |
|
31 |
'comment', 'comment_format', 'condition', 'content', |
|
32 |
'created_by', 'creation_date', 'delete_permission', |
|
33 |
'description', 'description_format', 'destination_state', |
|
34 |
'diem', 'eid', 'expression', 'exprtype', 'final', 'firstname', |
|
35 |
'for_user', 'from_state', 'fulltext_container', 'has_text', |
|
36 |
'identical_to', 'identity', 'in_group', 'initial_state', |
|
37 |
'inlined', 'inlined_relation', 'is', 'is_instance_of', |
|
38 |
'label', 'last_login_time', 'login', |
|
39 |
'mainvars', 'meta', 'modification_date', 'name', 'owned_by', 'pkey', 'primary_email', |
|
40 |
'read_permission', 'require_group', 'state_of', 'surname', 'symetric', |
|
41 |
'synopsis', 'talks_about', 'title', 'to_state', 'transition_of', |
|
42 |
'update_permission', 'use_email', 'value'))) |
|
43 |
||
44 |
def test_dbmodel_imported(self): |
|
45 |
eschema = self.schema['Blog'] |
|
46 |
orels = [str(e) for e in eschema.ordered_relations()] |
|
47 |
# only relations defined in the class are actually ordered |
|
48 |
orels, others = orels[:5], orels[5:] |
|
49 |
self.assertEquals(orels, |
|
50 |
['diem', 'title', 'content', 'talks_about', 'cites']) |
|
51 |
self.assertUnorderedIterableEquals(others, |
|
52 |
['eid', 'identity', 'owned_by', 'modification_date', |
|
53 |
'created_by', 'creation_date', 'is', 'is_instance_of']) |
|
54 |
self.assertUnorderedIterableEquals((str(e) for e in eschema.object_relations()), |
|
55 |
('ambiguous_relation', 'cites', 'identity', 'inlined_relation')) |
|
56 |
eschema = self.schema['Article'] |
|
57 |
orels = [str(e) for e in eschema.ordered_relations()] |
|
58 |
# only relations defined in the class are actually ordered |
|
59 |
orels, others = orels[:2], orels[2:] |
|
60 |
self.assertEquals(orels, |
|
61 |
['content', 'synopsis']) |
|
62 |
self.assertUnorderedIterableEquals(others, |
|
63 |
['eid', 'identity', 'owned_by', 'modification_date', |
|
64 |
'created_by', 'creation_date', 'is', 'is_instance_of']) |
|
65 |
self.assertUnorderedIterableEquals((str(e) for e in eschema.object_relations()), |
|
66 |
('ambiguous_relation', 'talks_about', 'identity')) |
|
67 |
||
68 |
def test_yams_imported(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
69 |
eschema = self.schema['CWProperty'] |
0 | 70 |
# only relations defined in the class are actually ordered |
71 |
orels = [str(e) for e in eschema.ordered_relations()] |
|
72 |
orels, others = orels[:3], orels[3:] |
|
73 |
self.assertEquals(orels, |
|
74 |
['pkey', 'value', 'for_user']) |
|
75 |
self.assertEquals(others, |
|
76 |
['created_by', 'creation_date', 'eid', 'identity', |
|
77 |
'is', 'is_instance_of', 'modification_date', 'owned_by']) |
|
78 |
self.assertUnorderedIterableEquals((str(e) for e in eschema.object_relations()), |
|
79 |
('identity',)) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
80 |
|
0 | 81 |
def test_yams_ambiguous_relation(self): |
82 |
rschema = self.schema['ambiguous_relation'] |
|
83 |
# only relations defined in the class are actually ordered |
|
84 |
self.assertUnorderedIterableEquals((str(e) for e in rschema.subjects()), |
|
85 |
('YamsEntity',)) |
|
86 |
self.assertUnorderedIterableEquals((str(e) for e in rschema.objects()), |
|
87 |
('Blog', 'Article')) |
|
88 |
||
89 |
def test_euser(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
90 |
eschema = self.schema['CWUser'] |
0 | 91 |
# XXX pretend to have some relations it has not |
92 |
self.assertEquals([str(e) for e in eschema.ordered_relations()], |
|
93 |
['login', 'firstname', 'surname', 'last_login_time', |
|
94 |
'primary_email', 'use_email', 'in_group', 'created_by', |
|
95 |
'creation_date', 'eid', 'has_text', 'identity', |
|
96 |
'is', 'is_instance_of', 'modification_date', |
|
97 |
'owned_by']) |
|
98 |
self.assertUnorderedIterableEquals((str(e) for e in eschema.object_relations()), |
|
99 |
('owned_by', 'created_by', 'identity', 'for_user')) |
|
100 |
||
101 |
def test_eid(self): |
|
102 |
rschema = self.schema['eid'] |
|
103 |
self.assertEquals(rschema.objects(), ('Bytes',)) |
|
104 |
self.assertEquals(rschema.rproperty('Blog', 'Bytes', 'cardinality'), '?1') |
|
105 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
106 |
|
0 | 107 |
if __name__ == '__main__': |
108 |
from logilab.common.testlib import unittest_main |
|
109 |
unittest_main() |