generated from ssec-jhu/base-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Iainland/healthz html response (#158)
init `/html` route.
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import socket | ||
|
||
from fastapi import FastAPI | ||
from fastapi.responses import HTMLResponse | ||
|
||
from evolver import __project__, __version__ | ||
|
||
html_app = FastAPI() | ||
|
||
|
||
@html_app.get("/network", operation_id="network_state_html", response_class=HTMLResponse) | ||
async def network_html(): | ||
hostname = socket.gethostname() | ||
ip_address = socket.gethostbyname(hostname) | ||
html_content = f""" | ||
<html> | ||
<head> | ||
<title>Evolver</title> | ||
</head> | ||
<body> | ||
<h1>device network details</h1> | ||
<p>Running '{__project__}' ver: '{__version__}'</p> | ||
<p>Hostname: {hostname}</p> | ||
<p>IP Address: {ip_address}</p> | ||
</body> | ||
</html> | ||
""" | ||
return html_content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from evolver import __version__ | ||
|
||
|
||
class TestHtmlApp: | ||
def test_html_network(self, app_client): | ||
response = app_client.get("/html/network") | ||
assert response.status_code == 200 | ||
assert response.headers["content-type"] == "text/html; charset=utf-8" | ||
|
||
html_content = response.text | ||
assert "<html>" in html_content | ||
assert "<title>Evolver</title>" in html_content | ||
if __version__: | ||
assert __version__ in html_content | ||
assert "device network details" in html_content | ||
assert "Hostname:" in html_content | ||
assert "IP Address:" in html_content |