47 from cubicweb import cwconfig, devtools, repoapi, server, web |
47 from cubicweb import cwconfig, devtools, repoapi, server, web |
48 from cubicweb.utils import json |
48 from cubicweb.utils import json |
49 from cubicweb.sobjects import notification |
49 from cubicweb.sobjects import notification |
50 from cubicweb.web import Redirect, application, eid_param |
50 from cubicweb.web import Redirect, application, eid_param |
51 from cubicweb.server.hook import SendMailOp |
51 from cubicweb.server.hook import SendMailOp |
52 from cubicweb.server.session import Session |
|
53 from cubicweb.devtools import SYSTEM_ENTITIES, SYSTEM_RELATIONS, VIEW_VALIDATORS |
52 from cubicweb.devtools import SYSTEM_ENTITIES, SYSTEM_RELATIONS, VIEW_VALIDATORS |
54 from cubicweb.devtools import fake, htmlparser, DEFAULT_EMPTY_DB_ID |
53 from cubicweb.devtools import fake, htmlparser, DEFAULT_EMPTY_DB_ID |
55 from cubicweb.devtools.fill import insert_entity_queries, make_relations_queries |
54 from cubicweb.devtools.fill import insert_entity_queries, make_relations_queries |
56 |
55 from cubicweb.web.views.authentication import Session |
57 |
56 |
58 if sys.version_info[:2] < (3, 4): |
57 if sys.version_info[:2] < (3, 4): |
59 from unittest2 import TestCase |
58 from unittest2 import TestCase |
60 if not hasattr(TestCase, 'subTest'): |
59 if not hasattr(TestCase, 'subTest'): |
61 raise ImportError('no subTest support in available unittest2') |
60 raise ImportError('no subTest support in available unittest2') |
249 To commit and rollback use:: |
248 To commit and rollback use:: |
250 |
249 |
251 req.cnx.commit() |
250 req.cnx.commit() |
252 req.cnx.rolback() |
251 req.cnx.rolback() |
253 """ |
252 """ |
|
253 session = kwargs.pop('session', Session(self._repo, self._user)) |
254 req = self.requestcls(self._repo.vreg, url=url, headers=headers, |
254 req = self.requestcls(self._repo.vreg, url=url, headers=headers, |
255 method=method, form=kwargs) |
255 method=method, form=kwargs) |
256 with self.cnx() as cnx: |
256 with self.cnx() as cnx: |
257 # web request expect a session attribute on cnx referencing the web session |
257 # web request expect a session attribute on cnx referencing the web session |
258 cnx.session = Session(self._repo, self._user) |
258 cnx.session = session |
259 req.set_cnx(cnx) |
259 req.set_cnx(cnx) |
260 yield req |
260 yield req |
261 |
261 |
262 @contextmanager |
262 @contextmanager |
263 def shell(self): |
263 def shell(self): |
679 req = self.request(fname=fname, pageid='123', arg=args) |
679 req = self.request(fname=fname, pageid='123', arg=args) |
680 ctrl = self.vreg['controllers'].select('ajax', req) |
680 ctrl = self.vreg['controllers'].select('ajax', req) |
681 return ctrl.publish(), req |
681 return ctrl.publish(), req |
682 |
682 |
683 @contextmanager |
683 @contextmanager |
684 def remote_calling(self, fname, *args): |
684 def remote_calling(self, fname, *args, **kwargs): |
685 """remote json call simulation""" |
685 """remote json call simulation""" |
686 args = [json.dumps(arg) for arg in args] |
686 args = [json.dumps(arg) for arg in args] |
687 with self.admin_access.web_request(fname=fname, pageid='123', arg=args) as req: |
687 with self.admin_access.web_request(fname=fname, pageid='123', arg=args, **kwargs) as req: |
688 ctrl = self.vreg['controllers'].select('ajax', req) |
688 ctrl = self.vreg['controllers'].select('ajax', req) |
689 yield ctrl.publish(), req |
689 yield ctrl.publish(), req |
690 |
690 |
691 def app_handle_request(self, req, path=None): |
691 def app_handle_request(self, req, path=None): |
692 if path is not None: |
692 if path is not None: |