author | Alexandre Fayolle <alexandre.fayolle@logilab.fr> |
Wed, 02 Jun 2010 16:25:12 +0000 | |
branch | stable |
changeset 5640 | 8a6d14f4fb9d |
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:
4212
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:
4212
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:
4212
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:
4212
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:
4212
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:
4212
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:
4212
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:
4212
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:
4212
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:
4212
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:
4212
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:
4212
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:
4212
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:
4212
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:
4212
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:
4212
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 |
||
23 |
import time |
|
24 |
from mx.DateTime import DateTimeType |
|
25 |
from datetime import datetime |
|
26 |
from cubicweb.goa import db |
|
27 |
||
28 |
from google.appengine.api import datastore |
|
29 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
30 |
class Article(db.Model): |
0 | 31 |
content = db.TextProperty() |
32 |
synopsis = db.StringProperty(default='hello') |
|
33 |
||
34 |
class Blog(db.Model): |
|
35 |
diem = db.DateProperty(required=True, auto_now_add=True) |
|
36 |
title = db.StringProperty(required=True) |
|
37 |
content = db.TextProperty() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
38 |
talks_about = db.ReferenceProperty(Article) |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
39 |
cites = db.SelfReferenceProperty() |
0 | 40 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
41 |
|
0 | 42 |
class MetaDataTC(GAEBasedTC): |
43 |
MODEL_CLASSES = (Article, Blog) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
44 |
|
0 | 45 |
def setUp(self): |
46 |
GAEBasedTC.setUp(self) |
|
47 |
self.req = self.request() |
|
48 |
self.a = self.add_entity('Article') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
49 |
self.p = self.add_entity('CWProperty', pkey=u'ui.language', value=u'en') |
0 | 50 |
self.session.commit() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
51 |
|
0 | 52 |
def _test_timestamp(self, entity, attr, sleep=0.1): |
53 |
timestamp = getattr(entity, attr) |
|
54 |
self.failUnless(timestamp) |
|
55 |
self.assertIsInstance(timestamp, DateTimeType) |
|
56 |
self.assertIsInstance(entity.to_gae_model()['s_'+attr], datetime) |
|
57 |
time.sleep(sleep) |
|
58 |
if entity.id == 'Article': |
|
59 |
entity.set_attributes(content=u'zou') |
|
60 |
else: |
|
61 |
entity.set_attributes(value=u'en') |
|
62 |
self.session.commit() |
|
63 |
return timestamp |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
64 |
|
0 | 65 |
def test_creation_date_dbmodel(self): |
66 |
cdate = self._test_timestamp(self.a, 'creation_date') |
|
67 |
self.assertEquals(cdate, self.a.creation_date) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
68 |
|
0 | 69 |
def test_creation_date_yams(self): |
70 |
cdate = self._test_timestamp(self.p, 'creation_date') |
|
71 |
self.assertEquals(cdate, self.p.creation_date) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
72 |
|
0 | 73 |
def test_modification_date_dbmodel(self): |
74 |
mdate = self._test_timestamp(self.a, 'modification_date', sleep=1) |
|
75 |
a = self.execute('Any X WHERE X eid %(x)s', {'x': self.a.eid}, 'x').get_entity(0, 0) |
|
76 |
self.failUnless(mdate < a.modification_date, (mdate, a.modification_date)) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
77 |
|
0 | 78 |
def test_modification_date_yams(self): |
79 |
mdate = self._test_timestamp(self.p, 'modification_date', sleep=1) |
|
80 |
p = self.execute('Any X WHERE X eid %(x)s', {'x': self.p.eid}, 'x').get_entity(0, 0) |
|
81 |
self.failUnless(mdate < p.modification_date, (mdate, p.modification_date)) |
|
82 |
||
83 |
def _test_owned_by(self, entity): |
|
84 |
self.assertEquals(len(entity.owned_by), 1) |
|
85 |
owner = entity.owned_by[0] |
|
86 |
self.assertIsInstance(owner, db.Model) |
|
87 |
dbmodel = entity.to_gae_model() |
|
88 |
self.assertEquals(len(dbmodel['s_owned_by']), 1) |
|
89 |
self.assertIsInstance(dbmodel['s_owned_by'][0], datastore.Key) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
90 |
|
0 | 91 |
def test_owned_by_dbmodel(self): |
92 |
self._test_owned_by(self.a) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
93 |
|
0 | 94 |
def test_owned_by_yams(self): |
95 |
self._test_owned_by(self.p) |
|
96 |
||
97 |
def _test_created_by(self, entity): |
|
98 |
self.assertEquals(len(entity.created_by), 1) |
|
99 |
creator = entity.created_by[0] |
|
100 |
self.assertIsInstance(creator, db.Model) |
|
101 |
self.assertIsInstance(entity.to_gae_model()['s_created_by'], datastore.Key) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
102 |
|
0 | 103 |
def test_created_by_dbmodel(self): |
104 |
self._test_created_by(self.a) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
105 |
|
0 | 106 |
def test_created_by_dbmodel(self): |
107 |
self._test_created_by(self.p) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
108 |
|
0 | 109 |
def test_user_owns_dbmodel(self): |
110 |
self.failUnless(self.req.user.owns(self.a.eid)) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
111 |
|
0 | 112 |
def test_user_owns_yams(self): |
113 |
self.failUnless(self.req.user.owns(self.p.eid)) |
|
114 |
||
115 |
def test_is_relation(self): |
|
116 |
en = self.execute('Any EN WHERE E name EN, X is E, X eid %(x)s', {'x': self.a.eid}, 'x')[0][0] |
|
117 |
self.assertEquals(en, 'Article') |
|
118 |
en = self.execute('Any EN WHERE E name EN, X is E, X eid %(x)s', {'x': self.p.eid}, 'x')[0][0] |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
119 |
self.assertEquals(en, 'CWProperty') |
0 | 120 |
en = self.execute('Any EN WHERE E name EN, X is E, X eid %(x)s', {'x': self.req.user.eid}, 'x')[0][0] |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
121 |
self.assertEquals(en, 'CWUser') |
0 | 122 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
123 |
|
0 | 124 |
if __name__ == '__main__': |
125 |
from logilab.common.testlib import unittest_main |
|
126 |
unittest_main() |