web/test/unittest_formfields.py
branchtls-sprint
changeset 1104 58f27c3c0167
parent 1095 6917ebe281e9
child 1265 e5cdd5c0dce3
equal deleted inserted replaced
1103:f719caf263de 1104:58f27c3c0167
     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 
       
     5 from cubicweb.devtools import TestServerConfiguration
     4 from cubicweb.devtools import TestServerConfiguration
       
     5 from cubicweb.web.formwidgets import PasswordInput
       
     6 from cubicweb.web.formfields import *
     6 from cubicweb.entities.lib import Card
     7 from cubicweb.entities.lib import Card
     7 from cubicweb.entities.authobjs import EUser
     8 from cubicweb.entities.authobjs import EUser
     8 from cubicweb.web.formwidgets import PasswordInput
     9 from cubes.file.entities import File
     9 from cubicweb.web.formfields import *
       
    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
    14 Card.schema = schema
    15 Card.__initialize__()
    15 Card.__initialize__()
    16 EUser.schema = schema
    16 EUser.schema = schema
    17 EUser.__initialize__()
    17 EUser.__initialize__()
       
    18 File.schema = schema
       
    19 File.__initialize__()
    18         
    20         
    19 class GuessFieldTC(TestCase):
    21 class GuessFieldTC(TestCase):
    20     
    22     
    21     def test_card_fields(self):
    23     def test_card_fields(self):
    22         title_field = guess_field(Card, schema['title'])
    24         title_field = guess_field(Card, schema['title'])
    57         owned_by_field = guess_field(EUser, schema['owned_by'], 'object')
    59         owned_by_field = guess_field(EUser, schema['owned_by'], 'object')
    58         self.assertIsInstance(owned_by_field, RelationField)
    60         self.assertIsInstance(owned_by_field, RelationField)
    59         self.assertEquals(owned_by_field.required, False)
    61         self.assertEquals(owned_by_field.required, False)
    60         self.assertEquals(owned_by_field.role, 'object')
    62         self.assertEquals(owned_by_field.role, 'object')
    61 
    63 
    62     
    64     def test_file_fields(self):
       
    65         data_format_field = guess_field(File, schema['data_format'])
       
    66         self.assertEquals(data_format_field, None)
       
    67         data_encoding_field = guess_field(File, schema['data_encoding'])
       
    68         self.assertEquals(data_encoding_field, None)
       
    69 
       
    70         data_field = guess_field(File, schema['data'])
       
    71         self.assertIsInstance(data_field, FileField)
       
    72         self.assertEquals(data_field.required, True)
       
    73         self.assertIsInstance(data_field.format_field, StringField)
       
    74         self.assertIsInstance(data_field.encoding_field, StringField)
       
    75         
    63 if __name__ == '__main__':
    76 if __name__ == '__main__':
    64     unittest_main()
    77     unittest_main()