author | sylvain.thenault@logilab.fr |
Tue, 28 Apr 2009 15:38:06 +0200 | |
branch | tls-sprint |
changeset 1505 | e4c99610e1f7 |
parent 1398 | 5fe84a5f7035 |
child 1802 | d628defebc17 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
2 |
from cubicweb.goa.testlib import * |
|
3 |
||
4 |
from cubicweb import Binary |
|
5 |
from cubicweb.goa.goaconfig import GAEConfiguration |
|
6 |
from cubicweb.server.utils import crypt_password |
|
7 |
||
8 |
from google.appengine.api.datastore_types import Text, Blob |
|
9 |
||
10 |
||
11 |
class Blog(db.Model): |
|
12 |
data = db.BlobProperty() |
|
13 |
||
14 |
class DBTest(GAEBasedTC): |
|
15 |
config = GAEConfiguration('toto') |
|
16 |
config.global_set_option('use-google-auth', False) |
|
17 |
||
18 |
MODEL_CLASSES = (Blog,) |
|
19 |
||
20 |
def test_set_none_relation(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
21 |
eprop = self.add_entity('CWProperty', pkey=u'ui.language', value=u'en') |
0 | 22 |
self.failUnless('s_for_user' in eprop._dbmodel) |
23 |
self.assertEquals(eprop._dbmodel['s_for_user'], None) |
|
24 |
||
25 |
def test_euser_key(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
26 |
euser = self.add_entity('CWUser', login=u'toto', upassword='toto') |
0 | 27 |
self.assertEquals(euser.key().name(), 'key_toto') |
28 |
||
29 |
def test_egroup_key(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
30 |
egroup = self.add_entity('CWGroup', name=u'toto') |
0 | 31 |
self.assertEquals(egroup.key().name(), 'key_toto') |
32 |
||
33 |
def test_password_encryption(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
34 |
euser = self.add_entity('CWUser', login=u'toto', upassword='toto') |
0 | 35 |
self.failUnless(euser.upassword != 'toto', euser.upassword) |
36 |
self.assertEquals(crypt_password('toto', euser.upassword[:2]), euser.upassword) |
|
37 |
||
38 |
def test_long_text(self): |
|
39 |
# datastore string type is limited to 500 bytes |
|
40 |
text = u'e'*501 |
|
41 |
entity = self.add_entity('State', name=u'test', description=text) |
|
42 |
self.assertIsInstance(entity.description, unicode) |
|
43 |
self.failIf(isinstance(entity.description, Text)) |
|
44 |
self.assertEquals(entity.description, text) |
|
45 |
||
46 |
def test_long_accentued_text(self): |
|
47 |
# datastore string type is limited to 500 bytes |
|
48 |
text = u'é'*500 |
|
49 |
entity = self.add_entity('State', name=u'test', description=text) |
|
50 |
self.assertIsInstance(entity.description, unicode) |
|
51 |
self.failIf(isinstance(entity.description, Text)) |
|
52 |
self.assertEquals(entity.description, text) |
|
53 |
||
54 |
def test_blob(self): |
|
55 |
data = 'e'*501 |
|
56 |
entity = self.add_entity('Blog', data=data) |
|
57 |
self.assertIsInstance(entity.data, Binary) |
|
58 |
value = entity.data.getvalue() |
|
59 |
self.failIf(isinstance(value, Blob)) |
|
60 |
self.assertEquals(value, data) |
|
61 |
||
62 |
||
63 |
if __name__ == '__main__': |
|
64 |
from logilab.common.testlib import unittest_main |
|
65 |
unittest_main() |