Skip to content

Commit

Permalink
Update Unit Tests (#4)
Browse files Browse the repository at this point in the history
* Enhance time retrieval tests with parameterization and regex validation

* Disable JSON Prettier validation in Super Linter workflow configuration
  • Loading branch information
Vianpyro authored Nov 12, 2024
1 parent 6a7cbf3 commit 6c8d44c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ jobs:
# To report GitHub Actions status checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_ALL_CODEBASE: false
VALIDATE_JSON_PRETTIER: false
VALIDATE_PYTHON_PYLINT: false
VALIDATE_PYTHON_ISORT: false
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@
"isort.args": [
"--profile",
"black"
]
],
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
18 changes: 15 additions & 3 deletions tests/test_get_time.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
import re
from unittest.mock import patch

import pytest

Expand All @@ -10,7 +11,18 @@ def client():
return app.test_client()


def test_get_time(client):
@pytest.mark.parametrize(
"fixed_time", ["12:34:56 01/01/2024", "23:59:59 31/12/2023", "00:00:00 01/01/2025"]
)
def test_get_time(client, fixed_time):
with patch("time.strftime", return_value=fixed_time):
response = client.get("/time")
assert response.status_code == 200
assert response.json == {"server_time": fixed_time}


def test_time_format(client):
response = client.get("/time")
assert response.status_code == 200
assert response.json == {"server_time": time.strftime("%H:%M:%S %d/%m/%Y")}
time_str = response.json.get("server_time")
assert re.match(r"\d{2}:\d{2}:\d{2} \d{2}/\d{2}/\d{4}", time_str)

0 comments on commit 6c8d44c

Please sign in to comment.