CI / lint (push) Skipped
CI / test (3.12) (push) Skipped
CI / test (3.13) (push) Skipped
58 lines
1.3 KiB
Python
58 lines
1.3 KiB
Python
import os
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
# Ensure safe defaults during tests
|
|
os.environ.setdefault("BEAMLINE", "SIMULATED")
|
|
os.environ.setdefault("JWT_AAREDAQ_KEY", "test_key_for_unit_testing")
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_logger():
|
|
return MagicMock()
|
|
|
|
|
|
# -------------------------
|
|
# Shared auth server fixtures
|
|
# -------------------------
|
|
@pytest.fixture(scope="session")
|
|
def server_module():
|
|
from aare.daq import server
|
|
|
|
return server
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_aaredb():
|
|
db = MagicMock()
|
|
db.find_loaded_sample.return_value = None
|
|
db.get_sample_info.return_value = None
|
|
return db
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_samples():
|
|
store = MagicMock()
|
|
store.find_sample.return_value = None
|
|
return store
|
|
|
|
|
|
@pytest.fixture
|
|
def auth_token_data():
|
|
from aare.daq.auth import TokenData
|
|
|
|
return TokenData(sub="testuser", staff=True, pgroups=["p12345"], session=123)
|
|
|
|
|
|
@pytest.fixture
|
|
def client(server_module, mock_aaredb, mock_samples, auth_token_data):
|
|
with (
|
|
patch("aare.daq.auth.parse_token", return_value=auth_token_data),
|
|
patch.object(server_module, "AareWrapper", return_value=mock_aaredb),
|
|
patch.object(server_module, "DummySampleStore", return_value=mock_samples),
|
|
TestClient(server_module.app) as c,
|
|
):
|
|
yield c
|