-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: lindenmckenzie <[email protected]>
- Loading branch information
1 parent
a9ad5e1
commit 63825f4
Showing
6 changed files
with
94 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
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,52 @@ | ||
import sys | ||
from datetime import datetime, timedelta | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from app import __version__ as VERSION | ||
from app.settings import BUILD_TIME, GIT_COMMIT | ||
from app.healthcheck import Healthcheck, OK | ||
|
||
start_time = datetime.now() | ||
|
||
|
||
@pytest.fixture | ||
def healthcheck(): | ||
checks = {"check1": OK, "check2": OK} | ||
return Healthcheck(OK, checks, start_time) | ||
|
||
|
||
@patch("app.healthcheck.datetime") | ||
def test_to_json(mock_datetime, healthcheck): | ||
formatted_build_time = datetime.fromtimestamp(int(BUILD_TIME)) | ||
build_time = formatted_build_time.strftime('%Y-%m-%dT%H:%M:%S%z') | ||
|
||
expected_json = { | ||
"status": OK, | ||
"version": { | ||
"version": VERSION, | ||
"build_time": build_time, | ||
"git_commit": GIT_COMMIT, | ||
"language": "python", | ||
"language_version": sys.version, | ||
}, | ||
"uptime": 1, | ||
"start_time": start_time.strftime('%Y-%m-%dT%H:%M:%S%z'), | ||
"checks": {"check1": OK, "check2": OK}, | ||
} | ||
|
||
result = healthcheck.to_json() | ||
print ("this is: ", result) | ||
print ("this is: ", expected_json) | ||
|
||
assert result == expected_json | ||
|
||
|
||
@patch("app.healthcheck.datetime") | ||
def test_get_uptime(mock_datetime, healthcheck): | ||
mock_datetime.now.return_value = healthcheck.start_time + timedelta(milliseconds=500) | ||
|
||
result = healthcheck.get_uptime() | ||
|
||
assert result == 500 |
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 @@ | ||
import time | ||
from dynaconf import Dynaconf | ||
from unittest.mock import patch | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def mock_settings(): | ||
with patch("app.settings.settings") as mock_settings: | ||
mock_settings.HOST = "mock_host" | ||
mock_settings.PORT = 8080 | ||
mock_settings.NAMESPACE = "mock_namespace" | ||
mock_settings.DATA_LOCATION = "/path/to/data" | ||
mock_settings.BUILD_TIME = 1234567890 | ||
mock_settings.GIT_COMMIT = "mock_commit" | ||
yield mock_settings | ||
|
||
def test_settings(mock_settings): | ||
assert mock_settings.HOST == "mock_host" | ||
assert mock_settings.PORT == 8080 | ||
assert mock_settings.NAMESPACE == "mock_namespace" | ||
assert mock_settings.DATA_LOCATION == "/path/to/data" | ||
assert mock_settings.BUILD_TIME == 1234567890 | ||
assert mock_settings.GIT_COMMIT == "mock_commit" |