Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a6cad14
Adds coverage on PR and also on commits to dev branch
singhgarima Apr 19, 2026
8ba68c0
Merge pull request #62 from singhgarima/dev
seanboyce Apr 21, 2026
322014d
Ignoring files based on vars.py
singhgarima Apr 21, 2026
9ebe536
refactor(books): extract service layer and convert to package
singhgarima Apr 21, 2026
bdc9869
refactor(books): extract BookMetadataClient class and add service tests
singhgarima Apr 21, 2026
d87b8fc
refactor(books): move BookMetadataClient to its own module
singhgarima Apr 22, 2026
f1379cb
(Issue #59 and Issue #54) Allow scanning a book without Author
singhgarima Apr 23, 2026
7682cad
Merge pull request #63 from singhgarima/dev
seanboyce Apr 25, 2026
2d7de2b
Fixes a bug around admin user restrictions for add_book endpoint
singhgarima Apr 25, 2026
ce32874
Merge pull request #65 from singhgarima/dev
seanboyce Apr 25, 2026
d0f0511
Split dependencies file into smaller files with related logic
singhgarima Apr 25, 2026
734683d
Adds annoated user and admin_user utils
singhgarima Apr 25, 2026
b42ff2e
Uses annotations in books api
singhgarima Apr 25, 2026
107a934
Uses annotations in admin api
singhgarima Apr 25, 2026
fa0f735
Uses annotations in federation api
singhgarima Apr 25, 2026
265c72c
Uses annotations in files api
singhgarima Apr 25, 2026
0eb9d3f
Uses annotations in reading list api
singhgarima Apr 25, 2026
5612c30
Ensures SQLite schema exists before any test runs
singhgarima Apr 25, 2026
29803b6
Adds a try/except
singhgarima Apr 26, 2026
0400ff1
Makes message more generic
singhgarima Apr 26, 2026
01bbc34
Update message for failed to download ebook and adds tests
singhgarima Apr 26, 2026
de9e19c
Merge pull request #66 from singhgarima/dev
seanboyce Apr 27, 2026
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: Tests (PR to dev)
name: CI pipeline

on:
pull_request:
branches:
- dev
push:
branches:
- dev

jobs:
unit-tests:
Expand All @@ -26,7 +29,21 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt -r requirements-test.txt

- name: Run unit tests
- name: Run unit tests with coverage
env:
USE_REDIS: "false"
run: python -m pytest tests/ -v
run: |
python -m pytest tests/ -v \
--cov=ubiblio \
--cov-report=term-missing \
--cov-report=xml \
--cov-report=html

- name: Upload coverage reports
uses: actions/upload-artifact@v4
with:
name: coverage-reports
path: |
htmlcov/
coverage.xml
if-no-files-found: error
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ coverage.xml
.pytest_cache/
cover/


# Translations
*.mo
*.pot
Expand All @@ -64,6 +65,7 @@ cover/
local_settings.py
db.sqlite3
db.sqlite3-journal
sql_app.db

# Flask stuff:
instance/
Expand Down Expand Up @@ -195,4 +197,6 @@ pyrightconfig.json
# End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode

config/
secret_key.txt
secret_key.txt
sign_key.txt
verify_key.txt
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tool.coverage.run]
source = ["ubiblio"]
branch = true
omit = [
"*/tests/*",
]

[tool.coverage.report]
precision = 1
show_missing = true
skip_empty = true
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-r requirements.txt
pytest
httpx
pytest-cov
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ aiofiles==24.1.0
pillow==12.2.0
uuid==1.30
requests==2.32.2
responses==0.25.8
17 changes: 17 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,20 @@

# Rate limiting uses Redis + FastAPILimiter.init(); tests skip that unless you opt in.
os.environ["USE_REDIS"] = "false"


def pytest_configure(config):
"""
Ensure the SQLite schema exists before any test runs.

Tests that go through ``TestClient(app)`` get the schema for free because
``ubiblio.main`` calls ``Base.metadata.create_all`` at import time, but tests
that exercise lower-level helpers (e.g. ``tests/dependencies/test_auth.py``)
don't import ``ubiblio.main``. On a clean CI checkout there's no ``sql_app.db``,
so they fail with "no such table: users". Importing the schema here is enough
to make either path work.
"""
from ubiblio import models
from ubiblio.database import engine

models.Base.metadata.create_all(bind=engine)
Empty file added tests/dependencies/__init__.py
Empty file.
21 changes: 21 additions & 0 deletions tests/dependencies/test_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest
from fastapi import HTTPException

from ubiblio.dependencies.auth import get_admin_user, get_user
from tests.helpers.create_test_user import create_test_user


class TestGetAdminUser:
def test_admin_user_is_returned(self):
with create_test_user(is_admin=True) as test_user:
user = get_user(test_user.username)
result = get_admin_user(user)
assert result is user

def test_non_admin_raises_403(self):
with create_test_user(is_admin=False) as test_user:
user = get_user(test_user.username)
with pytest.raises(HTTPException) as exc_info:
get_admin_user(user)
assert exc_info.value.status_code == 403
assert exc_info.value.detail == "Only an admin can perform this action."
Empty file added tests/routers/books/__init__.py
Empty file.
Loading
Loading