author | sylvain.thenault@logilab.fr |
Thu, 12 Mar 2009 20:46:30 +0100 | |
branch | tls-sprint |
changeset 1111 | bcb81e7c41bc |
parent 1104 | 58f27c3c0167 |
child 1265 | e5cdd5c0dce3 |
permissions | -rw-r--r-- |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
1 |
"""unittests for cw.web.formfields""" |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
2 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
3 |
from logilab.common.testlib import TestCase, unittest_main |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
4 |
from cubicweb.devtools import TestServerConfiguration |
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
5 |
from cubicweb.web.formwidgets import PasswordInput |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
6 |
from cubicweb.web.formfields import * |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
7 |
from cubicweb.entities.lib import Card |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
8 |
from cubicweb.entities.authobjs import EUser |
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
9 |
from cubes.file.entities import File |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
10 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
11 |
config = TestServerConfiguration('data') |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
12 |
config.bootstrap_cubes() |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
13 |
schema = config.load_schema() |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
14 |
Card.schema = schema |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
15 |
Card.__initialize__() |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
16 |
EUser.schema = schema |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
17 |
EUser.__initialize__() |
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
18 |
File.schema = schema |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
19 |
File.__initialize__() |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
20 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
21 |
class GuessFieldTC(TestCase): |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
22 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
23 |
def test_card_fields(self): |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
24 |
title_field = guess_field(Card, schema['title']) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
25 |
self.assertIsInstance(title_field, StringField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
26 |
self.assertEquals(title_field.required, True) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
27 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
28 |
synopsis_field = guess_field(Card, schema['synopsis']) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
29 |
self.assertIsInstance(synopsis_field, TextField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
30 |
self.assertEquals(synopsis_field.required, False) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
31 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
32 |
content_field = guess_field(Card, schema['content']) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
33 |
self.assertIsInstance(content_field, RichTextField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
34 |
self.assertEquals(content_field.required, False) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
35 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
36 |
content_format_field = guess_field(Card, schema['content_format']) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
37 |
self.assertEquals(content_format_field, None) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
38 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
39 |
wikiid_field = guess_field(Card, schema['wikiid']) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
40 |
self.assertIsInstance(wikiid_field, StringField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
41 |
self.assertEquals(wikiid_field.required, False) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
42 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
43 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
44 |
def test_euser_fields(self): |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
45 |
upassword_field = guess_field(EUser, schema['upassword']) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
46 |
self.assertIsInstance(upassword_field, StringField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
47 |
self.assertIsInstance(upassword_field.widget, PasswordInput) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
48 |
self.assertEquals(upassword_field.required, True) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
49 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
50 |
last_login_time_field = guess_field(EUser, schema['last_login_time']) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
51 |
self.assertIsInstance(last_login_time_field, DateTimeField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
52 |
self.assertEquals(last_login_time_field.required, False) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
53 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
54 |
in_group_field = guess_field(EUser, schema['in_group']) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
55 |
self.assertIsInstance(in_group_field, RelationField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
56 |
self.assertEquals(in_group_field.required, True) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
57 |
self.assertEquals(in_group_field.role, 'subject') |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
58 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
59 |
owned_by_field = guess_field(EUser, schema['owned_by'], 'object') |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
60 |
self.assertIsInstance(owned_by_field, RelationField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
61 |
self.assertEquals(owned_by_field.required, False) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
62 |
self.assertEquals(owned_by_field.role, 'object') |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
63 |
|
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
64 |
def test_file_fields(self): |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
65 |
data_format_field = guess_field(File, schema['data_format']) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
66 |
self.assertEquals(data_format_field, None) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
67 |
data_encoding_field = guess_field(File, schema['data_encoding']) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
68 |
self.assertEquals(data_encoding_field, None) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
69 |
|
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
70 |
data_field = guess_field(File, schema['data']) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
71 |
self.assertIsInstance(data_field, FileField) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
72 |
self.assertEquals(data_field.required, True) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
73 |
self.assertIsInstance(data_field.format_field, StringField) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
74 |
self.assertIsInstance(data_field.encoding_field, StringField) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
75 |
|
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
76 |
if __name__ == '__main__': |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
77 |
unittest_main() |