This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
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.
refactor: change ping endponint to use LivenessHealthBackend
- Loading branch information
1 parent
ff094bf
commit d9c7471
Showing
8 changed files
with
68 additions
and
17 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
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
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,15 @@ | ||
# SPDX-FileCopyrightText: 2024-present OLIST TINY TECNOLOGIA LTDA | ||
# | ||
# SPDX-License-Identifier: MIT | ||
from dataclasses import asdict | ||
from http import HTTPStatus | ||
|
||
from django.http import JsonResponse | ||
|
||
from .backends import Health, HealthStatus | ||
|
||
|
||
class HealthResponse(JsonResponse): | ||
def __init__(self, health: Health): | ||
status = HTTPStatus.OK if health.status == HealthStatus.UP else HTTPStatus.INTERNAL_SERVER_ERROR | ||
super().__init__(data=asdict(health), status=status) |
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
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,24 @@ | ||
# SPDX-FileCopyrightText: 2024-present OLIST TINY TECNOLOGIA LTDA | ||
# | ||
# SPDX-License-Identifier: MIT | ||
import json | ||
from http import HTTPStatus | ||
|
||
from healthy.backends import Health | ||
from healthy.responses import HealthResponse | ||
|
||
|
||
class TestHealthResponse: | ||
def test_with_up_health(self): | ||
health = Health.up({"message": "It's fine"}) | ||
response = HealthResponse(health) | ||
|
||
assert response.status_code == HTTPStatus.OK | ||
assert json.loads(response.content) == {"status": "up", "details": {"message": "It's fine"}} | ||
|
||
def test_with_down_health(self): | ||
health = Health.down({"message": "Something went wrong"}) | ||
response = HealthResponse(health) | ||
|
||
assert response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR | ||
assert json.loads(response.content) == {"status": "down", "details": {"message": "Something went wrong"}} |