Skip to content

Commit e4a1df8

Browse files
committed
Register /health with the route table and test the howto URL
Declare the health route with the module's RouteTableDef like the other handlers, use APP_PROTOCOL for the howto link so local http runs work, and assert the howto page renders APP_URL instead of the old Heroku host.
1 parent 931847c commit e4a1df8

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎blurb_it/__main__.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ async def handle_install(request: Request) -> Response:
6464
return response
6565

6666

67+
@routes.get("/health", name="health")
68+
async def health_check(request: Request) -> Response:
69+
"""Health check endpoint for container orchestration."""
70+
return web.Response(status=200, text="OK")
71+
72+
6773
@routes.get("/add_blurb", name="add_blurb")
6874
async def handle_add_blurb_get(request: Request) -> Response:
6975
"""Render a page with a textbox and submit button."""
@@ -127,11 +133,6 @@ async def handle_add_blurb_get(request: Request) -> Response:
127133
return response
128134

129135

130-
async def health_check(request: Request) -> Response:
131-
"""Health check endpoint for container orchestration."""
132-
return web.Response(status=200, text="OK")
133-
134-
135136
def get_access_token(token_str: str) -> str | None:
136137
for token in token_str.split("&"):
137138
token_split = token.split("=")
@@ -243,7 +244,6 @@ async def handle_add_blurb_post(request: Request) -> Response:
243244
)
244245
app["static_root_url"] = os.path.join(os.getcwd(), "static")
245246
app.router.add_routes(routes)
246-
app.router.add_get("/health", health_check)
247247
app.add_routes([web.static("/static", os.path.join(os.getcwd(), "static"))])
248248

249249
if os.path.isdir("/var/run/cabotage"):

‎templates/howto.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="py-3 mx-auto justify-content-center">
55
<p>As part of CPython’s workflow, any non-trivial change to the codebase requires an accompanying Misc/News.d file in the pull request.</p>
66
<p>So far, the way you would add the news entry is by using blurb command line tool, that can be installed using PyPI.</p>
7-
<p>But now, we’re going to defy the Zen of Python’s “there should be only one way to do it”, and present you with another way to do it: <strong>blurb-it</strong>. <a href="https://{{ app_url }}/">https://{{ app_url }}/</a></p>
7+
<p>But now, we’re going to defy the Zen of Python’s “there should be only one way to do it”, and present you with another way to do it: <strong>blurb-it</strong>. <a href="{{ app_protocol }}://{{ app_url }}/">{{ app_protocol }}://{{ app_url }}/</a></p>
88
<p>blurb-it provides a web interface for you to create news entry to your own CPython pull request. That means, you can do this from your phone, as long as you have a webbrowser and connected to the internet.</p>
99
<p>blurb-it is a <a href="https://github.com/apps/blurb-it">GitHub App</a> owned by The PSF. You’ll need to <a href="/install"><strong>install it</strong></a> and <strong>give write permission</strong> to your own fork’s cpython repo (so it can create the news file). Since <strong>the app will have write access to the repo</strong>, you should not install this on any other repo.</p>
1010
<p>Please give this a try and let me know of any issues by filing a bug in the <a href="https://github.com/python/blurb_it">blurb-it repo</a>.</p>

‎tests/test_main.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ async def test_handle_get(aiohttp_client) -> None:
5858
assert "Sign in with GitHub" in text
5959

6060

61-
async def test_handle_howto_get(aiohttp_client) -> None:
61+
async def test_handle_howto_get(aiohttp_client, monkeypatch) -> None:
6262
# Arrange
63+
monkeypatch.setenv("APP_URL", "blurb-it.example.org")
64+
monkeypatch.delenv("APP_PROTOCOL", raising=False)
6365
app = create_app()
6466

6567
# Act
@@ -72,6 +74,8 @@ async def test_handle_howto_get(aiohttp_client) -> None:
7274
text = await resp.text()
7375
assert "<title>📜🤖 Blurb It!</title>" in text
7476
assert "As part of CPython’s workflow" in text
77+
assert "https://blurb-it.example.org/" in text
78+
assert "herokuapp" not in text
7579

7680

7781
async def test_handle_install(aiohttp_client) -> None:

0 commit comments

Comments
 (0)