author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 27 May 2009 16:41:15 +0200 | |
branch | stable |
changeset 1968 | d3de0f44b57b |
parent 1802 | d628defebc17 |
child 1977 | 606923dff11b |
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() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
13 |
|
0 | 14 |
class DBTest(GAEBasedTC): |
15 |
config = GAEConfiguration('toto') |
|
16 |
config.global_set_option('use-google-auth', False) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
17 |
|
0 | 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') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
28 |
|
0 | 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) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
43 |
self.failIf(isinstance(entity.description, Text)) |
0 | 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) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
51 |
self.failIf(isinstance(entity.description, Text)) |
0 | 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() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
59 |
self.failIf(isinstance(value, Blob)) |
0 | 60 |
self.assertEquals(value, data) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
61 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
62 |
|
0 | 63 |
if __name__ == '__main__': |
64 |
from logilab.common.testlib import unittest_main |
|
65 |
unittest_main() |