Example #1
0
    def test_catches_exception(self):
        def view(request):
            raise Exception('Testing')

        middleware = DebugMiddleware.wrap(view)
        response = middleware(None)

        self.assertEqual(response.status_code, 500)
Example #2
0
    def test_errors_when_nothing_is_returned_from_view(self):
        def view(request):
            pass

        middleware = DebugMiddleware.wrap(view)
        response = middleware(None)

        self.assertEqual(response.status_code, 500)
Example #3
0
    def test_catches_Http404(self):
        def view(request):
            raise Http404('Page not found')

        middleware = DebugMiddleware.wrap(view)
        response = middleware(None)

        self.assertEqual(response.status_code, 404)
Example #4
0
def serve(handler, host='localhost', port=8080, debug=True):
    """
    Starts a developent server on the local machine. By default, the
    server runs on port 8080 on localhost. You can pass in a different
    hostname and/or IP using the keyword arguments.
    """

    if debug:
        handler = DebugMiddleware.wrap(handler)

    httpd = WSGIServer((host, port), WSGIRequestHandler)
    httpd.set_app(WSGIHandler(handler))
    print("Development server is running at http://%s:%s/" % (host, port))
    httpd.serve_forever()