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
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install -r cms/requirements.txt && pip install pytest pytest-cov
- run: pytest --cov --cov-report=xml -v
- uses: codecov/codecov-action@v5
if: github.event_name == 'push'
with:
fail_ci_if_error: false
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<p align="center">
<a href="https://github.com/GeiserX/Way-CMS/blob/main/LICENSE"><img src="https://img.shields.io/github/license/GeiserX/Way-CMS?style=flat-square" alt="License"></a>
<a href="https://hub.docker.com/r/drumsergio/way-cms"><img src="https://img.shields.io/docker/pulls/drumsergio/way-cms?style=flat-square&logo=docker&logoColor=white" alt="Docker Pulls"></a>
<a href="https://codecov.io/gh/GeiserX/Way-CMS"><img src="https://codecov.io/gh/GeiserX/Way-CMS/graph/badge.svg" alt="codecov"></a>
</p>

<p align="center"><strong>Simple, web-accessible CMS for editing HTML/CSS files downloaded from Wayback Archive with real-time preview.</strong></p>
Expand Down
60 changes: 60 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Conftest for Way-CMS tests.

The production code uses get_db() which opens a new connection each time.
This causes issues in tests because nested calls (e.g. create() calling get_by_id())
open separate connections and the inner one can't see uncommitted data from the outer.

We fix this by patching get_db to always return the same shared connection.
"""

import os
import sys
import sqlite3
from contextlib import contextmanager

import pytest

# Add cms directory to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'cms'))


@pytest.fixture(autouse=True)
def shared_db(tmp_path, monkeypatch):
"""Patch database module to use a shared in-memory-like connection."""
data_dir = str(tmp_path / "data")
db_path = os.path.join(data_dir, "waycms.db")
os.makedirs(data_dir, exist_ok=True)

monkeypatch.setattr('database.DATA_DIR', data_dir)
monkeypatch.setattr('database.DB_PATH', db_path)

# Create a single shared connection
shared_conn = sqlite3.connect(db_path)
shared_conn.row_factory = sqlite3.Row
shared_conn.execute("PRAGMA foreign_keys = ON")

@contextmanager
def shared_get_db():
try:
yield shared_conn
shared_conn.commit()
except Exception:
shared_conn.rollback()
raise

monkeypatch.setattr('database.get_db', shared_get_db)

# Also patch in models and auth since they import get_db at module level
import database
import models
import auth

# Patch get_db in models module (it imports from database)
monkeypatch.setattr('models.get_db', shared_get_db)

# Initialize the database schema
database.init_db()

yield shared_conn

shared_conn.close()
Loading
Loading