693 |
693 |
694 def test_ajaxfunc_noparameter(self): |
694 def test_ajaxfunc_noparameter(self): |
695 @ajaxfunc |
695 @ajaxfunc |
696 def foo(self, x, y): |
696 def foo(self, x, y): |
697 return 'hello' |
697 return 'hello' |
698 self.assertTrue(issubclass(foo, AjaxFunction)) |
698 self.assertEqual(foo(object, 1, 2), 'hello') |
699 self.assertEqual(foo.__regid__, 'foo') |
699 appobject = foo.__appobject__ |
700 self.assertEqual(foo.check_pageid, False) |
700 self.assertTrue(issubclass(appobject, AjaxFunction)) |
701 self.assertEqual(foo.output_type, None) |
701 self.assertEqual(appobject.__regid__, 'foo') |
702 req = self.request() |
702 self.assertEqual(appobject.check_pageid, False) |
703 f = foo(req) |
703 self.assertEqual(appobject.output_type, None) |
|
704 req = self.request() |
|
705 f = appobject(req) |
704 self.assertEqual(f(12, 13), 'hello') |
706 self.assertEqual(f(12, 13), 'hello') |
705 |
707 |
706 def test_ajaxfunc_checkpageid(self): |
708 def test_ajaxfunc_checkpageid(self): |
707 @ajaxfunc( check_pageid=True) |
709 @ajaxfunc(check_pageid=True) |
708 def foo(self, x, y): |
710 def foo(self, x, y): |
709 pass |
711 return 'hello' |
710 self.assertTrue(issubclass(foo, AjaxFunction)) |
712 self.assertEqual(foo(object, 1, 2), 'hello') |
711 self.assertEqual(foo.__regid__, 'foo') |
713 appobject = foo.__appobject__ |
712 self.assertEqual(foo.check_pageid, True) |
714 self.assertTrue(issubclass(appobject, AjaxFunction)) |
713 self.assertEqual(foo.output_type, None) |
715 self.assertEqual(appobject.__regid__, 'foo') |
|
716 self.assertEqual(appobject.check_pageid, True) |
|
717 self.assertEqual(appobject.output_type, None) |
714 # no pageid |
718 # no pageid |
715 req = self.request() |
719 req = self.request() |
716 f = foo(req) |
720 f = appobject(req) |
717 self.assertRaises(RemoteCallFailed, f, 12, 13) |
721 self.assertRaises(RemoteCallFailed, f, 12, 13) |
718 |
722 |
719 def test_ajaxfunc_json(self): |
723 def test_ajaxfunc_json(self): |
720 @ajaxfunc(output_type='json') |
724 @ajaxfunc(output_type='json') |
721 def foo(self, x, y): |
725 def foo(self, x, y): |
722 return x + y |
726 return x + y |
723 self.assertTrue(issubclass(foo, AjaxFunction)) |
727 self.assertEqual(foo(object, 1, 2), 3) |
724 self.assertEqual(foo.__regid__, 'foo') |
728 appobject = foo.__appobject__ |
725 self.assertEqual(foo.check_pageid, False) |
729 self.assertTrue(issubclass(appobject, AjaxFunction)) |
726 self.assertEqual(foo.output_type, 'json') |
730 self.assertEqual(appobject.__regid__, 'foo') |
|
731 self.assertEqual(appobject.check_pageid, False) |
|
732 self.assertEqual(appobject.output_type, 'json') |
727 # no pageid |
733 # no pageid |
728 req = self.request() |
734 req = self.request() |
729 f = foo(req) |
735 f = appobject(req) |
730 self.assertEqual(f(12, 13), '25') |
736 self.assertEqual(f(12, 13), '25') |
731 |
737 |
732 |
738 |
733 class JSonControllerTC(AjaxControllerTC): |
739 class JSonControllerTC(AjaxControllerTC): |
734 # NOTE: this class performs the same tests as AjaxController but with |
740 # NOTE: this class performs the same tests as AjaxController but with |