8 from google.appengine.api.datastore_types import Text, Blob |
8 from google.appengine.api.datastore_types import Text, Blob |
9 |
9 |
10 |
10 |
11 class Blog(db.Model): |
11 class Blog(db.Model): |
12 data = db.BlobProperty() |
12 data = db.BlobProperty() |
13 |
13 |
14 class DBTest(GAEBasedTC): |
14 class DBTest(GAEBasedTC): |
15 config = GAEConfiguration('toto') |
15 config = GAEConfiguration('toto') |
16 config.global_set_option('use-google-auth', False) |
16 config.global_set_option('use-google-auth', False) |
17 |
17 |
18 MODEL_CLASSES = (Blog,) |
18 MODEL_CLASSES = (Blog,) |
19 |
19 |
20 def test_set_none_relation(self): |
20 def test_set_none_relation(self): |
21 eprop = self.add_entity('CWProperty', pkey=u'ui.language', value=u'en') |
21 eprop = self.add_entity('CWProperty', pkey=u'ui.language', value=u'en') |
22 self.failUnless('s_for_user' in eprop._dbmodel) |
22 self.failUnless('s_for_user' in eprop._dbmodel) |
23 self.assertEquals(eprop._dbmodel['s_for_user'], None) |
23 self.assertEquals(eprop._dbmodel['s_for_user'], None) |
24 |
24 |
25 def test_euser_key(self): |
25 def test_euser_key(self): |
26 euser = self.add_entity('CWUser', login=u'toto', upassword='toto') |
26 euser = self.add_entity('CWUser', login=u'toto', upassword='toto') |
27 self.assertEquals(euser.key().name(), 'key_toto') |
27 self.assertEquals(euser.key().name(), 'key_toto') |
28 |
28 |
29 def test_egroup_key(self): |
29 def test_egroup_key(self): |
30 egroup = self.add_entity('CWGroup', name=u'toto') |
30 egroup = self.add_entity('CWGroup', name=u'toto') |
31 self.assertEquals(egroup.key().name(), 'key_toto') |
31 self.assertEquals(egroup.key().name(), 'key_toto') |
32 |
32 |
33 def test_password_encryption(self): |
33 def test_password_encryption(self): |
38 def test_long_text(self): |
38 def test_long_text(self): |
39 # datastore string type is limited to 500 bytes |
39 # datastore string type is limited to 500 bytes |
40 text = u'e'*501 |
40 text = u'e'*501 |
41 entity = self.add_entity('State', name=u'test', description=text) |
41 entity = self.add_entity('State', name=u'test', description=text) |
42 self.assertIsInstance(entity.description, unicode) |
42 self.assertIsInstance(entity.description, unicode) |
43 self.failIf(isinstance(entity.description, Text)) |
43 self.failIf(isinstance(entity.description, Text)) |
44 self.assertEquals(entity.description, text) |
44 self.assertEquals(entity.description, text) |
45 |
45 |
46 def test_long_accentued_text(self): |
46 def test_long_accentued_text(self): |
47 # datastore string type is limited to 500 bytes |
47 # datastore string type is limited to 500 bytes |
48 text = u'é'*500 |
48 text = u'é'*500 |
49 entity = self.add_entity('State', name=u'test', description=text) |
49 entity = self.add_entity('State', name=u'test', description=text) |
50 self.assertIsInstance(entity.description, unicode) |
50 self.assertIsInstance(entity.description, unicode) |
51 self.failIf(isinstance(entity.description, Text)) |
51 self.failIf(isinstance(entity.description, Text)) |
52 self.assertEquals(entity.description, text) |
52 self.assertEquals(entity.description, text) |
53 |
53 |
54 def test_blob(self): |
54 def test_blob(self): |
55 data = 'e'*501 |
55 data = 'e'*501 |
56 entity = self.add_entity('Blog', data=data) |
56 entity = self.add_entity('Blog', data=data) |
57 self.assertIsInstance(entity.data, Binary) |
57 self.assertIsInstance(entity.data, Binary) |
58 value = entity.data.getvalue() |
58 value = entity.data.getvalue() |
59 self.failIf(isinstance(value, Blob)) |
59 self.failIf(isinstance(value, Blob)) |
60 self.assertEquals(value, data) |
60 self.assertEquals(value, data) |
61 |
61 |
62 |
62 |
63 if __name__ == '__main__': |
63 if __name__ == '__main__': |
64 from logilab.common.testlib import unittest_main |
64 from logilab.common.testlib import unittest_main |
65 unittest_main() |
65 unittest_main() |