author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Tue, 04 May 2010 11:09:18 +0200 | |
branch | stable |
changeset 5459 | 6e561796804c |
parent 5424 | 8ecbcbff9777 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
18 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
19 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
20 |
""" |
0 | 21 |
from cubicweb.goa.testlib import * |
22 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
23 |
class Article(db.Model): |
0 | 24 |
content = db.TextProperty() |
25 |
synopsis = db.StringProperty(default='hello') |
|
26 |
||
27 |
class Blog(db.Model): |
|
28 |
diem = db.DateProperty(required=True, auto_now_add=True) |
|
29 |
title = db.StringProperty(required=True) |
|
30 |
content = db.TextProperty() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
31 |
talks_about = db.ReferenceProperty(Article) |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
32 |
cites = db.SelfReferenceProperty() |
0 | 33 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
34 |
|
0 | 35 |
class SomeViewsTC(GAEBasedTC): |
36 |
MODEL_CLASSES = (Article, Blog) |
|
37 |
||
38 |
def test_entities_and_relation(self): |
|
39 |
schema = self.schema |
|
40 |
self.assertSetEquals(set(str(e) for e in schema.entities()), |
|
41 |
set(('Boolean', 'Bytes', 'Date', 'Datetime', 'Float', |
|
42 |
'Decimal', |
|
43 |
'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
|
44 |
'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
|
45 |
'CWUser', 'EmailAddress', |
0 | 46 |
'RQLExpression', 'State', 'Transition', 'TrInfo', |
47 |
'Article', 'Blog', 'YamsEntity'))) |
|
48 |
self.assertSetEquals(set(str(e) for e in schema.relations()), |
|
49 |
set(('add_permission', 'address', 'alias', 'allowed_transition', |
|
50 |
'ambiguous_relation', 'canonical', 'cites', |
|
51 |
'comment', 'comment_format', 'condition', 'content', |
|
52 |
'created_by', 'creation_date', 'delete_permission', |
|
53 |
'description', 'description_format', 'destination_state', |
|
54 |
'diem', 'eid', 'expression', 'exprtype', 'final', 'firstname', |
|
55 |
'for_user', 'from_state', 'fulltext_container', 'has_text', |
|
56 |
'identical_to', 'identity', 'in_group', 'initial_state', |
|
57 |
'inlined', 'inlined_relation', 'is', 'is_instance_of', |
|
58 |
'label', 'last_login_time', 'login', |
|
59 |
'mainvars', 'meta', 'modification_date', 'name', 'owned_by', 'pkey', 'primary_email', |
|
4467
0e73d299730a
fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
60 |
'read_permission', 'require_group', 'state_of', 'surname', 'symmetric', |
0 | 61 |
'synopsis', 'talks_about', 'title', 'to_state', 'transition_of', |
62 |
'update_permission', 'use_email', 'value'))) |
|
63 |
||
64 |
def test_dbmodel_imported(self): |
|
65 |
eschema = self.schema['Blog'] |
|
66 |
orels = [str(e) for e in eschema.ordered_relations()] |
|
67 |
# only relations defined in the class are actually ordered |
|
68 |
orels, others = orels[:5], orels[5:] |
|
69 |
self.assertEquals(orels, |
|
70 |
['diem', 'title', 'content', 'talks_about', 'cites']) |
|
71 |
self.assertUnorderedIterableEquals(others, |
|
72 |
['eid', 'identity', 'owned_by', 'modification_date', |
|
73 |
'created_by', 'creation_date', 'is', 'is_instance_of']) |
|
74 |
self.assertUnorderedIterableEquals((str(e) for e in eschema.object_relations()), |
|
75 |
('ambiguous_relation', 'cites', 'identity', 'inlined_relation')) |
|
76 |
eschema = self.schema['Article'] |
|
77 |
orels = [str(e) for e in eschema.ordered_relations()] |
|
78 |
# only relations defined in the class are actually ordered |
|
79 |
orels, others = orels[:2], orels[2:] |
|
80 |
self.assertEquals(orels, |
|
81 |
['content', 'synopsis']) |
|
82 |
self.assertUnorderedIterableEquals(others, |
|
83 |
['eid', 'identity', 'owned_by', 'modification_date', |
|
84 |
'created_by', 'creation_date', 'is', 'is_instance_of']) |
|
85 |
self.assertUnorderedIterableEquals((str(e) for e in eschema.object_relations()), |
|
86 |
('ambiguous_relation', 'talks_about', 'identity')) |
|
87 |
||
88 |
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
|
89 |
eschema = self.schema['CWProperty'] |
0 | 90 |
# only relations defined in the class are actually ordered |
91 |
orels = [str(e) for e in eschema.ordered_relations()] |
|
92 |
orels, others = orels[:3], orels[3:] |
|
93 |
self.assertEquals(orels, |
|
94 |
['pkey', 'value', 'for_user']) |
|
95 |
self.assertEquals(others, |
|
96 |
['created_by', 'creation_date', 'eid', 'identity', |
|
97 |
'is', 'is_instance_of', 'modification_date', 'owned_by']) |
|
98 |
self.assertUnorderedIterableEquals((str(e) for e in eschema.object_relations()), |
|
99 |
('identity',)) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
100 |
|
0 | 101 |
def test_yams_ambiguous_relation(self): |
102 |
rschema = self.schema['ambiguous_relation'] |
|
103 |
# only relations defined in the class are actually ordered |
|
104 |
self.assertUnorderedIterableEquals((str(e) for e in rschema.subjects()), |
|
105 |
('YamsEntity',)) |
|
106 |
self.assertUnorderedIterableEquals((str(e) for e in rschema.objects()), |
|
107 |
('Blog', 'Article')) |
|
108 |
||
109 |
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
|
110 |
eschema = self.schema['CWUser'] |
0 | 111 |
# XXX pretend to have some relations it has not |
112 |
self.assertEquals([str(e) for e in eschema.ordered_relations()], |
|
113 |
['login', 'firstname', 'surname', 'last_login_time', |
|
114 |
'primary_email', 'use_email', 'in_group', 'created_by', |
|
115 |
'creation_date', 'eid', 'has_text', 'identity', |
|
116 |
'is', 'is_instance_of', 'modification_date', |
|
117 |
'owned_by']) |
|
118 |
self.assertUnorderedIterableEquals((str(e) for e in eschema.object_relations()), |
|
119 |
('owned_by', 'created_by', 'identity', 'for_user')) |
|
120 |
||
121 |
def test_eid(self): |
|
122 |
rschema = self.schema['eid'] |
|
123 |
self.assertEquals(rschema.objects(), ('Bytes',)) |
|
124 |
self.assertEquals(rschema.rproperty('Blog', 'Bytes', 'cardinality'), '?1') |
|
125 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
126 |
|
0 | 127 |
if __name__ == '__main__': |
128 |
from logilab.common.testlib import unittest_main |
|
129 |
unittest_main() |