author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 20 Jan 2010 14:34:06 +0100 | |
changeset 4292 | 3fc808b0490b |
parent 4212 | ab6573088b4a |
child 5421 | 8167de96c523 |
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 |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
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 |
||
10 |
import time |
|
11 |
from mx.DateTime import DateTimeType |
|
12 |
from datetime import datetime |
|
13 |
from cubicweb.goa import db |
|
14 |
||
15 |
from google.appengine.api import datastore |
|
16 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
17 |
class Article(db.Model): |
0 | 18 |
content = db.TextProperty() |
19 |
synopsis = db.StringProperty(default='hello') |
|
20 |
||
21 |
class Blog(db.Model): |
|
22 |
diem = db.DateProperty(required=True, auto_now_add=True) |
|
23 |
title = db.StringProperty(required=True) |
|
24 |
content = db.TextProperty() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
25 |
talks_about = db.ReferenceProperty(Article) |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
26 |
cites = db.SelfReferenceProperty() |
0 | 27 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
28 |
|
0 | 29 |
class MetaDataTC(GAEBasedTC): |
30 |
MODEL_CLASSES = (Article, Blog) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
31 |
|
0 | 32 |
def setUp(self): |
33 |
GAEBasedTC.setUp(self) |
|
34 |
self.req = self.request() |
|
35 |
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
|
36 |
self.p = self.add_entity('CWProperty', pkey=u'ui.language', value=u'en') |
0 | 37 |
self.session.commit() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
38 |
|
0 | 39 |
def _test_timestamp(self, entity, attr, sleep=0.1): |
40 |
timestamp = getattr(entity, attr) |
|
41 |
self.failUnless(timestamp) |
|
42 |
self.assertIsInstance(timestamp, DateTimeType) |
|
43 |
self.assertIsInstance(entity.to_gae_model()['s_'+attr], datetime) |
|
44 |
time.sleep(sleep) |
|
45 |
if entity.id == 'Article': |
|
46 |
entity.set_attributes(content=u'zou') |
|
47 |
else: |
|
48 |
entity.set_attributes(value=u'en') |
|
49 |
self.session.commit() |
|
50 |
return timestamp |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
51 |
|
0 | 52 |
def test_creation_date_dbmodel(self): |
53 |
cdate = self._test_timestamp(self.a, 'creation_date') |
|
54 |
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
|
55 |
|
0 | 56 |
def test_creation_date_yams(self): |
57 |
cdate = self._test_timestamp(self.p, 'creation_date') |
|
58 |
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
|
59 |
|
0 | 60 |
def test_modification_date_dbmodel(self): |
61 |
mdate = self._test_timestamp(self.a, 'modification_date', sleep=1) |
|
62 |
a = self.execute('Any X WHERE X eid %(x)s', {'x': self.a.eid}, 'x').get_entity(0, 0) |
|
63 |
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
|
64 |
|
0 | 65 |
def test_modification_date_yams(self): |
66 |
mdate = self._test_timestamp(self.p, 'modification_date', sleep=1) |
|
67 |
p = self.execute('Any X WHERE X eid %(x)s', {'x': self.p.eid}, 'x').get_entity(0, 0) |
|
68 |
self.failUnless(mdate < p.modification_date, (mdate, p.modification_date)) |
|
69 |
||
70 |
def _test_owned_by(self, entity): |
|
71 |
self.assertEquals(len(entity.owned_by), 1) |
|
72 |
owner = entity.owned_by[0] |
|
73 |
self.assertIsInstance(owner, db.Model) |
|
74 |
dbmodel = entity.to_gae_model() |
|
75 |
self.assertEquals(len(dbmodel['s_owned_by']), 1) |
|
76 |
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
|
77 |
|
0 | 78 |
def test_owned_by_dbmodel(self): |
79 |
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
|
80 |
|
0 | 81 |
def test_owned_by_yams(self): |
82 |
self._test_owned_by(self.p) |
|
83 |
||
84 |
def _test_created_by(self, entity): |
|
85 |
self.assertEquals(len(entity.created_by), 1) |
|
86 |
creator = entity.created_by[0] |
|
87 |
self.assertIsInstance(creator, db.Model) |
|
88 |
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
|
89 |
|
0 | 90 |
def test_created_by_dbmodel(self): |
91 |
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
|
92 |
|
0 | 93 |
def test_created_by_dbmodel(self): |
94 |
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
|
95 |
|
0 | 96 |
def test_user_owns_dbmodel(self): |
97 |
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
|
98 |
|
0 | 99 |
def test_user_owns_yams(self): |
100 |
self.failUnless(self.req.user.owns(self.p.eid)) |
|
101 |
||
102 |
def test_is_relation(self): |
|
103 |
en = self.execute('Any EN WHERE E name EN, X is E, X eid %(x)s', {'x': self.a.eid}, 'x')[0][0] |
|
104 |
self.assertEquals(en, 'Article') |
|
105 |
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
|
106 |
self.assertEquals(en, 'CWProperty') |
0 | 107 |
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
|
108 |
self.assertEquals(en, 'CWUser') |
0 | 109 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
110 |
|
0 | 111 |
if __name__ == '__main__': |
112 |
from logilab.common.testlib import unittest_main |
|
113 |
unittest_main() |