web/test/unittest_application.py
changeset 3462 3a79fecdd2b4
parent 3293 69c0ba095536
child 3524 a3431f4e2f40
equal deleted inserted replaced
3461:8a11aeea4d25 3462:3a79fecdd2b4
    35 
    35 
    36 
    36 
    37 class FakeController(ViewController):
    37 class FakeController(ViewController):
    38 
    38 
    39     def __init__(self, form=None):
    39     def __init__(self, form=None):
    40         self.req = FakeRequest()
    40         self._cw = FakeRequest()
    41         self.req.form = form or {}
    41         self._cw.form = form or {}
    42         self._cursor = self.req.cursor = MockCursor()
    42         self._cursor = self._cw.cursor = MockCursor()
    43 
    43 
    44     def new_cursor(self):
    44     def new_cursor(self):
    45         self._cursor = self.req.cursor = MockCursor()
    45         self._cursor = self._cw.cursor = MockCursor()
    46 
    46 
    47     def set_form(self, form):
    47     def set_form(self, form):
    48         self.req.form = form
    48         self._cw.form = form
    49 
    49 
    50 
    50 
    51 class RequestBaseTC(TestCase):
    51 class RequestBaseTC(TestCase):
    52     def setUp(self):
    52     def setUp(self):
    53         self.req = FakeRequest()
    53         self._cw = FakeRequest()
    54 
    54 
    55 
    55 
    56     def test_list_arg(self):
    56     def test_list_arg(self):
    57         """tests the list_arg() function"""
    57         """tests the list_arg() function"""
    58         list_arg = self.req.list_form_param
    58         list_arg = self._cw.list_form_param
    59         self.assertEquals(list_arg('arg3', {}), [])
    59         self.assertEquals(list_arg('arg3', {}), [])
    60         d = {'arg1' : "value1",
    60         d = {'arg1' : "value1",
    61              'arg2' : ('foo', INTERNAL_FIELD_VALUE,),
    61              'arg2' : ('foo', INTERNAL_FIELD_VALUE,),
    62              'arg3' : ['bar']}
    62              'arg3' : ['bar']}
    63         self.assertEquals(list_arg('arg1', d, True), ['value1'])
    63         self.assertEquals(list_arg('arg1', d, True), ['value1'])
    67         self.assertEquals(list_arg('arg3', d), ['bar',])
    67         self.assertEquals(list_arg('arg3', d), ['bar',])
    68         self.assertEquals({'arg3' : ['bar'],}, d)
    68         self.assertEquals({'arg3' : ['bar'],}, d)
    69 
    69 
    70 
    70 
    71     def test_from_controller(self):
    71     def test_from_controller(self):
    72         self.req.vreg['controllers'] = {'view': 1, 'login': 1}
    72         self._cw.vreg['controllers'] = {'view': 1, 'login': 1}
    73         self.assertEquals(self.req.from_controller(), 'view')
    73         self.assertEquals(self._cw.from_controller(), 'view')
    74         req = FakeRequest(url='project?vid=list')
    74         req = FakeRequest(url='project?vid=list')
    75         req.vreg['controllers'] = {'view': 1, 'login': 1}
    75         req.vreg['controllers'] = {'view': 1, 'login': 1}
    76         # this assertion is just to make sure that relative_path can be
    76         # this assertion is just to make sure that relative_path can be
    77         # correctly computed as it is used in from_controller()
    77         # correctly computed as it is used in from_controller()
    78         self.assertEquals(req.relative_path(False), 'project')
    78         self.assertEquals(req.relative_path(False), 'project')
   121                           ['SET X works_for Y WHERE X eid 8, Y eid %s' % i
   121                           ['SET X works_for Y WHERE X eid 8, Y eid %s' % i
   122                            for i in (12, 13, 14)])
   122                            for i in (12, 13, 14)])
   123 
   123 
   124 
   124 
   125         self.ctrl.new_cursor()
   125         self.ctrl.new_cursor()
   126         self.ctrl.req.form = {'__linkto' : 'works_for:12_13_14:object'}
   126         self.ctrl._cw.form = {'__linkto' : 'works_for:12_13_14:object'}
   127         self.ctrl.execute_linkto(eid=8)
   127         self.ctrl.execute_linkto(eid=8)
   128         self.assertEquals(self.ctrl._cursor.executed,
   128         self.assertEquals(self.ctrl._cursor.executed,
   129                           ['SET Y works_for X WHERE X eid 8, Y eid %s' % i
   129                           ['SET Y works_for X WHERE X eid 8, Y eid %s' % i
   130                            for i in (12, 13, 14)])
   130                            for i in (12, 13, 14)])
   131 
   131