Skip to content
Merged
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
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,34 @@ jobs:
flags: unittests
name: codecov-umbrella

integration:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "latest"

- name: Set up Python 3.12
run: uv python install 3.12

- name: Install dependencies
run: uv sync --dev

- name: Pull Readeck image
run: docker compose -p readeck-python-itest -f tests/integration/compose.yaml pull

- name: Run integration tests
run: uv run pytest tests/integration -v

- name: Tear down leftover Compose stack
if: always()
run: |
docker compose -p readeck-python-itest -f tests/integration/compose.yaml down -v --remove-orphans --timeout 10 || true

build:
runs-on: ubuntu-latest
needs: test
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.3.1] - 2026-09-12

### Added
- Docker Compose integration tests against a live Readeck instance.

### Changed
- Default `pytest` runs skip integration tests unless they are selected
explicitly with `-m integration` or by targeting `tests/integration`.
- Integration-only pytest runs disable coverage so the 80% unit-test gate
does not fail a live Docker session.
- Accept user profiles that omit `reader_settings`, matching live Readeck
responses for newly created users.

## [0.3.0] - 2026-09-12

### Added
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ uv sync --dev
# Run tests
uv run pytest

# Run integration tests (requires Docker)
uv run pytest tests/integration

# Run linting and formatting
uv run ruff check src tests --fix
uv run ruff format src tests
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ python_classes = ["Test*"]
python_functions = ["test_*"]
asyncio_default_fixture_loop_scope = "function"
asyncio_mode = "auto"
markers = [
"integration: live Readeck tests via Docker Compose",
]
addopts = [
"--cov=src/readeck",
"--cov-report=term-missing",
Expand Down
2 changes: 1 addition & 1 deletion src/readeck/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Readeck's bookmark and reading features.
"""

__version__ = "0.3.0"
__version__ = "0.3.1"
__author__ = "Yash Vanzara"
__email__ = "yashvanzara@gmail.com"

Expand Down
4 changes: 3 additions & 1 deletion src/readeck/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class UserSettings(BaseModel):
"""User settings and preferences."""

debug_info: bool = Field(..., description="Enable debug information")
reader_settings: ReaderSettings = Field(..., description="Reader configuration")
reader_settings: ReaderSettings | None = Field(
default=None, description="Reader configuration"
)
lang: str = Field(default="en-US", description="Language setting")
addon_reminder: bool = Field(default=True, description="Show addon reminders")
email_settings: EmailSettings = Field(
Expand Down
27 changes: 27 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
"""Test fixtures and utilities."""

from collections.abc import AsyncGenerator
from pathlib import Path
from typing import Any

import pytest

from readeck import ReadeckClient


def pytest_configure(config: pytest.Config) -> None:
"""Do not apply the unit-test coverage gate to live integration runs."""
markexpr = (config.option.markexpr or "").strip()
args = [str(arg) for arg in config.args]
integration_only = "integration" in markexpr or (
bool(args) and all("integration" in arg for arg in args)
)
if not integration_only:
return
cov = config.pluginmanager.getplugin("_cov")
if cov is not None:
config.pluginmanager.unregister(cov)


def pytest_ignore_collect(collection_path: Path, config: pytest.Config) -> bool | None:
"""Skip the live Docker suite unless it was requested explicitly."""
if "integration" not in Path(collection_path).parts:
return None
markexpr = (config.option.markexpr or "").strip()
if "integration" in markexpr:
return False
if any("integration" in str(arg) for arg in config.args):
return False
return True


@pytest.fixture
def mock_user_profile_data() -> dict[str, Any]:
"""Mock user profile response data."""
Expand Down
1 change: 1 addition & 0 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Live integration tests against a Dockerized Readeck instance."""
20 changes: 20 additions & 0 deletions tests/integration/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
app:
image: codeberg.org/readeck/readeck:0.23.2
ports:
- "18765:8000"
environment:
READECK_LOG_LEVEL: info
READECK_SERVER_HOST: "0.0.0.0"
READECK_SERVER_PORT: 8000
READECK_LOG_FORMAT: text
volumes:
- ${READECK_ITEST_DATA:-/tmp/readeck-python-itest}:/readeck
security_opt:
- no-new-privileges
healthcheck:
test: ["CMD", "/bin/readeck", "healthcheck", "-config", "config.toml"]
interval: 2s
timeout: 2s
retries: 30
start_period: 10s
124 changes: 124 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
"""Session fixtures for Dockerized Readeck integration tests."""

from __future__ import annotations

import atexit
import tempfile
from collections.abc import AsyncGenerator, Generator
from pathlib import Path

import pytest

from readeck import ReadeckClient, ReadeckError, ReadeckOAuthClient

from .helpers import (
BASE_URL,
COMPOSE_FILE,
TEST_PASSWORD,
TEST_USERNAME,
ReadeckCredentials,
ReadeckStack,
compose,
compose_down,
create_api_token,
create_test_user,
docker_available,
remove_data_dir,
wait_for_http,
)

_ACTIVE_DATA_DIR: Path | None = None


def _atexit_teardown() -> None:
if _ACTIVE_DATA_DIR is None:
return
compose_down(_ACTIVE_DATA_DIR)
remove_data_dir(_ACTIVE_DATA_DIR)


atexit.register(_atexit_teardown)


@pytest.fixture(scope="session")
def readeck_stack() -> Generator[ReadeckStack, None, None]:
"""Start Readeck, always tearing down leftover or current Compose state."""
global _ACTIVE_DATA_DIR

if not docker_available():
pytest.skip("Docker daemon is not available")
if not COMPOSE_FILE.exists():
pytest.fail(f"Compose file is missing: {COMPOSE_FILE}")

data_dir = Path(tempfile.mkdtemp(prefix="readeck-python-itest-"))
data_dir.mkdir(parents=True, exist_ok=True)
_ACTIVE_DATA_DIR = data_dir

compose_down(data_dir)
try:
started = compose(
["up", "-d", "--wait", "--wait-timeout", "120"],
data_dir,
timeout=240,
)
if started.returncode != 0:
logs = compose(["logs"], data_dir, timeout=30)
pytest.fail(
"Failed to start Readeck Compose stack.\n"
f"stdout:\n{started.stdout}\nstderr:\n{started.stderr}\n"
f"logs:\n{logs.stdout}\n{logs.stderr}"
)
wait_for_http(BASE_URL)
yield ReadeckStack(base_url=BASE_URL, data_dir=data_dir)
finally:
compose_down(data_dir)
remove_data_dir(data_dir)
_ACTIVE_DATA_DIR = None


@pytest.fixture(scope="session")
def readeck_credentials(readeck_stack: ReadeckStack) -> ReadeckCredentials:
"""Create the test user and an API token against the live instance."""
create_test_user(readeck_stack.data_dir)
token = create_api_token(readeck_stack.base_url, TEST_USERNAME, TEST_PASSWORD)
return ReadeckCredentials(
base_url=readeck_stack.base_url,
token=token,
username=TEST_USERNAME,
password=TEST_PASSWORD,
)


@pytest.fixture
async def readeck_client(
readeck_credentials: ReadeckCredentials,
) -> AsyncGenerator[ReadeckClient, None]:
"""Authenticated client closed after each test."""
async with ReadeckClient(
base_url=readeck_credentials.base_url,
token=readeck_credentials.token,
) as client:
yield client


@pytest.fixture
async def readeck_oauth_client(
readeck_stack: ReadeckStack,
) -> AsyncGenerator[ReadeckOAuthClient, None]:
"""Unauthenticated OAuth client closed after each test."""
async with ReadeckOAuthClient(base_url=readeck_stack.base_url) as client:
yield client


@pytest.fixture
async def created_bookmarks(
readeck_client: ReadeckClient,
) -> AsyncGenerator[list[str], None]:
"""Track bookmark IDs created during a test and delete them afterwards."""
bookmark_ids: list[str] = []
yield bookmark_ids
for bookmark_id in bookmark_ids:
try:
await readeck_client.delete_bookmark(bookmark_id)
except ReadeckError:
pass
Loading
Loading