1 # -*- coding: utf-8 -*- |
|
2 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
4 # |
|
5 # This file is part of CubicWeb. |
|
6 # |
|
7 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
8 # terms of the GNU Lesser General Public License as published by the Free |
|
9 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
10 # any later version. |
|
11 # |
|
12 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
14 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
15 # details. |
|
16 # |
|
17 # You should have received a copy of the GNU Lesser General Public License along |
|
18 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
19 """ |
|
20 |
|
21 """ |
|
22 from cubicweb.goa.testlib import * |
|
23 |
|
24 from cubicweb import Binary |
|
25 from cubicweb.goa.goaconfig import GAEConfiguration |
|
26 from cubicweb.server.utils import crypt_password |
|
27 |
|
28 from google.appengine.api.datastore_types import Text, Blob |
|
29 |
|
30 |
|
31 class Blog(db.Model): |
|
32 data = db.BlobProperty() |
|
33 |
|
34 class DBTest(GAEBasedTC): |
|
35 config = GAEConfiguration('toto') |
|
36 config.global_set_option('use-google-auth', False) |
|
37 |
|
38 MODEL_CLASSES = (Blog,) |
|
39 |
|
40 def test_set_none_relation(self): |
|
41 eprop = self.add_entity('CWProperty', pkey=u'ui.language', value=u'en') |
|
42 self.failUnless('s_for_user' in eprop._dbmodel) |
|
43 self.assertEquals(eprop._dbmodel['s_for_user'], None) |
|
44 |
|
45 def test_euser_key(self): |
|
46 euser = self.add_entity('CWUser', login=u'toto', upassword='toto') |
|
47 self.assertEquals(euser.key().name(), 'key_toto') |
|
48 |
|
49 def test_egroup_key(self): |
|
50 egroup = self.add_entity('CWGroup', name=u'toto') |
|
51 self.assertEquals(egroup.key().name(), 'key_toto') |
|
52 |
|
53 def test_password_encryption(self): |
|
54 euser = self.add_entity('CWUser', login=u'toto', upassword='toto') |
|
55 self.failUnless(euser.upassword != 'toto', euser.upassword) |
|
56 self.assertEquals(crypt_password('toto', euser.upassword[:2]), euser.upassword) |
|
57 |
|
58 def test_long_text(self): |
|
59 # datastore string type is limited to 500 bytes |
|
60 text = u'e'*501 |
|
61 entity = self.add_entity('State', name=u'test', description=text) |
|
62 self.assertIsInstance(entity.description, unicode) |
|
63 self.failIf(isinstance(entity.description, Text)) |
|
64 self.assertEquals(entity.description, text) |
|
65 |
|
66 def test_long_accentued_text(self): |
|
67 # datastore string type is limited to 500 bytes |
|
68 text = u'é'*500 |
|
69 entity = self.add_entity('State', name=u'test', description=text) |
|
70 self.assertIsInstance(entity.description, unicode) |
|
71 self.failIf(isinstance(entity.description, Text)) |
|
72 self.assertEquals(entity.description, text) |
|
73 |
|
74 def test_blob(self): |
|
75 data = 'e'*501 |
|
76 entity = self.add_entity('Blog', data=data) |
|
77 self.assertIsInstance(entity.data, Binary) |
|
78 value = entity.data.getvalue() |
|
79 self.failIf(isinstance(value, Blob)) |
|
80 self.assertEquals(value, data) |
|
81 |
|
82 |
|
83 if __name__ == '__main__': |
|
84 from logilab.common.testlib import unittest_main |
|
85 unittest_main() |
|