Beispiel #1
0
class TestBasicWSGI(TestWSGIController):
    def __init__(self, *args, **kargs):
        TestWSGIController.__init__(self, *args, **kargs)
        self.baseenviron = {}
        app = ControllerWrap(BasicWSGIController)
        app = self.sap = SetupCacheGlobal(app, self.baseenviron)
        app = RegistryManager(app)
        self.app = TestApp(app)
        
    def setUp(self):
        TestWSGIController.setUp(self)
        self.baseenviron.update(self.environ)

    def test_wsgi_call(self):
        resp = self.get_response()
        assert 'hello world' in resp
    
    def test_yield_wrapper(self):
        resp = self.get_response(action='yield_fun')
        assert 'hi' * 100 in resp

    def test_404(self):
        self.environ['paste.config']['global_conf']['debug'] = False
        self.environ['pylons.routes_dict']['action'] = 'notthere'
        resp = self.app.get('/', status=404)
        assert resp.status == 404
    
    def test_private_func(self):
        self.baseenviron['pylons.routes_dict']['action'] = '_private'
        resp = self.app.get('/', status=404)
        assert resp.status == 404
    
    def test_strme_func(self):
        self.baseenviron['pylons.routes_dict']['action'] = 'strme'
        resp = self.app.get('/')
        assert "hi there" in resp
    
    def test_header_check(self):
        self.baseenviron['pylons.routes_dict']['action'] = 'header_check'
        resp = self.app.get('/')
        assert "Hello all!" in resp
        assert resp.response.headers['Content-Type'] == 'text/plain'
        assert resp.response.headers['Cache-Control'] == 'private'
        assert resp.header('Content-Type') == 'text/plain'
    
    def test_head(self):
        self.baseenviron['pylons.routes_dict']['action'] = 'header_check'
        resp = self.app._gen_request('HEAD', '/')
        assert '' == resp.body
        assert resp.header('Content-Type') == 'text/plain'

    def test_redirect(self):
        self.baseenviron['pylons.routes_dict']['action'] = 'use_redirect'
        resp = self.app.get('/', status=301)

    def test_nothing(self):
        self.baseenviron['pylons.routes_dict']['action'] = 'nothing'
        resp = self.app.get('/')
        assert '' == resp.body
        assert resp.response.headers['Cache-Control'] == 'private'

    def test_unicode_action(self):
        self.baseenviron['pylons.routes_dict']['action'] = u'ОбсуждениеКомпаний'
        resp = self.app.get('/', status=404)

    def test_params(self):
        self.baseenviron['pylons.routes_dict']['action'] = u'params'
        resp = self.app.get('/?foo=bar')
        assert "[('foo', u'bar')]" in resp, str(resp)
        resp = self.app.post('/?foo=bar', params=dict(snafu='snafoo'))
        assert "[('foo', u'bar'), ('snafu', u'snafoo')]" in resp, str(resp)
        resp = self.app.put('/?foo=bar', params=dict(snafu='snafoo'))
        assert "[('foo', u'bar'), ('snafu', u'snafoo')]" in resp, str(resp)

    def test_list(self):
        self.baseenviron['pylons.routes_dict']['action'] = 'list'
        assert 'from a list' in self.app.get('/')
Beispiel #2
0
class TestBasicWSGI(TestWSGIController):
    def __init__(self, *args, **kargs):
        TestWSGIController.__init__(self, *args, **kargs)
        self.baseenviron = {}
        app = ControllerWrap(BasicWSGIController)
        app = self.sap = SetupCacheGlobal(app, self.baseenviron)
        app = TestMiddleware(app)
        app = RegistryManager(app)
        self.app = TestApp(app)
        
    def setUp(self):
        TestWSGIController.setUp(self)
        self.baseenviron.update(self.environ)

    def test_wsgi_call(self):
        resp = self.get_response()
        assert 'hello world' in resp
    
    def test_yield_wrapper(self):
        resp = self.get_response(action='yield_fun')
        assert 'hi' * 100 in resp

    def test_404(self):
        self.environ['paste.config']['global_conf']['debug'] = False
        self.environ['pylons.routes_dict']['action'] = 'notthere'
        resp = self.app.get('/', status=404)
        assert resp.status == 404
    
    def test_404exception(self):
        self.environ['paste.config']['global_conf']['debug'] = False
        self.environ['pylons.routes_dict']['action'] = 'use_customnotfound'
        resp = self.app.get('/', status=404)
        assert 'pylons.controller.exception' in resp.environ
        exc = resp.environ['pylons.controller.exception']
        assert exc.detail == 'Custom not found'
        assert resp.status == 404
    
    def test_private_func(self):
        self.baseenviron['pylons.routes_dict']['action'] = '_private'
        resp = self.app.get('/', status=404)
        assert resp.status == 404
    
    def test_strme_func(self):
        self.baseenviron['pylons.routes_dict']['action'] = 'strme'
        resp = self.app.get('/')
        assert "hi there" in resp
    
    def test_header_check(self):
        self.baseenviron['pylons.routes_dict']['action'] = 'header_check'
        resp = self.app.get('/')
        assert "Hello all!" in resp
        assert resp.response.headers['Content-Type'] == 'text/plain'
        assert resp.response.headers['Cache-Control'] == 'private'
        assert resp.header('Content-Type') == 'text/plain'
    
    def test_head(self):
        self.baseenviron['pylons.routes_dict']['action'] = 'header_check'
        resp = self.app._gen_request('HEAD', '/')
        assert '' == resp.body
        assert resp.header('Content-Type') == 'text/plain'

    def test_redirect(self):
        self.baseenviron['pylons.routes_dict']['action'] = 'use_redirect'
        resp = self.app.get('/', status=301)

    def test_nothing(self):
        self.baseenviron['pylons.routes_dict']['action'] = 'nothing'
        resp = self.app.get('/')
        assert '' == resp.body
        assert resp.response.headers['Cache-Control'] == 'private'

    def test_unicode_action(self):
        self.baseenviron['pylons.routes_dict']['action'] = u'ОбсуждениеКомпаний'
        resp = self.app.get('/', status=404)

    def test_params(self):
        self.baseenviron['pylons.routes_dict']['action'] = u'params'
        resp = self.app.get('/?foo=bar')
        assert "'foo', u'bar')]" in resp, str(resp)
        resp = self.app.post('/?foo=bar', params=dict(snafu='snafoo'))
        assert "'foo', u'bar')" in resp, str(resp)
        assert "'snafu', u'snafoo')]" in resp, str(resp)
        resp = self.app.put('/?foo=bar', params=dict(snafu='snafoo'))
        assert "'foo', u'bar')" in resp, str(resp)
        assert "'snafu', u'snafoo')]" in resp, str(resp)

    def test_list(self):
        self.baseenviron['pylons.routes_dict']['action'] = 'list'
        assert 'from a list' in self.app.get('/')