author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 02 Dec 2009 14:38:17 +0100 | |
branch | stable |
changeset 3971 | 7cfbc35dce7e |
parent 1977 | 606923dff11b |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
1 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
7 |
""" |
0 | 8 |
from cubicweb.goa.testlib import * |
9 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
10 |
class Article(db.Model): |
0 | 11 |
content = db.TextProperty() |
12 |
synopsis = db.StringProperty(default='hello') |
|
13 |
||
14 |
class Blog(db.Model): |
|
15 |
diem = db.DateProperty(required=True, auto_now_add=True) |
|
16 |
title = db.StringProperty(required=True) |
|
17 |
content = db.TextProperty() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
18 |
talks_about = db.ReferenceProperty(Article) |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
19 |
cites = db.SelfReferenceProperty() |
0 | 20 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
21 |
|
0 | 22 |
class SomeViewsTC(GAEBasedTC): |
23 |
MODEL_CLASSES = (Article, Blog) |
|
24 |
||
25 |
def test_entities_and_relation(self): |
|
26 |
schema = self.schema |
|
27 |
self.assertSetEquals(set(str(e) for e in schema.entities()), |
|
28 |
set(('Boolean', 'Bytes', 'Date', 'Datetime', 'Float', |
|
29 |
'Decimal', |
|
30 |
'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
|
31 |
'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
|
32 |
'CWUser', 'EmailAddress', |
0 | 33 |
'RQLExpression', 'State', 'Transition', 'TrInfo', |
34 |
'Article', 'Blog', 'YamsEntity'))) |
|
35 |
self.assertSetEquals(set(str(e) for e in schema.relations()), |
|
36 |
set(('add_permission', 'address', 'alias', 'allowed_transition', |
|
37 |
'ambiguous_relation', 'canonical', 'cites', |
|
38 |
'comment', 'comment_format', 'condition', 'content', |
|
39 |
'created_by', 'creation_date', 'delete_permission', |
|
40 |
'description', 'description_format', 'destination_state', |
|
41 |
'diem', 'eid', 'expression', 'exprtype', 'final', 'firstname', |
|
42 |
'for_user', 'from_state', 'fulltext_container', 'has_text', |
|
43 |
'identical_to', 'identity', 'in_group', 'initial_state', |
|
44 |
'inlined', 'inlined_relation', 'is', 'is_instance_of', |
|
45 |
'label', 'last_login_time', 'login', |
|
46 |
'mainvars', 'meta', 'modification_date', 'name', 'owned_by', 'pkey', 'primary_email', |
|
47 |
'read_permission', 'require_group', 'state_of', 'surname', 'symetric', |
|
48 |
'synopsis', 'talks_about', 'title', 'to_state', 'transition_of', |
|
49 |
'update_permission', 'use_email', 'value'))) |
|
50 |
||
51 |
def test_dbmodel_imported(self): |
|
52 |
eschema = self.schema['Blog'] |
|
53 |
orels = [str(e) for e in eschema.ordered_relations()] |
|
54 |
# only relations defined in the class are actually ordered |
|
55 |
orels, others = orels[:5], orels[5:] |
|
56 |
self.assertEquals(orels, |
|
57 |
['diem', 'title', 'content', 'talks_about', 'cites']) |
|
58 |
self.assertUnorderedIterableEquals(others, |
|
59 |
['eid', 'identity', 'owned_by', 'modification_date', |
|
60 |
'created_by', 'creation_date', 'is', 'is_instance_of']) |
|
61 |
self.assertUnorderedIterableEquals((str(e) for e in eschema.object_relations()), |
|
62 |
('ambiguous_relation', 'cites', 'identity', 'inlined_relation')) |
|
63 |
eschema = self.schema['Article'] |
|
64 |
orels = [str(e) for e in eschema.ordered_relations()] |
|
65 |
# only relations defined in the class are actually ordered |
|
66 |
orels, others = orels[:2], orels[2:] |
|
67 |
self.assertEquals(orels, |
|
68 |
['content', 'synopsis']) |
|
69 |
self.assertUnorderedIterableEquals(others, |
|
70 |
['eid', 'identity', 'owned_by', 'modification_date', |
|
71 |
'created_by', 'creation_date', 'is', 'is_instance_of']) |
|
72 |
self.assertUnorderedIterableEquals((str(e) for e in eschema.object_relations()), |
|
73 |
('ambiguous_relation', 'talks_about', 'identity')) |
|
74 |
||
75 |
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
|
76 |
eschema = self.schema['CWProperty'] |
0 | 77 |
# only relations defined in the class are actually ordered |
78 |
orels = [str(e) for e in eschema.ordered_relations()] |
|
79 |
orels, others = orels[:3], orels[3:] |
|
80 |
self.assertEquals(orels, |
|
81 |
['pkey', 'value', 'for_user']) |
|
82 |
self.assertEquals(others, |
|
83 |
['created_by', 'creation_date', 'eid', 'identity', |
|
84 |
'is', 'is_instance_of', 'modification_date', 'owned_by']) |
|
85 |
self.assertUnorderedIterableEquals((str(e) for e in eschema.object_relations()), |
|
86 |
('identity',)) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
87 |
|
0 | 88 |
def test_yams_ambiguous_relation(self): |
89 |
rschema = self.schema['ambiguous_relation'] |
|
90 |
# only relations defined in the class are actually ordered |
|
91 |
self.assertUnorderedIterableEquals((str(e) for e in rschema.subjects()), |
|
92 |
('YamsEntity',)) |
|
93 |
self.assertUnorderedIterableEquals((str(e) for e in rschema.objects()), |
|
94 |
('Blog', 'Article')) |
|
95 |
||
96 |
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
|
97 |
eschema = self.schema['CWUser'] |
0 | 98 |
# XXX pretend to have some relations it has not |
99 |
self.assertEquals([str(e) for e in eschema.ordered_relations()], |
|
100 |
['login', 'firstname', 'surname', 'last_login_time', |
|
101 |
'primary_email', 'use_email', 'in_group', 'created_by', |
|
102 |
'creation_date', 'eid', 'has_text', 'identity', |
|
103 |
'is', 'is_instance_of', 'modification_date', |
|
104 |
'owned_by']) |
|
105 |
self.assertUnorderedIterableEquals((str(e) for e in eschema.object_relations()), |
|
106 |
('owned_by', 'created_by', 'identity', 'for_user')) |
|
107 |
||
108 |
def test_eid(self): |
|
109 |
rschema = self.schema['eid'] |
|
110 |
self.assertEquals(rschema.objects(), ('Bytes',)) |
|
111 |
self.assertEquals(rschema.rproperty('Blog', 'Bytes', 'cardinality'), '?1') |
|
112 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
113 |
|
0 | 114 |
if __name__ == '__main__': |
115 |
from logilab.common.testlib import unittest_main |
|
116 |
unittest_main() |