author | sylvain.thenault@logilab.fr |
Fri, 17 Apr 2009 16:55:37 +0200 | |
branch | tls-sprint |
changeset 1398 | 5fe84a5f7035 |
parent 1268 | 5db94912650b |
child 1453 | a9841184be7c |
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 |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1268
diff
changeset
|
8 |
from cubicweb.entities.authobjs import CWUser |
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__() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1268
diff
changeset
|
16 |
CWUser.schema = schema |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1268
diff
changeset
|
17 |
CWUser.__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) |
1268
5db94912650b
get field's help in guess_field
sylvain.thenault@logilab.fr
parents:
1265
diff
changeset
|
31 |
self.assertEquals(synopsis_field.help, 'an abstract for this card') |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
32 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
33 |
content_field = guess_field(Card, schema['content']) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
34 |
self.assertIsInstance(content_field, RichTextField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
35 |
self.assertEquals(content_field.required, False) |
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1104
diff
changeset
|
36 |
self.assertEquals(content_field.format_field, None) |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1104
diff
changeset
|
37 |
|
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
38 |
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
|
39 |
self.assertEquals(content_format_field, None) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
40 |
|
1265
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1104
diff
changeset
|
41 |
content_format_field = guess_field(Card, schema['content_format'], skip_meta_attr=False) |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1104
diff
changeset
|
42 |
self.assertEquals(content_format_field.internationalizable, True) |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1104
diff
changeset
|
43 |
self.assertEquals(content_format_field.sort, True) |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1104
diff
changeset
|
44 |
self.assertEquals(content_format_field.initial, 'text/rest') |
e5cdd5c0dce3
handle sort/internationalizable on Field base class + fix guess_field to deal with internationalizable and default values
sylvain.thenault@logilab.fr
parents:
1104
diff
changeset
|
45 |
|
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
46 |
wikiid_field = guess_field(Card, schema['wikiid']) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
47 |
self.assertIsInstance(wikiid_field, StringField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
48 |
self.assertEquals(wikiid_field.required, False) |
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 |
|
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
51 |
def test_euser_fields(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1268
diff
changeset
|
52 |
upassword_field = guess_field(CWUser, schema['upassword']) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
53 |
self.assertIsInstance(upassword_field, StringField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
54 |
self.assertIsInstance(upassword_field.widget, PasswordInput) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
55 |
self.assertEquals(upassword_field.required, True) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
56 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1268
diff
changeset
|
57 |
last_login_time_field = guess_field(CWUser, schema['last_login_time']) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
58 |
self.assertIsInstance(last_login_time_field, DateTimeField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
59 |
self.assertEquals(last_login_time_field.required, False) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
60 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1268
diff
changeset
|
61 |
in_group_field = guess_field(CWUser, schema['in_group']) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
62 |
self.assertIsInstance(in_group_field, RelationField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
63 |
self.assertEquals(in_group_field.required, True) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
64 |
self.assertEquals(in_group_field.role, 'subject') |
1268
5db94912650b
get field's help in guess_field
sylvain.thenault@logilab.fr
parents:
1265
diff
changeset
|
65 |
self.assertEquals(in_group_field.help, 'groups grant permissions to the user') |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
66 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1268
diff
changeset
|
67 |
owned_by_field = guess_field(CWUser, schema['owned_by'], 'object') |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
68 |
self.assertIsInstance(owned_by_field, RelationField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
69 |
self.assertEquals(owned_by_field.required, False) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
70 |
self.assertEquals(owned_by_field.role, 'object') |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
71 |
|
1268
5db94912650b
get field's help in guess_field
sylvain.thenault@logilab.fr
parents:
1265
diff
changeset
|
72 |
|
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
73 |
def test_file_fields(self): |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
74 |
data_format_field = guess_field(File, schema['data_format']) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
75 |
self.assertEquals(data_format_field, None) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
76 |
data_encoding_field = guess_field(File, schema['data_encoding']) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
77 |
self.assertEquals(data_encoding_field, None) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
78 |
|
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
79 |
data_field = guess_field(File, schema['data']) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
80 |
self.assertIsInstance(data_field, FileField) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
81 |
self.assertEquals(data_field.required, True) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
82 |
self.assertIsInstance(data_field.format_field, StringField) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
83 |
self.assertIsInstance(data_field.encoding_field, StringField) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
84 |
|
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
85 |
if __name__ == '__main__': |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
86 |
unittest_main() |