author | Rémi Cardona <remi.cardona@logilab.fr> |
Wed, 20 May 2015 16:33:01 +0200 | |
changeset 10426 | ce213d6858f1 |
parent 10273 | ef74abcf369d |
child 10772 | 2ff5afce3216 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5712
e136d392bd71
[form] refactor meta-attributes handling: hide them by default using uicfg.afs instead of returning None (or not, according to skip_meta_attr flag argument) in guess_field
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
18 |
"""unittests for cw.web.formfields""" |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
19 |
|
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
|
20 |
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
|
21 |
|
1836
d3f0c6e868ef
fix StringField widget selection with SizeConstraint and StaticVocabularyConstraint constraints
Florent <florent@secondweb.fr>
parents:
1797
diff
changeset
|
22 |
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
|
23 |
|
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
24 |
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
|
25 |
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
|
26 |
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
|
27 |
from cubicweb.web.formfields import * |
9444
6012cf57f48e
[web/formfields] Make CompoundField inherit needs_multipart from its subfields
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8666
diff
changeset
|
28 |
from cubicweb.web.views.forms import EntityFieldsForm, FieldsForm |
1858
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
29 |
|
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
30 |
from cubes.file.entities import File |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
31 |
|
6781
5062d86d6ffe
[unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6631
diff
changeset
|
32 |
def setUpModule(*args): |
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
33 |
global schema |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
34 |
config = TestServerConfiguration('data', apphome=GuessFieldTC.datadir) |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
35 |
config.bootstrap_cubes() |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
36 |
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
|
37 |
|
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8519
diff
changeset
|
38 |
class GuessFieldTC(CubicWebTC): |
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8519
diff
changeset
|
39 |
|
1570
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
40 |
def test_state_fields(self): |
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
41 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
42 |
title_field = guess_field(schema['State'], schema['name'], req=req) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
43 |
self.assertIsInstance(title_field, StringField) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
44 |
self.assertEqual(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
|
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 |
# 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
|
47 |
# self.assertIsInstance(synopsis_field, StringField) |
5c40d9fb4e8d
stop using card in test, update form tests
sylvain.thenault@logilab.fr
parents:
1453
diff
changeset
|
48 |
# self.assertIsInstance(synopsis_field.widget, TextArea) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5712
diff
changeset
|
49 |
# self.assertEqual(synopsis_field.required, False) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5712
diff
changeset
|
50 |
# self.assertEqual(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
|
51 |
|
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
52 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
53 |
description_field = guess_field(schema['State'], schema['description'], req=req) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
54 |
self.assertIsInstance(description_field, RichTextField) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
55 |
self.assertEqual(description_field.required, False) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
56 |
self.assertEqual(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
|
57 |
|
5712
e136d392bd71
[form] refactor meta-attributes handling: hide them by default using uicfg.afs instead of returning None (or not, according to skip_meta_attr flag argument) in guess_field
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
58 |
# description_format_field = guess_field(schema['State'], schema['description_format']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5712
diff
changeset
|
59 |
# self.assertEqual(description_format_field, None) |
5712
e136d392bd71
[form] refactor meta-attributes handling: hide them by default using uicfg.afs instead of returning None (or not, according to skip_meta_attr flag argument) in guess_field
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
60 |
|
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
61 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
62 |
description_format_field = guess_field(schema['State'], schema['description_format'], |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
63 |
req=req) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
64 |
self.assertEqual(description_format_field.internationalizable, True) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
65 |
self.assertEqual(description_format_field.sort, True) |
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
|
66 |
|
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
|
67 |
# 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
|
68 |
# self.assertIsInstance(wikiid_field, StringField) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5712
diff
changeset
|
69 |
# self.assertEqual(wikiid_field.required, False) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
70 |
|
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
71 |
|
1858
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
72 |
def test_cwuser_fields(self): |
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
73 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
74 |
upassword_field = guess_field(schema['CWUser'], schema['upassword'], req=req) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
75 |
self.assertIsInstance(upassword_field, StringField) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
76 |
self.assertIsInstance(upassword_field.widget, PasswordInput) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
77 |
self.assertEqual(upassword_field.required, True) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
78 |
|
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
79 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
80 |
last_login_time_field = guess_field(schema['CWUser'], schema['last_login_time'], req=req) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
81 |
self.assertIsInstance(last_login_time_field, DateTimeField) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
82 |
self.assertEqual(last_login_time_field.required, False) |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
83 |
|
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
84 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
85 |
in_group_field = guess_field(schema['CWUser'], schema['in_group'], req=req) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
86 |
self.assertIsInstance(in_group_field, RelationField) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
87 |
self.assertEqual(in_group_field.required, True) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
88 |
self.assertEqual(in_group_field.role, 'subject') |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
89 |
self.assertEqual(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
|
90 |
|
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
91 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
92 |
owned_by_field = guess_field(schema['CWUser'], schema['owned_by'], 'object', req=req) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
93 |
self.assertIsInstance(owned_by_field, RelationField) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
94 |
self.assertEqual(owned_by_field.required, False) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
95 |
self.assertEqual(owned_by_field.role, 'object') |
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
96 |
|
1268
5db94912650b
get field's help in guess_field
sylvain.thenault@logilab.fr
parents:
1265
diff
changeset
|
97 |
|
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
98 |
def test_file_fields(self): |
5712
e136d392bd71
[form] refactor meta-attributes handling: hide them by default using uicfg.afs instead of returning None (or not, according to skip_meta_attr flag argument) in guess_field
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
99 |
# data_format_field = guess_field(schema['File'], schema['data_format']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5712
diff
changeset
|
100 |
# self.assertEqual(data_format_field, None) |
5712
e136d392bd71
[form] refactor meta-attributes handling: hide them by default using uicfg.afs instead of returning None (or not, according to skip_meta_attr flag argument) in guess_field
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
101 |
# data_encoding_field = guess_field(schema['File'], schema['data_encoding']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5712
diff
changeset
|
102 |
# self.assertEqual(data_encoding_field, None) |
5712
e136d392bd71
[form] refactor meta-attributes handling: hide them by default using uicfg.afs instead of returning None (or not, according to skip_meta_attr flag argument) in guess_field
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
103 |
# data_name_field = guess_field(schema['File'], schema['data_name']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5712
diff
changeset
|
104 |
# self.assertEqual(data_name_field, None) |
1104
58f27c3c0167
more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents:
1095
diff
changeset
|
105 |
|
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
106 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
107 |
data_field = guess_field(schema['File'], schema['data'], req=req) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
108 |
self.assertIsInstance(data_field, FileField) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
109 |
self.assertEqual(data_field.required, True) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
110 |
self.assertIsInstance(data_field.format_field, StringField) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
111 |
self.assertIsInstance(data_field.encoding_field, StringField) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
112 |
self.assertIsInstance(data_field.name_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
|
113 |
|
1836
d3f0c6e868ef
fix StringField widget selection with SizeConstraint and StaticVocabularyConstraint constraints
Florent <florent@secondweb.fr>
parents:
1797
diff
changeset
|
114 |
def test_constraints_priority(self): |
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
115 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
116 |
salesterm_field = guess_field(schema['Salesterm'], schema['reason'], req=req) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
117 |
constraints = schema['reason'].rdef('Salesterm', 'String').constraints |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
118 |
self.assertEqual([c.__class__ for c in constraints], |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
119 |
[SizeConstraint, StaticVocabularyConstraint]) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
120 |
self.assertIsInstance(salesterm_field, StringField) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
121 |
self.assertIsInstance(salesterm_field.widget, Select) |
1836
d3f0c6e868ef
fix StringField widget selection with SizeConstraint and StaticVocabularyConstraint constraints
Florent <florent@secondweb.fr>
parents:
1797
diff
changeset
|
122 |
|
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
|
123 |
|
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
|
124 |
def test_bool_field_base(self): |
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
125 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
126 |
field = guess_field(schema['CWAttribute'], schema['indexed'], req=req) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
127 |
self.assertIsInstance(field, BooleanField) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
128 |
self.assertEqual(field.required, False) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
129 |
self.assertIsInstance(field.widget, Radio) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
130 |
self.assertEqual(field.vocabulary(mock(_cw=mock(_=unicode))), |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
131 |
[(u'yes', '1'), (u'no', '')]) |
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
|
132 |
|
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
|
133 |
def test_bool_field_explicit_choices(self): |
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
134 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
135 |
field = guess_field(schema['CWAttribute'], schema['indexed'], |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
136 |
choices=[(u'maybe', '1'), (u'no', '')], req=req) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
137 |
self.assertIsInstance(field.widget, Radio) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
138 |
self.assertEqual(field.vocabulary(mock(req=mock(_=unicode))), |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
139 |
[(u'maybe', '1'), (u'no', '')]) |
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
|
140 |
|
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
|
141 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
142 |
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
|
143 |
def test_rtf_format_field(self): |
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
144 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
145 |
req.use_fckeditor = lambda: False |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
146 |
e = self.vreg['etypes'].etype_class('State')(req) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
147 |
form = EntityFieldsForm(req, entity=e) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
148 |
description_field = guess_field(schema['State'], schema['description']) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
149 |
description_format_field = description_field.get_format_field(form) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
150 |
self.assertEqual(description_format_field.internationalizable, True) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
151 |
self.assertEqual(description_format_field.sort, True) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
152 |
# unlike below, initial is bound to form.form_field_format |
10273
ef74abcf369d
[config] disable fckeditor by default (closes #1368900)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9647
diff
changeset
|
153 |
self.assertEqual(description_format_field.value(form), 'text/plain') |
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
154 |
req.cnx.execute('INSERT CWProperty X: X pkey "ui.default-text-format", X value "text/rest", X for_user U WHERE U login "admin"') |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
155 |
req.cnx.commit() |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
156 |
self.assertEqual(description_format_field.value(form), 'text/rest') |
1858
69e41c88e195
connect format field to form_field_format for its initial value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1836
diff
changeset
|
157 |
|
3334
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
158 |
|
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
159 |
def test_property_key_field(self): |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
160 |
from cubicweb.web.views.cwproperties import PropertyKeyField |
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
161 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
162 |
field = PropertyKeyField(name='test') |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
163 |
e = self.vreg['etypes'].etype_class('CWProperty')(req) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
164 |
renderer = self.vreg['formrenderers'].select('base', req) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
165 |
form = EntityFieldsForm(req, entity=e) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
166 |
form.formvalues = {} |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
167 |
field.render(form, renderer) |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
168 |
|
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6781
diff
changeset
|
169 |
|
9444
6012cf57f48e
[web/formfields] Make CompoundField inherit needs_multipart from its subfields
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8666
diff
changeset
|
170 |
class CompoundFieldTC(CubicWebTC): |
6012cf57f48e
[web/formfields] Make CompoundField inherit needs_multipart from its subfields
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8666
diff
changeset
|
171 |
|
6012cf57f48e
[web/formfields] Make CompoundField inherit needs_multipart from its subfields
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8666
diff
changeset
|
172 |
def test_multipart(self): |
6012cf57f48e
[web/formfields] Make CompoundField inherit needs_multipart from its subfields
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8666
diff
changeset
|
173 |
"""Ensures that compound forms have needs_multipart set if their |
6012cf57f48e
[web/formfields] Make CompoundField inherit needs_multipart from its subfields
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8666
diff
changeset
|
174 |
children require it""" |
6012cf57f48e
[web/formfields] Make CompoundField inherit needs_multipart from its subfields
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8666
diff
changeset
|
175 |
class AForm(FieldsForm): |
6012cf57f48e
[web/formfields] Make CompoundField inherit needs_multipart from its subfields
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8666
diff
changeset
|
176 |
comp = CompoundField([IntField(), StringField()]) |
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
177 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
178 |
aform = AForm(req, None) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
179 |
self.assertFalse(aform.needs_multipart) |
9444
6012cf57f48e
[web/formfields] Make CompoundField inherit needs_multipart from its subfields
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8666
diff
changeset
|
180 |
class MForm(FieldsForm): |
6012cf57f48e
[web/formfields] Make CompoundField inherit needs_multipart from its subfields
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8666
diff
changeset
|
181 |
comp = CompoundField([IntField(), FileField()]) |
9647
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
182 |
with self.admin_access.web_request() as req: |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
183 |
mform = MForm(req, None) |
74cddb36ce1e
[web/test] port unittest_formfields to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
9444
diff
changeset
|
184 |
self.assertTrue(mform.needs_multipart) |
9444
6012cf57f48e
[web/formfields] Make CompoundField inherit needs_multipart from its subfields
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8666
diff
changeset
|
185 |
|
6012cf57f48e
[web/formfields] Make CompoundField inherit needs_multipart from its subfields
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8666
diff
changeset
|
186 |
|
3334
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
187 |
class UtilsTC(TestCase): |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
188 |
def test_vocab_sort(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5712
diff
changeset
|
189 |
self.assertEqual(vocab_sort([('Z', 1), ('A', 2), |
3334
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
190 |
('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
|
191 |
('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
|
192 |
[('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
|
193 |
('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
|
194 |
('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
|
195 |
) |
8d831c02da9a
fix sort of fields vocabulary: should consider option groups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2091
diff
changeset
|
196 |
|
1095
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
197 |
if __name__ == '__main__': |
6917ebe281e9
test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
198 |
unittest_main() |