equal
deleted
inserted
replaced
1 """unittests for cw.web.formfields""" |
1 """unittests for cw.web.formfields""" |
2 |
2 |
|
3 from yams.constraints import StaticVocabularyConstraint, SizeConstraint |
3 from logilab.common.testlib import TestCase, unittest_main |
4 from logilab.common.testlib import TestCase, unittest_main |
4 from cubicweb.devtools import TestServerConfiguration |
5 from cubicweb.devtools import TestServerConfiguration |
5 from cubicweb.web.formwidgets import PasswordInput, TextArea |
6 from cubicweb.web.formwidgets import PasswordInput, TextArea, Select |
6 from cubicweb.web.formfields import * |
7 from cubicweb.web.formfields import * |
7 from cubicweb.entities.wfobjs import State |
8 from cubicweb.entities.wfobjs import State |
8 from cubicweb.entities.authobjs import CWUser |
9 from cubicweb.entities.authobjs import CWUser |
9 from cubes.file.entities import File |
10 from cubes.file.entities import File |
10 |
11 |
12 config.bootstrap_cubes() |
13 config.bootstrap_cubes() |
13 schema = config.load_schema() |
14 schema = config.load_schema() |
14 state_schema = schema['State'] |
15 state_schema = schema['State'] |
15 cwuser_schema = schema['CWUser'] |
16 cwuser_schema = schema['CWUser'] |
16 file_schema = schema['File'] |
17 file_schema = schema['File'] |
|
18 salesterm_schema = schema['Salesterm'] |
17 |
19 |
18 class GuessFieldTC(TestCase): |
20 class GuessFieldTC(TestCase): |
19 |
21 |
20 def test_state_fields(self): |
22 def test_state_fields(self): |
21 title_field = guess_field(state_schema, schema['name']) |
23 title_field = guess_field(state_schema, schema['name']) |
78 self.assertIsInstance(data_field, FileField) |
80 self.assertIsInstance(data_field, FileField) |
79 self.assertEquals(data_field.required, True) |
81 self.assertEquals(data_field.required, True) |
80 self.assertIsInstance(data_field.format_field, StringField) |
82 self.assertIsInstance(data_field.format_field, StringField) |
81 self.assertIsInstance(data_field.encoding_field, StringField) |
83 self.assertIsInstance(data_field.encoding_field, StringField) |
82 |
84 |
|
85 def test_constraints_priority(self): |
|
86 salesterm_field = guess_field(salesterm_schema, schema['reason']) |
|
87 constraints = schema['reason'].rproperty('Salesterm', 'String', 'constraints') |
|
88 self.assertEquals([c.__class__ for c in constraints], |
|
89 [SizeConstraint, StaticVocabularyConstraint]) |
|
90 self.assertIsInstance(salesterm_field.widget, Select) |
|
91 |
83 if __name__ == '__main__': |
92 if __name__ == '__main__': |
84 unittest_main() |
93 unittest_main() |