1 """unittests for cw.web.formfields""" |
1 """unittests for cw.web.formfields""" |
2 |
2 |
3 from logilab.common.testlib import TestCase, unittest_main |
3 from logilab.common.testlib import TestCase, unittest_main |
4 from cubicweb.devtools import TestServerConfiguration |
4 from cubicweb.devtools import TestServerConfiguration |
5 from cubicweb.web.formwidgets import PasswordInput |
5 from cubicweb.web.formwidgets import PasswordInput, TextArea |
6 from cubicweb.web.formfields import * |
6 from cubicweb.web.formfields import * |
7 from cubicweb.entities.lib import Card |
7 from cubicweb.entities.wfobjs import State |
8 from cubicweb.entities.authobjs import CWUser |
8 from cubicweb.entities.authobjs import CWUser |
9 from cubes.file.entities import File |
9 from cubes.file.entities import File |
10 |
10 |
11 config = TestServerConfiguration('data') |
11 config = TestServerConfiguration('data') |
12 config.bootstrap_cubes() |
12 config.bootstrap_cubes() |
13 schema = config.load_schema() |
13 schema = config.load_schema() |
14 card_schema = schema['Card'] |
14 state_schema = schema['State'] |
15 cwuser_schema = schema['CWUser'] |
15 cwuser_schema = schema['CWUser'] |
16 file_schema.schema = schema['File'] |
16 file_schema.schema = schema['File'] |
17 |
17 |
18 class GuessFieldTC(TestCase): |
18 class GuessFieldTC(TestCase): |
19 |
19 |
20 def test_card_fields(self): |
20 def test_state_fields(self): |
21 title_field = guess_field(card_schema, schema['title']) |
21 title_field = guess_field(state_schema, schema['name']) |
22 self.assertIsInstance(title_field, StringField) |
22 self.assertIsInstance(title_field, StringField) |
23 self.assertEquals(title_field.required, True) |
23 self.assertEquals(title_field.required, True) |
24 |
24 |
25 synopsis_field = guess_field(card_schema, schema['synopsis']) |
25 # synopsis_field = guess_field(state_schema, schema['synopsis']) |
26 self.assertIsInstance(synopsis_field, TextField) |
26 # self.assertIsInstance(synopsis_field, StringField) |
27 self.assertEquals(synopsis_field.required, False) |
27 # self.assertIsInstance(synopsis_field.widget, TextArea) |
28 self.assertEquals(synopsis_field.help, 'an abstract for this card') |
28 # self.assertEquals(synopsis_field.required, False) |
|
29 # self.assertEquals(synopsis_field.help, 'an abstract for this state') |
29 |
30 |
30 content_field = guess_field(card_schema, schema['content']) |
31 description_field = guess_field(state_schema, schema['description']) |
31 self.assertIsInstance(content_field, RichTextField) |
32 self.assertIsInstance(description_field, RichTextField) |
32 self.assertEquals(content_field.required, False) |
33 self.assertEquals(description_field.required, False) |
33 self.assertEquals(content_field.format_field, None) |
34 self.assertEquals(description_field.format_field, None) |
34 |
35 |
35 content_format_field = guess_field(card_schema, schema['content_format']) |
36 description_format_field = guess_field(state_schema, schema['description_format']) |
36 self.assertEquals(content_format_field, None) |
37 self.assertEquals(description_format_field, None) |
37 |
38 |
38 content_format_field = guess_field(card_schema, schema['content_format'], skip_meta_attr=False) |
39 description_format_field = guess_field(state_schema, schema['description_format'], skip_meta_attr=False) |
39 self.assertEquals(content_format_field.internationalizable, True) |
40 self.assertEquals(description_format_field.internationalizable, True) |
40 self.assertEquals(content_format_field.sort, True) |
41 self.assertEquals(description_format_field.sort, True) |
41 self.assertEquals(content_format_field.initial, 'text/rest') |
42 self.assertEquals(description_format_field.initial, 'text/rest') |
42 |
43 |
43 wikiid_field = guess_field(card_schema, schema['wikiid']) |
44 # wikiid_field = guess_field(state_schema, schema['wikiid']) |
44 self.assertIsInstance(wikiid_field, StringField) |
45 # self.assertIsInstance(wikiid_field, StringField) |
45 self.assertEquals(wikiid_field.required, False) |
46 # self.assertEquals(wikiid_field.required, False) |
46 |
47 |
47 |
48 |
48 def test_euser_fields(self): |
49 def test_euser_fields(self): |
49 upassword_field = guess_field(cwuser_schema, schema['upassword']) |
50 upassword_field = guess_field(cwuser_schema, schema['upassword']) |
50 self.assertIsInstance(upassword_field, StringField) |
51 self.assertIsInstance(upassword_field, StringField) |