Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"poutine",
"preds",
"prio",
"pytestmark",
"rebindings",
"recognised",
"refetches",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ def _make_annotation() -> EpisodeAnnotation:
)


@pytest.fixture
def client() -> TestClient:
from src.api.main import app

with TestClient(app) as c:
yield c


@pytest.fixture
def override_services():
from src.api.main import app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
from src.api.models.detection import EpisodeDetectionSummary


@pytest.fixture
def client() -> TestClient:
from src.api.main import app

with TestClient(app) as c:
yield c


@pytest.fixture
def override_services():
from src.api.main import app
Expand Down
38 changes: 4 additions & 34 deletions data-management/viewer/backend/tests/api/test_annotations.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
"""
Integration tests for annotation API endpoints.
"""
"""Integration tests for annotation API endpoints."""

import asyncio
import tempfile
from datetime import UTC, datetime

import pytest
from fastapi.testclient import TestClient

from src.api.main import app
from src.api.models.annotations import (
AnomalyAnnotation,
ConfidenceLevel,
Expand All @@ -27,29 +21,6 @@
from src.api.models.datasources import DatasetInfo, FeatureSchema


@pytest.fixture
def client(monkeypatch):
"""Create test client with isolated singletons and empty temp data path."""
with tempfile.TemporaryDirectory() as tmp:
monkeypatch.setenv("DATA_DIR", tmp)
monkeypatch.setenv("STORAGE_BACKEND", "local")

import src.api.config as config_mod
import src.api.services.annotation_service as ann_mod
import src.api.services.dataset_service as ds_mod

config_mod._app_config = None
ds_mod._dataset_service = None
ann_mod._annotation_service = None

with TestClient(app) as c:
yield c

config_mod._app_config = None
ds_mod._dataset_service = None
ann_mod._annotation_service = None


@pytest.fixture
def sample_dataset():
"""Create a sample dataset for testing."""
Expand All @@ -66,14 +37,13 @@ def sample_dataset():


@pytest.fixture
def registered_dataset(client, sample_dataset):
async def registered_dataset(client, sample_dataset):
"""Register a sample dataset before tests."""
import src.api.services.dataset_service as ds_mod

service = ds_mod.get_dataset_service()
asyncio.run(service.register_dataset(sample_dataset))
yield sample_dataset
service._datasets.clear()
await service.register_dataset(sample_dataset)
return sample_dataset


@pytest.fixture
Expand Down
6 changes: 6 additions & 0 deletions data-management/viewer/backend/tests/api/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def test_valid_csrf_token_passes(self, client_with_auth):


class TestApiKeyProvider:
@pytest.mark.asyncio
async def test_authenticate_valid_key(self):
from unittest.mock import MagicMock

Expand All @@ -211,6 +212,7 @@ async def test_authenticate_valid_key(self):
assert result is not None
assert result["auth_method"] == "apikey"

@pytest.mark.asyncio
async def test_authenticate_wrong_key(self):
from unittest.mock import MagicMock

Expand All @@ -222,6 +224,7 @@ async def test_authenticate_wrong_key(self):
result = await provider.authenticate(request)
assert result is None

@pytest.mark.asyncio
async def test_authenticate_missing_key(self):
from unittest.mock import MagicMock

Expand All @@ -246,6 +249,7 @@ def test_www_authenticate_header(self):


class TestEasyAuthProvider:
@pytest.mark.asyncio
async def test_authenticate_valid_principal(self):
import base64
import json
Expand All @@ -269,6 +273,7 @@ async def test_authenticate_valid_principal(self):
assert result["auth_method"] == "easy_auth"
assert "Dataviewer.Admin" in result["roles"]

@pytest.mark.asyncio
async def test_authenticate_missing_header(self):
from unittest.mock import MagicMock

Expand All @@ -280,6 +285,7 @@ async def test_authenticate_missing_header(self):
result = await provider.authenticate(request)
assert result is None

@pytest.mark.asyncio
async def test_authenticate_invalid_base64(self):
from unittest.mock import MagicMock

Expand Down
40 changes: 4 additions & 36 deletions data-management/viewer/backend/tests/api/test_datasets.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
"""
Integration tests for dataset API endpoints.
"""

import os
import tempfile
"""Integration tests for dataset API endpoints."""

import pytest
from fastapi.testclient import TestClient

from src.api.main import app
from src.api.models.datasources import DatasetInfo, FeatureSchema, TaskInfo


@pytest.fixture
def client():
"""Create test client with isolated singletons and empty temp data path."""
with tempfile.TemporaryDirectory() as tmp:
os.environ["DATA_DIR"] = tmp

import src.api.config as config_mod
import src.api.services.annotation_service as ann_mod
import src.api.services.dataset_service as ds_mod

config_mod._app_config = None
ds_mod._dataset_service = None
ann_mod._annotation_service = None

with TestClient(app) as c:
yield c

config_mod._app_config = None
ds_mod._dataset_service = None
ann_mod._annotation_service = None


@pytest.fixture
def sample_dataset():
"""Create a sample dataset for testing."""
Expand All @@ -54,16 +25,13 @@ def sample_dataset():


@pytest.fixture
def registered_dataset(client, sample_dataset):
async def registered_dataset(client, sample_dataset):
"""Register a sample dataset before tests."""
import asyncio

import src.api.services.dataset_service as ds_mod

service = ds_mod.get_dataset_service()
asyncio.run(service.register_dataset(sample_dataset))
yield sample_dataset
service._datasets.clear()
await service.register_dataset(sample_dataset)
return sample_dataset


class TestDatasetEndpoints:
Expand Down
Loading
Loading