web/test/unittest_form.py
changeset 10786 2ef74a6e6785
parent 10782 65bb683d2a51
child 11013 645fcb5bcc39
equal deleted inserted replaced
10785:e63fb79b32e0 10786:2ef74a6e6785
    18 
    18 
    19 import time
    19 import time
    20 
    20 
    21 from xml.etree.ElementTree import fromstring
    21 from xml.etree.ElementTree import fromstring
    22 from lxml import html
    22 from lxml import html
       
    23 
       
    24 from six import text_type
    23 
    25 
    24 from logilab.common.testlib import unittest_main
    26 from logilab.common.testlib import unittest_main
    25 
    27 
    26 from cubicweb import Binary, ValidationError
    28 from cubicweb import Binary, ValidationError
    27 from cubicweb.devtools.testlib import CubicWebTC
    29 from cubicweb.devtools.testlib import CubicWebTC
    63         with self.admin_access.web_request() as req:
    65         with self.admin_access.web_request() as req:
    64             b = req.create_entity('BlogEntry', title=u'di mascii code', content=u'a best-seller')
    66             b = req.create_entity('BlogEntry', title=u'di mascii code', content=u'a best-seller')
    65             t = req.create_entity('Tag', name=u'x')
    67             t = req.create_entity('Tag', name=u'x')
    66             form1 = self.vreg['forms'].select('edition', req, entity=t)
    68             form1 = self.vreg['forms'].select('edition', req, entity=t)
    67             choices = [reid for rview, reid in form1.field_by_name('tags', 'subject', t.e_schema).choices(form1)]
    69             choices = [reid for rview, reid in form1.field_by_name('tags', 'subject', t.e_schema).choices(form1)]
    68             self.assertIn(unicode(b.eid), choices)
    70             self.assertIn(text_type(b.eid), choices)
    69             form2 = self.vreg['forms'].select('edition', req, entity=b)
    71             form2 = self.vreg['forms'].select('edition', req, entity=b)
    70             choices = [reid for rview, reid in form2.field_by_name('tags', 'object', t.e_schema).choices(form2)]
    72             choices = [reid for rview, reid in form2.field_by_name('tags', 'object', t.e_schema).choices(form2)]
    71             self.assertIn(unicode(t.eid), choices)
    73             self.assertIn(text_type(t.eid), choices)
    72 
    74 
    73             b.cw_clear_all_caches()
    75             b.cw_clear_all_caches()
    74             t.cw_clear_all_caches()
    76             t.cw_clear_all_caches()
    75             req.cnx.execute('SET X tags Y WHERE X is Tag, Y is BlogEntry')
    77             req.cnx.execute('SET X tags Y WHERE X is Tag, Y is BlogEntry')
    76 
    78 
    77             choices = [reid for rview, reid in form1.field_by_name('tags', 'subject', t.e_schema).choices(form1)]
    79             choices = [reid for rview, reid in form1.field_by_name('tags', 'subject', t.e_schema).choices(form1)]
    78             self.assertIn(unicode(b.eid), choices)
    80             self.assertIn(text_type(b.eid), choices)
    79             choices = [reid for rview, reid in form2.field_by_name('tags', 'object', t.e_schema).choices(form2)]
    81             choices = [reid for rview, reid in form2.field_by_name('tags', 'object', t.e_schema).choices(form2)]
    80             self.assertIn(unicode(t.eid), choices)
    82             self.assertIn(text_type(t.eid), choices)
    81 
    83 
    82     def test_form_field_choices_new_entity(self):
    84     def test_form_field_choices_new_entity(self):
    83         with self.admin_access.web_request() as req:
    85         with self.admin_access.web_request() as req:
    84             e = self.vreg['etypes'].etype_class('CWUser')(req)
    86             e = self.vreg['etypes'].etype_class('CWUser')(req)
    85             form = self.vreg['forms'].select('edition', req, entity=e)
    87             form = self.vreg['forms'].select('edition', req, entity=e)