Ejemplo n.º 1
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.º 2
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')