Ejemplo n.º 1
0
 def test_regexp_transformation(self):
     """test regexp-based rewrite"""
     req = FakeRequest()
     rewriter = SimpleReqRewriter(req)
     rewriter.rewrite(req, '/add/Task')
     self.assertEqual(req.form, {'vid': "creation", 'etype': "Task"})
     req = FakeRequest()
     rewriter.rewrite(req, '/add/Task/')
     self.assertEqual(req.form, {'vid': "creation", 'etype': "Task"})
Ejemplo n.º 2
0
 def test_from_controller(self):
     self._cw.vreg['controllers'] = {'view': 1, 'login': 1}
     self.assertEqual(self._cw.from_controller(), 'view')
     req = FakeRequest(url='project?vid=list')
     req.vreg['controllers'] = {'view': 1, 'login': 1}
     # this assertion is just to make sure that relative_path can be
     # correctly computed as it is used in from_controller()
     self.assertEqual(req.relative_path(False), 'project')
     self.assertEqual(req.from_controller(), 'view')
     # test on a valid non-view controller
     req = FakeRequest(url='login?x=1&y=2')
     req.vreg['controllers'] = {'view': 1, 'login': 1}
     self.assertEqual(req.relative_path(False), 'login')
     self.assertEqual(req.from_controller(), 'login')
Ejemplo n.º 3
0
def _test_cache(hin, hout, method='GET'):
    """forge and process an HTTP request using given headers in/out and method,
    then return it once its .is_client_cache_valid() method has been called.

    req.status_out is None if the page should have been calculated.
    """
    # forge request
    req = FakeRequest(method=method)
    for key, value in hin:
        req._headers_in.addRawHeader(key, str(value))
    for key, value in hout:
        req.headers_out.addRawHeader(key, str(value))
    # process
    req.status_out = None
    req.is_client_cache_valid()
    return req
Ejemplo n.º 4
0
 def test_basic_transformation(self):
     """test simple string-based rewrite"""
     req = FakeRequest()
     rewriter = SimpleReqRewriter(req)
     self.assertRaises(KeyError, rewriter.rewrite, req,
                       '/view?vid=whatever')
     self.assertEqual(req.form, {})
     rewriter.rewrite(req, '/index')
     self.assertEqual(req.form, {'vid': "index"})
Ejemplo n.º 5
0
 def test_nonascii_path(self):
     oldrules = SimpleReqRewriter.rules
     SimpleReqRewriter.rules = [(re.compile('/\w+', re.U), dict(vid='foo'))]
     with self.admin_access.web_request() as req:
         try:
             path = str(FakeRequest().url_quote(u'été'))
             ctrl, rset = self.process(req, path)
             self.assertEqual(rset, None)
             self.assertEqual(req.form, {'vid': "foo"})
         finally:
             SimpleReqRewriter.rules = oldrules
Ejemplo n.º 6
0
 def _test_arurl(self, qs, **kwargs):
     req = FakeRequest()
     arurl = req.ajax_replace_url
     # NOTE: for the simplest use cases, we could use doctest
     url = arurl('foo', **kwargs)
     self.assertTrue(url.startswith('javascript:'))
     self.assertTrue(url.endswith('()'))
     cbname = url.split()[1][:-2]
     self.assertMultiLineEqual(
         'function %s() { $("#foo").loadxhtml("http://testing.fr/cubicweb/ajax?%s",'
         '{"pageid": "%s"},"get","replace"); }' % (cbname, qs, req.pageid),
         req.html_headers.post_inlined_scripts[0])
Ejemplo n.º 7
0
class RequestBaseTC(TestCase):
    def setUp(self):
        self._cw = FakeRequest()

    def test_list_arg(self):
        """tests the list_arg() function"""
        list_arg = self._cw.list_form_param
        self.assertEqual(list_arg('arg3', {}), [])
        d = {
            'arg1': "value1",
            'arg2': (
                'foo',
                INTERNAL_FIELD_VALUE,
            ),
            'arg3': ['bar']
        }
        self.assertEqual(list_arg('arg1', d, True), ['value1'])
        self.assertEqual(d, {
            'arg2': ('foo', INTERNAL_FIELD_VALUE),
            'arg3': ['bar']
        })
        self.assertEqual(list_arg('arg2', d, True), ['foo'])
        self.assertEqual({'arg3': ['bar']}, d)
        self.assertEqual(list_arg('arg3', d), ['bar'])
        self.assertEqual({'arg3': ['bar']}, d)

    def test_from_controller(self):
        self._cw.vreg['controllers'] = {'view': 1, 'login': 1}
        self.assertEqual(self._cw.from_controller(), 'view')
        req = FakeRequest(url='project?vid=list')
        req.vreg['controllers'] = {'view': 1, 'login': 1}
        # this assertion is just to make sure that relative_path can be
        # correctly computed as it is used in from_controller()
        self.assertEqual(req.relative_path(False), 'project')
        self.assertEqual(req.from_controller(), 'view')
        # test on a valid non-view controller
        req = FakeRequest(url='login?x=1&y=2')
        req.vreg['controllers'] = {'view': 1, 'login': 1}
        self.assertEqual(req.relative_path(False), 'login')
        self.assertEqual(req.from_controller(), 'login')
Ejemplo n.º 8
0
 def setUp(self):
     self._cw = FakeRequest()
Ejemplo n.º 9
0
 def __init__(self, form=None):
     self._cw = FakeRequest()
     self._cw.form = form or {}
     self._cursor = MockCursor()
     self._cw.execute = self._cursor.execute