class TestRedirection(unittest.TestCase): def setUp(self): self.mapper = Mapper() self.mapper.resource('thing', 'things') def _get_controller_for_request(self, path='/things/x', **kwargs): request = Request.blank(path, **kwargs) request.script_name = '/script' pylons.request._push_object(request) pylons.url._push_object(URLGenerator(self.mapper, request.environ)) pylons.tmpl_context._push_object(TmplContext()) controller = Controller() controller.controller = 'things' controller.format = 'json' return controller def test_redirect(self): controller = self._get_controller_for_request() url_args = dict(action='show', id='x') try: controller._do_redirect(url_args) except HTTPSeeOther as e: assert e.location == '/script/things/x.json' def test_xhr(self): controller = self._get_controller_for_request() url_args = dict(action='show', id='x') try: controller._do_redirect(url_args) except HTTPSeeOther as e: assert e.location == '/script/things/x.json' def test_xhr_with_client_request_url(self): controller = self._get_controller_for_request(headers={ 'X-Requested-With': 'XMLHttpRequest', 'X-Restler-Client-Request-URL': 'http://tntest.trimet.org/script', }) url_args = dict(action='show', id='x') try: controller._do_redirect(url_args) except HTTPSeeOther as e: assert e.location == 'http://tntest.trimet.org/script/things/x.json'
name = os.path.abspath(os.path.join(os.path.dirname(__file__))) name = os.path.join(name, "controllers") map = Mapper(directory=name) map.connect('/', controller = 'index') map.connect('/recent_views', controller = 'index', action = 'recent_views') map.connect('/progress_box', controller = 'index', action = 'progress_box') map.connect('/fans_today', controller = 'index', action = 'fans_today') map.connect('/sold_and_featured_today', controller = 'index', action = 'sold_and_featured_today') map.connect('/shop/:(id)', controller = 'index', action = 'switch_shop') map.connect('goods/statistics', controller = 'goods', action = 'statistics') map.connect('goods/active', controller = 'goods', action = 'active') map.connect('goods/:(key)/edit', controller = 'goods', action = 'edit') map.resource('goods', 'goods') map.connect('expenses/active', controller = 'expenses', action = 'active') map.connect('expenses/balance', controller = 'expenses', action = 'balance') map.connect('expenses/:(key)/edit', controller = 'expenses', action = 'edit') map.resource('expenses', 'expenses') map.resource('fans', 'fans') map.connect('fans/:(key)/:(action)', controller = 'fans') map.connect(':controller/:action') class WSGIApplication(webapp.WSGIApplication): """Wraps a set of webapp RequestHandlers in a WSGI-compatible application.