web/test/unittest_formfields.py
branchtls-sprint
changeset 1095 6917ebe281e9
child 1104 58f27c3c0167
equal deleted inserted replaced
1094:b42340dda74b 1095:6917ebe281e9
       
     1 """unittests for cw.web.formfields"""
       
     2 
       
     3 from logilab.common.testlib import TestCase, unittest_main
       
     4 
       
     5 from cubicweb.devtools import TestServerConfiguration
       
     6 from cubicweb.entities.lib import Card
       
     7 from cubicweb.entities.authobjs import EUser
       
     8 from cubicweb.web.formwidgets import PasswordInput
       
     9 from cubicweb.web.formfields import *
       
    10 
       
    11 config = TestServerConfiguration('data')
       
    12 config.bootstrap_cubes()
       
    13 schema = config.load_schema()
       
    14 Card.schema = schema
       
    15 Card.__initialize__()
       
    16 EUser.schema = schema
       
    17 EUser.__initialize__()
       
    18         
       
    19 class GuessFieldTC(TestCase):
       
    20     
       
    21     def test_card_fields(self):
       
    22         title_field = guess_field(Card, schema['title'])
       
    23         self.assertIsInstance(title_field, StringField)
       
    24         self.assertEquals(title_field.required, True)
       
    25         
       
    26         synopsis_field = guess_field(Card, schema['synopsis'])
       
    27         self.assertIsInstance(synopsis_field, TextField)
       
    28         self.assertEquals(synopsis_field.required, False)
       
    29         
       
    30         content_field = guess_field(Card, schema['content'])
       
    31         self.assertIsInstance(content_field, RichTextField)
       
    32         self.assertEquals(content_field.required, False)
       
    33         
       
    34         content_format_field = guess_field(Card, schema['content_format'])
       
    35         self.assertEquals(content_format_field, None)
       
    36         
       
    37         wikiid_field = guess_field(Card, schema['wikiid'])
       
    38         self.assertIsInstance(wikiid_field, StringField)
       
    39         self.assertEquals(wikiid_field.required, False)
       
    40 
       
    41         
       
    42     def test_euser_fields(self):
       
    43         upassword_field = guess_field(EUser, schema['upassword'])
       
    44         self.assertIsInstance(upassword_field, StringField)
       
    45         self.assertIsInstance(upassword_field.widget, PasswordInput)
       
    46         self.assertEquals(upassword_field.required, True)
       
    47 
       
    48         last_login_time_field = guess_field(EUser, schema['last_login_time'])
       
    49         self.assertIsInstance(last_login_time_field, DateTimeField)
       
    50         self.assertEquals(last_login_time_field.required, False)
       
    51 
       
    52         in_group_field = guess_field(EUser, schema['in_group'])
       
    53         self.assertIsInstance(in_group_field, RelationField)
       
    54         self.assertEquals(in_group_field.required, True)
       
    55         self.assertEquals(in_group_field.role, 'subject')
       
    56 
       
    57         owned_by_field = guess_field(EUser, schema['owned_by'], 'object')
       
    58         self.assertIsInstance(owned_by_field, RelationField)
       
    59         self.assertEquals(owned_by_field.required, False)
       
    60         self.assertEquals(owned_by_field.role, 'object')
       
    61 
       
    62     
       
    63 if __name__ == '__main__':
       
    64     unittest_main()