web/test/unittest_formfields.py
author sylvain.thenault@logilab.fr
Tue, 28 Apr 2009 19:09:37 +0200
branchtls-sprint
changeset 1519 5cfc5cc1dd20
parent 1453 a9841184be7c
child 1570 5c40d9fb4e8d
permissions -rw-r--r--
fix retreival of previously submitted error for entity forms
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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()
1453
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    14
card_schema = schema['Card']
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    15
cwuser_schema = schema['CWUser']
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    16
file_schema.schema = schema['File']
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    17
1095
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    18
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
    19
1095
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    20
    def test_card_fields(self):
1453
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    21
        title_field = guess_field(card_schema, schema['title'])
1095
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    22
        self.assertIsInstance(title_field, StringField)
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    23
        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
    24
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    25
        synopsis_field = guess_field(card_schema, schema['synopsis'])
1095
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    26
        self.assertIsInstance(synopsis_field, TextField)
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    27
        self.assertEquals(synopsis_field.required, False)
1268
5db94912650b get field's help in guess_field
sylvain.thenault@logilab.fr
parents: 1265
diff changeset
    28
        self.assertEquals(synopsis_field.help, 'an abstract for this card')
1453
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    29
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    30
        content_field = guess_field(card_schema, schema['content'])
1095
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    31
        self.assertIsInstance(content_field, RichTextField)
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
        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
    33
        self.assertEquals(content_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
    34
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    35
        content_format_field = guess_field(card_schema, schema['content_format'])
1095
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    36
        self.assertEquals(content_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
    37
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    38
        content_format_field = guess_field(card_schema, schema['content_format'], skip_meta_attr=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
    39
        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
    40
        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
    41
        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
    42
1453
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    43
        wikiid_field = guess_field(card_schema, schema['wikiid'])
1095
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    44
        self.assertIsInstance(wikiid_field, StringField)
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    45
        self.assertEquals(wikiid_field.required, False)
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    46
1453
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    47
1095
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    48
    def test_euser_fields(self):
1453
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    49
        upassword_field = guess_field(cwuser_schema, schema['upassword'])
1095
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    50
        self.assertIsInstance(upassword_field, StringField)
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    51
        self.assertIsInstance(upassword_field.widget, PasswordInput)
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    52
        self.assertEquals(upassword_field.required, True)
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    53
1453
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    54
        last_login_time_field = guess_field(cwuser_schema, schema['last_login_time'])
1095
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    55
        self.assertIsInstance(last_login_time_field, DateTimeField)
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    56
        self.assertEquals(last_login_time_field.required, False)
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    57
1453
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    58
        in_group_field = guess_field(cwuser_schema, schema['in_group'])
1095
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    59
        self.assertIsInstance(in_group_field, RelationField)
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    60
        self.assertEquals(in_group_field.required, True)
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    61
        self.assertEquals(in_group_field.role, 'subject')
1268
5db94912650b get field's help in guess_field
sylvain.thenault@logilab.fr
parents: 1265
diff changeset
    62
        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
    63
1453
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    64
        owned_by_field = guess_field(cwuser_schema, schema['owned_by'], 'object')
1095
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    65
        self.assertIsInstance(owned_by_field, RelationField)
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    66
        self.assertEquals(owned_by_field.required, False)
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    67
        self.assertEquals(owned_by_field.role, 'object')
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    68
1268
5db94912650b get field's help in guess_field
sylvain.thenault@logilab.fr
parents: 1265
diff changeset
    69
1104
58f27c3c0167 more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents: 1095
diff changeset
    70
    def test_file_fields(self):
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
        data_format_field = guess_field(file_schema, schema['data_format'])
1104
58f27c3c0167 more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents: 1095
diff changeset
    72
        self.assertEquals(data_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
    73
        data_encoding_field = guess_field(file_schema, schema['data_encoding'])
1104
58f27c3c0167 more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents: 1095
diff changeset
    74
        self.assertEquals(data_encoding_field, None)
58f27c3c0167 more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents: 1095
diff changeset
    75
1453
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    76
        data_field = guess_field(file_schema, schema['data'])
1104
58f27c3c0167 more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents: 1095
diff changeset
    77
        self.assertIsInstance(data_field, FileField)
58f27c3c0167 more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents: 1095
diff changeset
    78
        self.assertEquals(data_field.required, True)
58f27c3c0167 more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents: 1095
diff changeset
    79
        self.assertIsInstance(data_field.format_field, StringField)
58f27c3c0167 more guess_field tests and fixes
sylvain.thenault@logilab.fr
parents: 1095
diff changeset
    80
        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
    81
1095
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    82
if __name__ == '__main__':
6917ebe281e9 test and fix guess_field, some pylint fixes
sylvain.thenault@logilab.fr
parents:
diff changeset
    83
    unittest_main()