author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 23 Sep 2009 19:23:09 +0200 | |
changeset 3447 | 0a0f8df4a2f7 |
parent 3369 | 7b88d12b4ee2 |
child 3536 | f6c9a5df80fb |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1858
diff
changeset
|
1 |
"""unittests for cw.web.formfields |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1858
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1858
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1858
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1858
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1858
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1858
diff
changeset
|
7 |
""" |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
8 |
|
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
9 |
from logilab.common.testlib import TestCase, unittest_main, mock_object as mock |
1858
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
10 |
|
1836
d3f0c6e868ef
fix StringField widget selection with SizeConstraint and StaticVocabularyConstraint constraints
Florent <florent@secondweb.fr>
parents:
1797
diff
changeset
|
11 |
from yams.constraints import StaticVocabularyConstraint, SizeConstraint |
1858
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
12 |
|
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
13 |
from cubicweb.devtools import TestServerConfiguration |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
14 |
from cubicweb.devtools.testlib import CubicWebTC |
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
15 |
from cubicweb.web.formwidgets import PasswordInput, TextArea, Select, Radio |
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
16 |
from cubicweb.web.formfields import * |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
17 |
from cubicweb.web.views.forms import EntityFieldsForm |
1858
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
18 |
|
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
19 |
from cubes.file.entities import File |
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 |
config = TestServerConfiguration('data') |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
22 |
config.bootstrap_cubes() |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
23 |
schema = config.load_schema() |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
24 |
|
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
25 |
class GuessFieldTC(TestCase): |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
26 |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
27 |
def test_state_fields(self): |
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
28 |
title_field = guess_field(schema['State'], schema['name']) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
29 |
self.assertIsInstance(title_field, StringField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
30 |
self.assertEquals(title_field.required, True) |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
31 |
|
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
32 |
# synopsis_field = guess_field(schema['State'], schema['synopsis']) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
33 |
# self.assertIsInstance(synopsis_field, StringField) |
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
34 |
# self.assertIsInstance(synopsis_field.widget, TextArea) |
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
35 |
# self.assertEquals(synopsis_field.required, False) |
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
36 |
# self.assertEquals(synopsis_field.help, 'an abstract for this state') |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
37 |
|
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
38 |
description_field = guess_field(schema['State'], schema['description']) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
39 |
self.assertIsInstance(description_field, RichTextField) |
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
40 |
self.assertEquals(description_field.required, False) |
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
41 |
self.assertEquals(description_field.format_field, None) |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
42 |
|
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
43 |
description_format_field = guess_field(schema['State'], schema['description_format']) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
44 |
self.assertEquals(description_format_field, None) |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
45 |
|
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
46 |
description_format_field = guess_field(schema['State'], schema['description_format'], skip_meta_attr=False) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
47 |
self.assertEquals(description_format_field.internationalizable, True) |
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
48 |
self.assertEquals(description_format_field.sort, True) |
1797
c2a80130b06d
fix some web tests, adjusts rtags
sylvain.thenault@logilab.fr
parents:
1654
diff
changeset
|
49 |
self.assertEquals(description_format_field.initial(None), 'text/rest') |
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
|
50 |
|
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
51 |
# wikiid_field = guess_field(schema['State'], schema['wikiid']) |
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
52 |
# self.assertIsInstance(wikiid_field, StringField) |
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
53 |
# self.assertEquals(wikiid_field.required, False) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
54 |
|
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
55 |
|
1858
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
56 |
def test_cwuser_fields(self): |
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
57 |
upassword_field = guess_field(schema['CWUser'], schema['upassword']) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
58 |
self.assertIsInstance(upassword_field, StringField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
59 |
self.assertIsInstance(upassword_field.widget, PasswordInput) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
60 |
self.assertEquals(upassword_field.required, True) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
61 |
|
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
62 |
last_login_time_field = guess_field(schema['CWUser'], schema['last_login_time']) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
63 |
self.assertIsInstance(last_login_time_field, DateTimeField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
64 |
self.assertEquals(last_login_time_field.required, False) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
65 |
|
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
66 |
in_group_field = guess_field(schema['CWUser'], schema['in_group']) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
67 |
self.assertIsInstance(in_group_field, RelationField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
68 |
self.assertEquals(in_group_field.required, True) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
69 |
self.assertEquals(in_group_field.role, 'subject') |
1268
5db94912650b
get field's help in guess_field
sylvain.thenault@logilab.fr
parents:
1265
diff
changeset
|
70 |
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
|
71 |
|
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
72 |
owned_by_field = guess_field(schema['CWUser'], schema['owned_by'], 'object') |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
73 |
self.assertIsInstance(owned_by_field, RelationField) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
74 |
self.assertEquals(owned_by_field.required, False) |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
75 |
self.assertEquals(owned_by_field.role, 'object') |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
76 |
|
1268
5db94912650b
get field's help in guess_field
sylvain.thenault@logilab.fr
parents:
1265
diff
changeset
|
77 |
|
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
78 |
def test_file_fields(self): |
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
79 |
data_format_field = guess_field(schema['File'], schema['data_format']) |
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
80 |
self.assertEquals(data_format_field, None) |
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
81 |
data_encoding_field = guess_field(schema['File'], schema['data_encoding']) |
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
82 |
self.assertEquals(data_encoding_field, None) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
83 |
|
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
84 |
data_field = guess_field(schema['File'], schema['data']) |
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
85 |
self.assertIsInstance(data_field, FileField) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
86 |
self.assertEquals(data_field.required, True) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
87 |
self.assertIsInstance(data_field.format_field, StringField) |
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
88 |
self.assertIsInstance(data_field.encoding_field, StringField) |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
89 |
|
1836
d3f0c6e868ef
fix StringField widget selection with SizeConstraint and StaticVocabularyConstraint constraints
Florent <florent@secondweb.fr>
parents:
1797
diff
changeset
|
90 |
def test_constraints_priority(self): |
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
91 |
salesterm_field = guess_field(schema['Salesterm'], schema['reason']) |
1836
d3f0c6e868ef
fix StringField widget selection with SizeConstraint and StaticVocabularyConstraint constraints
Florent <florent@secondweb.fr>
parents:
1797
diff
changeset
|
92 |
constraints = schema['reason'].rproperty('Salesterm', 'String', 'constraints') |
d3f0c6e868ef
fix StringField widget selection with SizeConstraint and StaticVocabularyConstraint constraints
Florent <florent@secondweb.fr>
parents:
1797
diff
changeset
|
93 |
self.assertEquals([c.__class__ for c in constraints], |
d3f0c6e868ef
fix StringField widget selection with SizeConstraint and StaticVocabularyConstraint constraints
Florent <florent@secondweb.fr>
parents:
1797
diff
changeset
|
94 |
[SizeConstraint, StaticVocabularyConstraint]) |
d3f0c6e868ef
fix StringField widget selection with SizeConstraint and StaticVocabularyConstraint constraints
Florent <florent@secondweb.fr>
parents:
1797
diff
changeset
|
95 |
self.assertIsInstance(salesterm_field.widget, Select) |
d3f0c6e868ef
fix StringField widget selection with SizeConstraint and StaticVocabularyConstraint constraints
Florent <florent@secondweb.fr>
parents:
1797
diff
changeset
|
96 |
|
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
97 |
|
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
98 |
def test_bool_field_base(self): |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
99 |
field = guess_field(schema['CWAttribute'], schema['indexed']) |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
100 |
self.assertIsInstance(field, BooleanField) |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
101 |
self.assertEquals(field.required, False) |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
102 |
self.assertEquals(field.initial(None), None) |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
103 |
self.assertIsInstance(field.widget, Radio) |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
104 |
self.assertEquals(field.vocabulary(mock(req=mock(_=unicode))), |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
105 |
[(u'yes', '1'), (u'no', '')]) |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
106 |
|
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
107 |
def test_bool_field_explicit_choices(self): |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
108 |
field = guess_field(schema['CWAttribute'], schema['indexed'], |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
109 |
choices=[(u'maybe', '1'), (u'no', '')]) |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
110 |
self.assertIsInstance(field.widget, Radio) |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
111 |
self.assertEquals(field.vocabulary(mock(req=mock(_=unicode))), |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
112 |
[(u'maybe', '1'), (u'no', '')]) |
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
113 |
|
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
114 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
115 |
class MoreFieldsTC(CubicWebTC): |
1858
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
116 |
def test_rtf_format_field(self): |
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
117 |
req = self.request() |
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
118 |
req.use_fckeditor = lambda: False |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
119 |
e = self.vreg['etypes'].etype_class('State')(req) |
1858
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
120 |
form = EntityFieldsForm(req, entity=e) |
2091
a7ea618e5478
don't set select widget when a vocabulary widget is already specified on the field class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2005
diff
changeset
|
121 |
description_field = guess_field(schema['State'], schema['description']) |
1858
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
122 |
description_format_field = description_field.get_format_field(form) |
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
123 |
self.assertEquals(description_format_field.internationalizable, True) |
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
124 |
self.assertEquals(description_format_field.sort, True) |
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
125 |
# unlike below, initial is bound to form.form_field_format |
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
126 |
self.assertEquals(description_format_field.initial(form), 'text/html') |
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
127 |
self.execute('INSERT CWProperty X: X pkey "ui.default-text-format", X value "text/rest", X for_user U WHERE U login "admin"') |
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
128 |
self.commit() |
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
129 |
self.assertEquals(description_format_field.initial(form), 'text/rest') |
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
130 |
|
3334
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
131 |
|
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
132 |
class UtilsTC(TestCase): |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
133 |
def test_vocab_sort(self): |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
134 |
self.assertEquals(vocab_sort([('Z', 1), ('A', 2), |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
135 |
('Group 1', None), ('Y', 3), ('B', 4), |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
136 |
('Group 2', None), ('X', 5), ('C', 6)]), |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
137 |
[('A', 2), ('Z', 1), |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
138 |
('Group 1', None), ('B', 4), ('Y', 3), |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
139 |
('Group 2', None), ('C', 6), ('X', 5)] |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
140 |
) |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
141 |
|
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
142 |
if __name__ == '__main__': |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
143 |
unittest_main() |