web/test/unittest_form.py
branchtls-sprint
changeset 1359 bef6891393d7
parent 1345 9f086baa2537
child 1393 ff6758d7b96f
equal deleted inserted replaced
1358:a7438eb2420c 1359:bef6891393d7
     1 from logilab.common.testlib import unittest_main, mock_object
     1 from logilab.common.testlib import unittest_main, mock_object
     2 from cubicweb import Binary
     2 from cubicweb import Binary
     3 from cubicweb.devtools.testlib import WebTest
     3 from cubicweb.devtools.testlib import WebTest
     4 from cubicweb.web.form import EntityFieldsForm, FormRenderer
     4 from cubicweb.web.form import EntityFieldsForm, FieldsForm, FormRenderer
     5 from cubicweb.web.formfields import (IntField, StringField, RichTextField,
     5 from cubicweb.web.formfields import (IntField, StringField, RichTextField,
     6                                      DateTimeField, DateTimePicker,
     6                                      DateTimeField, DateTimePicker,
     7                                      FileField, EditableFileField)
     7                                      FileField, EditableFileField)
     8 from cubicweb.web.formwidgets import PasswordInput
     8 from cubicweb.web.formwidgets import PasswordInput
     9 from cubicweb.web.views.workflow import ChangeStateForm
     9 from cubicweb.web.views.workflow import ChangeStateForm
       
    10 
       
    11 
       
    12 class FieldsFormTC(WebTest):
       
    13 
       
    14     def test_form_field_format(self):
       
    15         form = FieldsForm(self.request(), None)
       
    16         self.assertEquals(form.form_field_format(None), 'text/html')
       
    17         self.execute('INSERT EProperty X: X pkey "ui.default-text-format", X value "text/rest", X for_user U WHERE U login "admin"')
       
    18         self.commit()
       
    19         self.assertEquals(form.form_field_format(None), 'text/rest')
    10 
    20 
    11 
    21 
    12 class EntityFieldsFormTC(WebTest):
    22 class EntityFieldsFormTC(WebTest):
    13 
    23 
    14     def setUp(self):
    24     def setUp(self):
    36         e = self.etype_instance('EUser')
    46         e = self.etype_instance('EUser')
    37         form = EntityFieldsForm(self.request(), None, entity=e)
    47         form = EntityFieldsForm(self.request(), None, entity=e)
    38         unrelated = [rview for rview, reid in form.subject_relation_vocabulary('in_group')]
    48         unrelated = [rview for rview, reid in form.subject_relation_vocabulary('in_group')]
    39         # should be default groups but owners, i.e. managers, users, guests
    49         # should be default groups but owners, i.e. managers, users, guests
    40         self.assertEquals(unrelated, [u'guests', u'managers', u'users'])
    50         self.assertEquals(unrelated, [u'guests', u'managers', u'users'])
       
    51 
       
    52     def test_subject_in_state_vocabulary(self):
       
    53         # on a new entity
       
    54         e = self.etype_instance('EUser')
       
    55         form = EntityFieldsForm(self.request(), None, entity=e)
       
    56         states = list(form.subject_in_state_vocabulary('in_state'))
       
    57         self.assertEquals(len(states), 1)
       
    58         self.assertEquals(states[0][0], u'activated') # list of (combobox view, state eid)
       
    59         # on an existant entity
       
    60         e = self.user()
       
    61         form = EntityFieldsForm(self.request(), None, entity=e)
       
    62         states = list(form.subject_in_state_vocabulary('in_state'))
       
    63         self.assertEquals(len(states), 1)
       
    64         self.assertEquals(states[0][0], u'deactivated') # list of (combobox view, state eid)
       
    65 
    41 
    66 
    42         
    67         
    43     # form view tests #########################################################
    68     # form view tests #########################################################
    44         
    69         
    45     def test_massmailing_formview(self):
    70     def test_massmailing_formview(self):