Skip to content

Commit 3eaea4b

Browse files
authored
Merge pull request #750 from andreyvelich/fix-simple-examples
Fix error handler in simple extension examples
2 parents 3864399 + ef2eb3d commit 3eaea4b

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

examples/simple/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ git clone https://github.com/jupyter/jupyter_server && \
1515
pip install -e .[test]
1616
```
1717

18-
**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.
18+
**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.
1919

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

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

9393
```bash
9494
# HTML static page.

examples/simple/simple_ext1/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def initialize_handlers(self):
4646
(r"/{}/template1/(.*)$".format(self.name), TemplateHandler),
4747
(r"/{}/redirect".format(self.name), RedirectHandler),
4848
(r"/{}/typescript/?".format(self.name), TypescriptHandler),
49-
(r"/{}/(.*)", ErrorHandler),
49+
(r"/{}/(.*)".format(self.name), ErrorHandler),
5050
]
5151
)
5252

examples/simple/simple_ext1/handlers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ def get(self):
4242

4343
class TemplateHandler(BaseTemplateHandler):
4444
def get(self, path):
45-
"""Optionaly, you can print(self.get_template('simple1.html'))"""
45+
"""Optionally, you can print(self.get_template('simple1.html'))"""
4646
self.write(self.render_template("simple1.html", path=path))
4747

4848

4949
class ErrorHandler(BaseTemplateHandler):
5050
def get(self, path):
51-
self.write(self.render_template("error.html", path=path))
51+
# write_error renders template from error.html file.
52+
self.write_error(400)

examples/simple/simple_ext2/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ def get(self, path):
3131

3232
class ErrorHandler(BaseTemplateHandler):
3333
def get(self, path):
34-
self.write(self.render_template("error.html"))
34+
self.write_error(400)

examples/simple/tests/test_handlers.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,21 @@ def jp_server_config(jp_template_dir):
1111
async def test_handler_default(jp_fetch):
1212
r = await jp_fetch("simple_ext1/default", method="GET")
1313
assert r.code == 200
14-
print(r.body.decode())
1514
assert r.body.decode().index("Hello Simple 1 - I am the default...") > -1
1615

1716

1817
async def test_handler_template(jp_fetch):
19-
r = await jp_fetch("simple_ext1/template1/test", method="GET")
18+
path = "/custom/path"
19+
r = await jp_fetch("simple_ext1/template1/{}".format(path), method="GET")
2020
assert r.code == 200
21+
assert r.body.decode().index("Path: {}".format(path)) > -1
22+
23+
24+
async def test_handler_typescript(jp_fetch):
25+
r = await jp_fetch("simple_ext1/typescript", method="GET")
26+
assert r.code == 200
27+
28+
29+
async def test_handler_error(jp_fetch):
30+
r = await jp_fetch("simple_ext1/nope", method="GET")
31+
assert r.body.decode().index("400 : Bad Request") > -1

0 commit comments

Comments
 (0)