web/test/unittest_views_basecontrollers.py
changeset 10016 984505da8b89
parent 9846 67c1b77b44be
child 10075 136b5f995f8e
equal deleted inserted replaced
10015:57a16bef82c0 10016:984505da8b89
    21 # parse_qs is deprecated in cgi and has been moved to urlparse in Python 2.6
    21 # parse_qs is deprecated in cgi and has been moved to urlparse in Python 2.6
    22 try:
    22 try:
    23     from urlparse import parse_qs as url_parse_query
    23     from urlparse import parse_qs as url_parse_query
    24 except ImportError:
    24 except ImportError:
    25     from cgi import parse_qs as url_parse_query
    25     from cgi import parse_qs as url_parse_query
       
    26 
       
    27 import lxml
       
    28 
    26 from logilab.common.testlib import unittest_main
    29 from logilab.common.testlib import unittest_main
       
    30 
    27 from logilab.common.decorators import monkeypatch
    31 from logilab.common.decorators import monkeypatch
    28 
    32 
    29 from cubicweb import Binary, NoSelectableObject, ValidationError
    33 from cubicweb import Binary, NoSelectableObject, ValidationError
    30 from cubicweb.devtools.testlib import CubicWebTC
    34 from cubicweb.devtools.testlib import CubicWebTC
    31 from cubicweb.utils import json_dumps
    35 from cubicweb.utils import json_dumps
    78             with self.assertRaises(ValidationError) as cm:
    82             with self.assertRaises(ValidationError) as cm:
    79                 self.ctrl_publish(req)
    83                 self.ctrl_publish(req)
    80                 cm.exception.translate(unicode)
    84                 cm.exception.translate(unicode)
    81                 self.assertEqual({'login-subject': 'the value "admin" is already used, use another one'},
    85                 self.assertEqual({'login-subject': 'the value "admin" is already used, use another one'},
    82                                  cm.exception.errors)
    86                                  cm.exception.errors)
       
    87 
       
    88     def test_simultaneous_edition_only_one_commit(self):
       
    89         """ Allow two simultaneous edit view of the same entity as long as only one commits
       
    90         """
       
    91         with self.admin_access.web_request() as req:
       
    92             e = req.create_entity('BlogEntry', title=u'cubicweb.org', content=u"hop")
       
    93             expected_path = e.rest_path()
       
    94             req.cnx.commit()
       
    95             form = self.vreg['views'].select('edition', req, rset=e.as_rset(), row=0)
       
    96             html_form = lxml.html.fromstring(form.render(w=None, action='edit')).forms[0]
       
    97 
       
    98         with self.admin_access.web_request() as req2:
       
    99             form2 = self.vreg['views'].select('edition', req, rset=e.as_rset(), row=0)
       
   100 
       
   101         with self.admin_access.web_request(**dict(html_form.form_values())) as req:
       
   102             path, args = self.expect_redirect_handle_request(req, path='edit')
       
   103             self.assertEqual(path, expected_path)
       
   104 
       
   105     def test_simultaneous_edition_refuse_second_commit(self):
       
   106         """ Disallow committing changes to an entity edited in between """
       
   107         with self.admin_access.web_request() as req:
       
   108             e = req.create_entity('BlogEntry', title=u'cubicweb.org', content=u"hop")
       
   109             eid = e.eid
       
   110             req.cnx.commit()
       
   111             form = self.vreg['views'].select('edition', req, rset=e.as_rset(), row=0)
       
   112             html_form = lxml.html.fromstring(form.render(w=None, action='edit')).forms[0]
       
   113 
       
   114         with self.admin_access.web_request() as req2:
       
   115             e = req2.entity_from_eid(eid)
       
   116             e.cw_set(content = u"hip")
       
   117             req2.cnx.commit()
       
   118 
       
   119         form_field_name = "content-subject:%d" % eid
       
   120         form_values = dict(html_form.form_values())
       
   121         assert form_field_name in form_values
       
   122         form_values[form_field_name] = u'yep'
       
   123         with self.admin_access.web_request(**form_values) as req:
       
   124             with self.assertRaises(ValidationError) as cm:
       
   125                 self.ctrl_publish(req)
       
   126             reported_eid, dict_info = cm.exception.args
       
   127             self.assertEqual(reported_eid, eid)
       
   128             self.assertIn(None, dict_info)
       
   129             self.assertIn("has changed since you started to edit it.", dict_info[None])
    83 
   130 
    84     def test_user_editing_itself(self):
   131     def test_user_editing_itself(self):
    85         """checking that a manager user can edit itself
   132         """checking that a manager user can edit itself
    86         """
   133         """
    87         with self.admin_access.web_request() as req:
   134         with self.admin_access.web_request() as req: