web/test/unittest_views_basecontrollers.py
changeset 10751 9ffdfa1d28f5
parent 10749 2703116e4b21
child 10932 cb217b2b3463
equal deleted inserted replaced
10750:1166a47dad40 10751:9ffdfa1d28f5
   407                         '_cw_entity_fields:%s'%seid: 'amount-subject',
   407                         '_cw_entity_fields:%s'%seid: 'amount-subject',
   408                         'amount-subject:%s'%seid: u'-10',
   408                         'amount-subject:%s'%seid: u'-10',
   409                     }
   409                     }
   410             self.assertMultiLineEqual('''<script type="text/javascript">
   410             self.assertMultiLineEqual('''<script type="text/javascript">
   411  window.parent.handleFormValidationResponse('entityForm', null, null, [false, [%s, {"amount-subject": "value -10 must be >= 0"}], null], null);
   411  window.parent.handleFormValidationResponse('entityForm', null, null, [false, [%s, {"amount-subject": "value -10 must be >= 0"}], null], null);
   412 </script>'''%seid, self.ctrl_publish(req, 'validateform'))
   412 </script>'''%seid, self.ctrl_publish(req, 'validateform').decode('ascii'))
   413 
   413 
   414         # ensure a value that comply a constraint is properly processed
   414         # ensure a value that comply a constraint is properly processed
   415         with self.admin_access.web_request(rollbackfirst=True) as req:
   415         with self.admin_access.web_request(rollbackfirst=True) as req:
   416             req.form = {'eid': [text_type(seid)],
   416             req.form = {'eid': [text_type(seid)],
   417                         '__type:%s'%seid: 'Salesterm',
   417                         '__type:%s'%seid: 'Salesterm',
   418                         '_cw_entity_fields:%s'%seid: 'amount-subject',
   418                         '_cw_entity_fields:%s'%seid: 'amount-subject',
   419                         'amount-subject:%s'%seid: u'20',
   419                         'amount-subject:%s'%seid: u'20',
   420                     }
   420                     }
   421             self.assertMultiLineEqual('''<script type="text/javascript">
   421             self.assertMultiLineEqual('''<script type="text/javascript">
   422  window.parent.handleFormValidationResponse('entityForm', null, null, [true, "http://testing.fr/cubicweb/view", null], null);
   422  window.parent.handleFormValidationResponse('entityForm', null, null, [true, "http://testing.fr/cubicweb/view", null], null);
   423 </script>''', self.ctrl_publish(req, 'validateform'))
   423 </script>''', self.ctrl_publish(req, 'validateform').decode('ascii'))
   424             self.assertEqual(20, req.execute('Any V WHERE X amount V, X eid %(eid)s',
   424             self.assertEqual(20, req.execute('Any V WHERE X amount V, X eid %(eid)s',
   425                                              {'eid': seid})[0][0])
   425                                              {'eid': seid})[0][0])
   426 
   426 
   427         with self.admin_access.web_request(rollbackfirst=True) as req:
   427         with self.admin_access.web_request(rollbackfirst=True) as req:
   428             req.form = {'eid': ['X'],
   428             req.form = {'eid': ['X'],
   446                     MyOperation(self._cw, entity=self.entity)
   446                     MyOperation(self._cw, entity=self.entity)
   447 
   447 
   448             with self.temporary_appobjects(ValidationErrorInOpAfterHook):
   448             with self.temporary_appobjects(ValidationErrorInOpAfterHook):
   449                 self.assertMultiLineEqual('''<script type="text/javascript">
   449                 self.assertMultiLineEqual('''<script type="text/javascript">
   450  window.parent.handleFormValidationResponse('entityForm', null, null, [false, ["X", {"amount-subject": "value -10 must be >= 0"}], null], null);
   450  window.parent.handleFormValidationResponse('entityForm', null, null, [false, ["X", {"amount-subject": "value -10 must be >= 0"}], null], null);
   451 </script>''', self.ctrl_publish(req, 'validateform'))
   451 </script>''', self.ctrl_publish(req, 'validateform').decode('ascii'))
   452 
   452 
   453             self.assertMultiLineEqual('''<script type="text/javascript">
   453             self.assertMultiLineEqual('''<script type="text/javascript">
   454  window.parent.handleFormValidationResponse('entityForm', null, null, [true, "http://testing.fr/cubicweb/view", null], null);
   454  window.parent.handleFormValidationResponse('entityForm', null, null, [true, "http://testing.fr/cubicweb/view", null], null);
   455 </script>''', self.ctrl_publish(req, 'validateform'))
   455 </script>''', self.ctrl_publish(req, 'validateform').decode('ascii'))
   456 
   456 
   457     def test_req_pending_insert(self):
   457     def test_req_pending_insert(self):
   458         """make sure req's pending insertions are taken into account"""
   458         """make sure req's pending insertions are taken into account"""
   459         with self.admin_access.web_request() as req:
   459         with self.admin_access.web_request() as req:
   460             tmpgroup = req.create_entity('CWGroup', name=u"test")
   460             tmpgroup = req.create_entity('CWGroup', name=u"test")
   962                 pass
   962                 pass
   963         @monkeypatch(JSonController)
   963         @monkeypatch(JSonController)
   964         def js_foo(self):
   964         def js_foo(self):
   965             return u'hello'
   965             return u'hello'
   966         with self.remote_calling('foo') as (res, _):
   966         with self.remote_calling('foo') as (res, _):
   967             self.assertEqual(res, u'hello')
   967             self.assertEqual(res, b'hello')
   968 
   968 
   969     def test_monkeypatch_jsoncontroller_xhtmlize(self):
   969     def test_monkeypatch_jsoncontroller_xhtmlize(self):
   970         with self.assertRaises(RemoteCallFailed):
   970         with self.assertRaises(RemoteCallFailed):
   971             with self.remote_calling('foo'):
   971             with self.remote_calling('foo'):
   972                 pass
   972                 pass
   973         @monkeypatch(JSonController)
   973         @monkeypatch(JSonController)
   974         @xhtmlize
   974         @xhtmlize
   975         def js_foo(self):
   975         def js_foo(self):
   976             return u'hello'
   976             return u'hello'
   977         with self.remote_calling('foo') as (res, _):
   977         with self.remote_calling('foo') as (res, _):
   978             self.assertEqual(u'<div>hello</div>', res)
   978             self.assertEqual(b'<div>hello</div>', res)
   979 
   979 
   980     def test_monkeypatch_jsoncontroller_jsonize(self):
   980     def test_monkeypatch_jsoncontroller_jsonize(self):
   981         with self.assertRaises(RemoteCallFailed):
   981         with self.assertRaises(RemoteCallFailed):
   982             with self.remote_calling('foo'):
   982             with self.remote_calling('foo'):
   983                 pass
   983                 pass
   984         @monkeypatch(JSonController)
   984         @monkeypatch(JSonController)
   985         @jsonize
   985         @jsonize
   986         def js_foo(self):
   986         def js_foo(self):
   987             return 12
   987             return 12
   988         with self.remote_calling('foo') as (res, _):
   988         with self.remote_calling('foo') as (res, _):
   989             self.assertEqual(res, '12')
   989             self.assertEqual(res, b'12')
   990 
   990 
   991     def test_monkeypatch_jsoncontroller_stdfunc(self):
   991     def test_monkeypatch_jsoncontroller_stdfunc(self):
   992         @monkeypatch(JSonController)
   992         @monkeypatch(JSonController)
   993         @jsonize
   993         @jsonize
   994         def js_reledit_form(self):
   994         def js_reledit_form(self):
   995             return 12
   995             return 12
   996         with self.remote_calling('reledit_form') as (res, _):
   996         with self.remote_calling('reledit_form') as (res, _):
   997             self.assertEqual(res, '12')
   997             self.assertEqual(res, b'12')
   998 
   998 
   999 
   999 
  1000 class UndoControllerTC(CubicWebTC):
  1000 class UndoControllerTC(CubicWebTC):
  1001 
  1001 
  1002     def setUp(self):
  1002     def setUp(self):