mirror of
https://github.com/bellingcat/auto-archiver-api.git
synced 2026-06-11 21:18:35 +03:00
default endpoints tested
This commit is contained in:
79
src/tests/endpoints/test_default.py
Normal file
79
src/tests/endpoints/test_default.py
Normal file
@@ -0,0 +1,79 @@
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from fastapi.testclient import TestClient
|
||||
from core.config import VERSION
|
||||
|
||||
|
||||
def test_endpoint_home():
|
||||
from main import app
|
||||
client = TestClient(app)
|
||||
|
||||
r = client.get("/")
|
||||
assert r.status_code == 200
|
||||
j = r.json()
|
||||
assert "version" in j and j["version"] == VERSION
|
||||
assert "breakingChanges" in j
|
||||
assert "groups" not in j
|
||||
|
||||
|
||||
@patch("endpoints.default.bearer_security", new_callable=AsyncMock)
|
||||
@patch("endpoints.default.get_user_auth", new_callable=AsyncMock, return_value="test@example.com")
|
||||
@patch("endpoints.default.crud.get_user_groups", return_value=["group1", "group2"])
|
||||
def test_endpoint_home_with_groups(m1, m2, m3):
|
||||
from main import app
|
||||
client = TestClient(app)
|
||||
|
||||
r = client.get("/")
|
||||
assert r.status_code == 200
|
||||
j = r.json()
|
||||
assert "version" in j and j["version"] == VERSION
|
||||
assert "breakingChanges" in j
|
||||
assert "groups" in j
|
||||
assert j["groups"] == ["group1", "group2"]
|
||||
|
||||
|
||||
def test_endpoint_health():
|
||||
from main import app
|
||||
client = TestClient(app)
|
||||
|
||||
r = client.get("/health")
|
||||
assert r.status_code == 200
|
||||
assert r.json() == {"status": "ok"}
|
||||
|
||||
|
||||
def test_endpoint_groups_403():
|
||||
from main import app
|
||||
client = TestClient(app)
|
||||
r = client.get("/groups")
|
||||
assert r.status_code == 403
|
||||
|
||||
|
||||
@patch("endpoints.default.crud.get_user_groups", return_value=["group1", "group2"])
|
||||
def test_endpoint_groups(m1):
|
||||
async def mock_get_user_auth(): return True
|
||||
from main import app
|
||||
from security import get_user_auth
|
||||
app.dependency_overrides[get_user_auth] = mock_get_user_auth
|
||||
|
||||
client = TestClient(app)
|
||||
r = client.get("/groups")
|
||||
|
||||
assert r.status_code == 200
|
||||
j = r.json()
|
||||
assert j == ["group1", "group2"]
|
||||
|
||||
|
||||
def test_no_serve_local_archive_by_default():
|
||||
from main import app
|
||||
client = TestClient(app)
|
||||
|
||||
r = client.get("/app/local_archive_test/temp.txt")
|
||||
assert r.status_code == 404
|
||||
|
||||
|
||||
def test_favicon():
|
||||
from main import app
|
||||
client = TestClient(app)
|
||||
|
||||
r = client.get("/favicon.ico")
|
||||
assert r.status_code == 200
|
||||
assert r.headers["content-type"] == "image/vnd.microsoft.icon"
|
||||
Reference in New Issue
Block a user