def test_composition(self): app = self._echo_app app = path_prefix.PathPrefixMiddleware(app, "/bar") app = path_prefix.PathPrefixMiddleware(app, "/foo") server = werkzeug_test.Client(app, werkzeug.wrappers.BaseResponse) response = server.get("/foo/bar/baz/quux") self._assert_ok(response, path="/baz/quux", script="/foo/bar")
def _create_wsgi_app(self): """Apply middleware to create the final WSGI app.""" app = self._route_request app = empty_path_redirect.EmptyPathRedirectMiddleware(app) app = experiment_id.ExperimentIdMiddleware(app) app = path_prefix.PathPrefixMiddleware(app, self._path_prefix) app = _handling_errors(app) return app
def _create_wsgi_app(self): """Apply middleware to create the final WSGI app.""" app = self._route_request app = _auth_context_middleware(app, self._auth_providers) app = empty_path_redirect.EmptyPathRedirectMiddleware(app) app = experiment_id.ExperimentIdMiddleware(app) app = path_prefix.PathPrefixMiddleware(app, self._path_prefix) app = security_validator.SecurityValidatorMiddleware(app) app = _handling_errors(app) return app
def test_empty_path_prefix(self): app = path_prefix.PathPrefixMiddleware(self._echo_app, "") server = werkzeug_test.Client(app, werkzeug.wrappers.BaseResponse) with self.subTest("at empty"): self._assert_ok(server.get(""), path="", script="") with self.subTest("at root"): self._assert_ok(server.get("/"), path="/", script="") with self.subTest("at subpath"): response = server.get("/foo/bar") self._assert_ok(server.get("/foo/bar"), path="/foo/bar", script="")
def test_nonempty_path_prefix(self): app = path_prefix.PathPrefixMiddleware(self._echo_app, "/pfx") server = werkzeug_test.Client(app, werkzeug.wrappers.BaseResponse) with self.subTest("at root"): response = server.get("/pfx") self._assert_ok(response, path="", script="/pfx") with self.subTest("at root with slash"): response = server.get("/pfx/") self._assert_ok(response, path="/", script="/pfx") with self.subTest("at subpath"): response = server.get("/pfx/foo/bar") self._assert_ok(response, path="/foo/bar", script="/pfx") with self.subTest("at non-path-component extension"): with self.assertRaises(errors.NotFoundError): server.get("/pfxz") with self.subTest("above path prefix"): with self.assertRaises(errors.NotFoundError): server.get("/hmm")
def test_bad_path_prefix_with_trailing_slash(self): with self.assertRaises(ValueError) as cm: path_prefix.PathPrefixMiddleware(self._echo_app, "/hmm/") msg = str(cm.exception) self.assertIn("must not end with slash", msg) self.assertIn(repr("/hmm/"), msg)
def test_bad_path_prefix_without_leading_slash(self): with self.assertRaises(ValueError) as cm: path_prefix.PathPrefixMiddleware(self._echo_app, "hmm") msg = str(cm.exception) self.assertIn("must start with slash", msg) self.assertIn(repr("hmm"), msg)