def test_unicode_request(self): """Make sure the request uses Unicode.""" env = {'QUERY_STRING': 'q=ü'} app = App() @app.expose("/foo") def __endpoint__(request): self.assertTrue(isinstance(request.GET, webob.UnicodeMultiDict)) app.route({'REQUEST_METHOD': 'GET', 'PATH_INFO': "/foo"})
def test_success(self): response = Response(body="Hi") app = App() app.expose('/')(lambda request: response) resp = app.route({'REQUEST_METHOD': 'GET', 'PATH_INFO': '/'}) self.assertTrue(resp is response)
def test_exceptions_returned(self): """Make sure non-HTTPExceptions are returned.""" ex = Exception("Test exception") app = App() @app.expose("/foo") def test_f(request): raise ex (req, resp) = app.route({'REQUEST_METHOD': 'GET', 'PATH_INFO': "/foo"}) self.assert_(resp is ex)
def test_multi_expose(self): app = App() @app.expose("/foo") @app.expose("/bar") def endpoint(request): return Response(body="Hi.") (req, resp) = app.route({'REQUEST_METHOD': "GET", 'PATH_INFO': "/foo"}) self.assertTrue(isinstance(resp, Response)) self.assertFalse(isinstance(resp, exc.HTTPError)) self.assertTrue(resp.body == "Hi.")
def test_generates_request(self): """Make sure request objects are generated.""" runs = [] app = App() @app.expose("/foo") def test_f(request): runs.append(True) self.assert_(isinstance(request, Request)) return Response() (req, resp) = app.route({'REQUEST_METHOD': 'GET', 'PATH_INFO': "/foo"}) self.assert_(len(runs) == 1)
class EndpointsTest(unittest.TestCase): """Test dream.endpoints()""" def setUp(self): self.app = App() endpoints(self.app, '/endpoints') def test_endpoints(self): self.assertTrue('GET /endpoints' in self.app.endpoints().keys()) def test_endpoints_reponse(self): self.assertTrue(isinstance( self.app.route({'REQUEST_METHOD': 'GET', 'PATH_INFO': '/endpoints'}), HumanReadableJSONResponse))
class EndpointsTest(unittest.TestCase): """Test dream.endpoints()""" def setUp(self): self.app = App() endpoints(self.app, '/endpoints') def test_endpoints(self): self.assertTrue('GET /endpoints' in self.app.endpoints().keys()) def test_endpoints_reponse(self): (request, response) = self.app.route({'REQUEST_METHOD': 'GET', 'PATH_INFO': '/endpoints'}) self.assertTrue(isinstance(response, HumanReadableJSONResponse)) def test_has_prefix(self): """Make sure endpoint URLs include the prefix.""" prefix = "/foo" app = App(prefix=prefix) endpoints(app, "/endpoints") for endpoint in app.endpoints().iterkeys(): self.assertTrue(prefix in endpoint)
def test_nonprefix_404(self): app = App() (req, resp) = app.route({'REQUEST_METHOD': 'GET', 'PATH_INFO': '/foo'}) self.assertTrue(isinstance(resp, exc.HTTPNotFound))
def test_prefix_404(self): app = App(prefix='/1.0') self.assertTrue(isinstance( app.route({'REQUEST_METHOD': 'GET', 'PATH_INFO': '/foo'})[1], exc.HTTPNotFound))