Files
snotes/tests/conftest.py

56 lines
1.9 KiB
Python

from __future__ import annotations
import pytest
from httpx import ASGITransport, AsyncClient
@pytest.fixture
def anyio_backend():
return "asyncio"
@pytest.fixture
async def client(tmp_path, monkeypatch):
from backend.config import settings
monkeypatch.setattr(settings, "data_dir", str(tmp_path / "notes"))
monkeypatch.setattr(settings, "database_path", str(tmp_path / "test.db"))
monkeypatch.setattr(settings, "actions_file", str(tmp_path / "actions.toml"))
monkeypatch.setattr(settings, "users", "schmeeve,ilya")
monkeypatch.setattr(settings, "remote_pass", "hunter2")
monkeypatch.setattr(settings, "secret_key", "test-secret")
monkeypatch.setattr(settings, "lan_cidrs", "192.168.1.0/24")
monkeypatch.setattr(settings, "common_space", "common")
from backend import database
from backend.main import app
await database.init_db()
transport = ASGITransport(app=app, client=("192.168.1.5", 12345))
async with AsyncClient(transport=transport, base_url="http://test") as c:
yield c
@pytest.fixture
async def remote_client(tmp_path, monkeypatch):
from backend.config import settings
monkeypatch.setattr(settings, "data_dir", str(tmp_path / "notes"))
monkeypatch.setattr(settings, "database_path", str(tmp_path / "test.db"))
monkeypatch.setattr(settings, "actions_file", str(tmp_path / "actions.toml"))
monkeypatch.setattr(settings, "users", "schmeeve")
monkeypatch.setattr(settings, "remote_pass", "hunter2")
monkeypatch.setattr(settings, "secret_key", "test-secret")
monkeypatch.setattr(settings, "lan_cidrs", "192.168.1.0/24")
monkeypatch.setattr(settings, "common_space", "common")
from backend import database
from backend.main import app
await database.init_db()
transport = ASGITransport(app=app, client=("8.8.8.8", 12345))
async with AsyncClient(transport=transport, base_url="http://test") as c:
yield c