Skip to content

Commit

Permalink
feat: backend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon committed Sep 5, 2023
1 parent a4f6a23 commit 8c74513
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#: The REEV version from the file (``None`` if to load dynamically from git)
REEV_VERSION = None
# Try to obtain version from file, otherwise keep it at ``None``
if os.path.exists(VERSION_FILE):
if os.path.exists(VERSION_FILE): # pragma: no cover
with open(VERSION_FILE) as f:
REEV_VERSION = f.read().strip() or None

Expand Down
43 changes: 43 additions & 0 deletions backend/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import subprocess
import typing

import pytest
Expand Down Expand Up @@ -74,3 +75,45 @@ async def test_invalid_proxy_route(monkeypatch, httpx_mock):
response = client.get("/proxy/some-other-path")
assert response.status_code == 404
assert response.text == "Reverse proxy route not found"


@pytest.mark.asyncio
async def test_version(monkeypatch):
"""Test version endpoint."""
monkeypatch.setattr(main, "REEV_VERSION", "1.2.3")
response = client.get("/version")
assert response.status_code == 200
assert response.text == "1.2.3"


@pytest.mark.asyncio
async def test_version_no_version(monkeypatch):
"""Test version endpoint with no version."""
monkeypatch.setattr(main, "REEV_VERSION", None)
response = client.get("/version")
assert response.status_code == 200
expected = subprocess.check_output(["git", "describe", "--tags", "--dirty"]).strip().decode()
assert response.text == expected


@pytest.mark.asyncio
async def test_variantvalidator(monkeypatch, httpx_mock):
"""Test variant validator endpoint."""
variantvalidator_url = "https://rest.variantvalidator.org/VariantValidator/variantvalidator"
httpx_mock.add_response(
url=f"{variantvalidator_url}/{MOCKED_URL_TOKEN}",
method="GET",
text="Mocked response",
)

response = client.get(f"/variantvalidator/{MOCKED_URL_TOKEN}")
assert response.status_code == 200
assert response.text == "Mocked response"


@pytest.mark.asyncio
async def test_favicon():
"""Test favicon endpoint."""
response = client.get("/favicon.ico")
assert response.status_code == 200
assert response.headers["content-type"] == "image/vnd.microsoft.icon"

0 comments on commit 8c74513

Please sign in to comment.