Beispiel #1
0
 def test_simplest_app(self):
 
     app = App()
 
     @app.route(None)
     def do_render(request):
         return app.Response('hello')
 
     client = app.test_client()
     res = client.get('/')
 
     self.assertEqual(res.status_code, 200)
     self.assertEqual(res.mimetype, 'text/html')
     self.assertEqual(res.data, 'hello')
Beispiel #2
0
 def test_simplest_cookie_app(self):
 
     app = App(test.app_config)
 
     @app.route('/set')
     def do_set(request):
         res = app.Response('cookies set')
         res.set_cookie('key', 'value')
         return res
 
     @app.route('/get')
     def do_get(request):
         return app.Response(request.cookies.get('key', 'no value'))
 
     client = app.test_client()
     
     res = client.get('/set')
     self.assertEqual(res.data, 'cookies set')
     
     res = client.get('/get')
     self.assertEqual(res.data, 'value')
Beispiel #3
0
 def test_args_dispatching(self):
 
     app = App()
 
     @app.route('/wsgi')
     def do_wsgi(environ, start):
         assert isinstance(environ, dict)
         start('200 OK', [])
         return ['wsgi']
     
     @app.route('/request')
     def do_request(request):
         assert isinstance(request, Request)
         return Response('request')
     
     @app.route('/none')
     def do_none():
         return 'none'
     
     client = app.test_client()
     self.assertEqual(client.get('/wsgi').data, 'wsgi')
     self.assertEqual(client.get('/request').data, 'request')
     self.assertEqual(client.get('/none').data, 'none')