Warning:
Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.
| File test_reponse.py,
1.0 KB
(added by Felix.Schwarz, 5 years ago) |
|
some cleanup, removed wrong cherrypy.request assignments
|
| Line | |
|---|
| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: UTF-8 -*- |
|---|
| 3 | |
|---|
| 4 | import unittest |
|---|
| 5 | |
|---|
| 6 | import cherrypy |
|---|
| 7 | import turbogears |
|---|
| 8 | from turbogears import controllers, redirect, testutil |
|---|
| 9 | |
|---|
| 10 | class RedirectRoot(controllers.RootController): |
|---|
| 11 | def index(self): |
|---|
| 12 | raise redirect("foo") |
|---|
| 13 | index = turbogears.expose()(index) |
|---|
| 14 | |
|---|
| 15 | class TestControllers(unittest.TestCase): |
|---|
| 16 | def setUp(self): |
|---|
| 17 | cherrypy.root = None |
|---|
| 18 | cherrypy.tree.mount_points = {} |
|---|
| 19 | cherrypy.tree.mount(RedirectRoot(), "/") |
|---|
| 20 | self.root = cherrypy.root |
|---|
| 21 | |
|---|
| 22 | def tearDown(self): |
|---|
| 23 | cherrypy.root = None |
|---|
| 24 | cherrypy.tree.mount_points = {} |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | def test_index(self): |
|---|
| 28 | "Test that call_with_request is usable if controller uses redirect" |
|---|
| 29 | try: |
|---|
| 30 | testutil.call(self.root.index) |
|---|
| 31 | self.fail("no redirect exception raised") |
|---|
| 32 | except cherrypy.HTTPRedirect, e: |
|---|
| 33 | assert e.status in [302, 303] |
|---|
| 34 | self.assertEquals(1, len(e.urls)) |
|---|
| 35 | assert e.urls[0].endswith("foo") |
|---|
| 36 | |
|---|
| 37 | if __name__ == "__main__": |
|---|
| 38 | unittest.main() |
|---|
Download in other formats: