Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error handler in simple extension examples #750

Merged
merged 1 commit into from Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/simple/README.md
Expand Up @@ -15,7 +15,7 @@ git clone https://github.com/jupyter/jupyter_server && \
pip install -e .[test]
```

**OPTIONAL** If you want to build the Typescript code, you need [npm](https://www.npmjs.com) on your local environement. Compiled javascript is provided as artifact in this repository, so this Typescript build step is optional. The Typescript source and configuration have been taken from https://github.com/markellekelly/jupyter-server-example.
**OPTIONAL** If you want to build the Typescript code, you need [npm](https://www.npmjs.com) on your local environment. Compiled javascript is provided as artifact in this repository, so this Typescript build step is optional. The Typescript source and configuration have been taken from https://github.com/markellekelly/jupyter-server-example.

```bash
npm install && \
Expand Down Expand Up @@ -88,7 +88,7 @@ The following command starts both the `simple_ext1` and `simple_ext2` extensions
jupyter server --ServerApp.jpserver_extensions="{'simple_ext1': True, 'simple_ext2': True}"
```

Check that the previous `Extension 1` content is still available ant that you can also render `Extension 2` Server content in your browser.
Check that the previous `Extension 1` content is still available and that you can also render `Extension 2` Server content in your browser.

```bash
# HTML static page.
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/simple_ext1/application.py
Expand Up @@ -46,7 +46,7 @@ def initialize_handlers(self):
(r"/{}/template1/(.*)$".format(self.name), TemplateHandler),
(r"/{}/redirect".format(self.name), RedirectHandler),
(r"/{}/typescript/?".format(self.name), TypescriptHandler),
(r"/{}/(.*)", ErrorHandler),
(r"/{}/(.*)".format(self.name), ErrorHandler),
]
)

Expand Down
5 changes: 3 additions & 2 deletions examples/simple/simple_ext1/handlers.py
Expand Up @@ -42,10 +42,11 @@ def get(self):

class TemplateHandler(BaseTemplateHandler):
def get(self, path):
"""Optionaly, you can print(self.get_template('simple1.html'))"""
"""Optionally, you can print(self.get_template('simple1.html'))"""
self.write(self.render_template("simple1.html", path=path))


class ErrorHandler(BaseTemplateHandler):
def get(self, path):
self.write(self.render_template("error.html", path=path))
# write_error renders template from error.html file.
self.write_error(400)
2 changes: 1 addition & 1 deletion examples/simple/simple_ext2/handlers.py
Expand Up @@ -31,4 +31,4 @@ def get(self, path):

class ErrorHandler(BaseTemplateHandler):
def get(self, path):
self.write(self.render_template("error.html"))
self.write_error(400)
15 changes: 13 additions & 2 deletions examples/simple/tests/test_handlers.py
Expand Up @@ -11,10 +11,21 @@ def jp_server_config(jp_template_dir):
async def test_handler_default(jp_fetch):
r = await jp_fetch("simple_ext1/default", method="GET")
assert r.code == 200
print(r.body.decode())
assert r.body.decode().index("Hello Simple 1 - I am the default...") > -1


async def test_handler_template(jp_fetch):
r = await jp_fetch("simple_ext1/template1/test", method="GET")
path = "/custom/path"
r = await jp_fetch("simple_ext1/template1/{}".format(path), method="GET")
assert r.code == 200
assert r.body.decode().index("Path: {}".format(path)) > -1


async def test_handler_typescript(jp_fetch):
r = await jp_fetch("simple_ext1/typescript", method="GET")
assert r.code == 200


async def test_handler_error(jp_fetch):
r = await jp_fetch("simple_ext1/nope", method="GET")
assert r.body.decode().index("400 : Bad Request") > -1