Beispiel #1
0
    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"})
Beispiel #2
0
 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)
Beispiel #3
0
    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)
Beispiel #4
0
    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.")
Beispiel #5
0
    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)
Beispiel #6
0
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))
Beispiel #7
0
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)
Beispiel #8
0
 def test_nonprefix_404(self):
     app = App()
     (req, resp) = app.route({'REQUEST_METHOD': 'GET', 'PATH_INFO': '/foo'})
     self.assertTrue(isinstance(resp, exc.HTTPNotFound))
Beispiel #9
0
 def test_prefix_404(self):
     app = App(prefix='/1.0')
     self.assertTrue(isinstance(
             app.route({'REQUEST_METHOD': 'GET', 'PATH_INFO': '/foo'})[1],
             exc.HTTPNotFound))