ENH: Add root endpoint for App Service health checks (#77)
* ✨ Add health check endpoint * ✅ Add test for health check endpoint
This commit is contained in:
Родитель
4c60ba92ac
Коммит
fc5392ada1
|
@ -51,10 +51,10 @@ def assert_response_error_type(response: TestResponse, status_code: HTTP_STATUS_
|
|||
assert response.status_code == status_code.value
|
||||
response_json = response.json
|
||||
|
||||
# this makes mypy happy that a dictionary has actually been returned
|
||||
# this makes mypy happy that a dictionary has actually been returned
|
||||
assert response_json is not None
|
||||
|
||||
assert len(response_json['code']) > 0
|
||||
assert len(response_json['code']) > 0
|
||||
assert len(response_json['detail']) > 0
|
||||
assert response_json['status'] == status_code.value
|
||||
assert len(response_json['title']) > 0
|
||||
|
@ -63,6 +63,14 @@ def assert_response_error_type(response: TestResponse, status_code: HTTP_STATUS_
|
|||
else:
|
||||
assert 'extra_details' not in response_json
|
||||
|
||||
def test_health_check() -> None:
|
||||
"""
|
||||
Test that the health check endpoint returns 200.
|
||||
"""
|
||||
with app.test_client() as client:
|
||||
response = client.get("/")
|
||||
assert response.status_code == HTTP_STATUS_CODE.OK.value
|
||||
|
||||
|
||||
def test_ping_unauthorized() -> None:
|
||||
"""
|
||||
|
|
10
app.py
10
app.py
|
@ -114,6 +114,16 @@ def is_authenticated_request(req: Request) -> Optional[Response]:
|
|||
return None
|
||||
|
||||
|
||||
@inject
|
||||
@app.route("/", methods=['GET'])
|
||||
def health_check() -> Response:
|
||||
"""
|
||||
Health check endpoint.
|
||||
:return: 200 OK.
|
||||
"""
|
||||
return make_response(jsonify({'status': 'Healthy'}), HTTP_STATUS_CODE.OK.value)
|
||||
|
||||
|
||||
@app.route("/v1/ping", methods=['GET'])
|
||||
def ping() -> Response:
|
||||
authentication_response = is_authenticated_request(request)
|
||||
|
|
Загрузка…
Ссылка в новой задаче