Skip to content

Commit 2f48adb

Browse files
authored
Merge pull request #1 from PythonUnited/tests
Add ci/tests
2 parents 4b5b96c + 4a26090 commit 2f48adb

12 files changed

Lines changed: 150 additions & 18 deletions

File tree

.github/workflows/ci.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Install uv
16+
uses: astral-sh/setup-uv@v5
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.12"
22+
23+
- name: Run Ruff
24+
run: |
25+
uv pip install --system ruff
26+
ruff check .
27+
ruff format --check .
28+
29+
test:
30+
needs: lint
31+
runs-on: ubuntu-latest
32+
strategy:
33+
matrix:
34+
python-version: ["3.12", "3.13", "3.14"]
35+
django-version: ["6.0"]
36+
37+
steps:
38+
- uses: actions/checkout@v4
39+
40+
- name: Install uv
41+
uses: astral-sh/setup-uv@v5
42+
with:
43+
enable-cache: true
44+
45+
- name: Set up Python ${{ matrix.python-version }}
46+
uses: actions/setup-python@v5
47+
with:
48+
python-version: ${{ matrix.python-version }}
49+
50+
- name: Install dependencies
51+
run: |
52+
uv pip install --system "django==${{ matrix.django-version }}"
53+
uv pip install --system -e ".[test]" || uv pip install --system -e . pytest pytest-django huey
54+
55+
- name: Run Tests
56+
run: PYTHONPATH=. pytest

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ Log and monitor [Huey](https://huey.readthedocs.io/en/latest/) task attempts dir
1515

1616
1. Install the package using [uv](https://docs.astral.sh/uv/):
1717
```bash
18-
uv add django-huey-log
18+
uv add git+https://github.com/PythonUnited/django-huey-log.git
1919
```
2020

2121
2. Add `huey_log` to your `INSTALLED_APPS` in `settings.py`:
2222
```python
2323
INSTALLED_APPS = [
2424
# ...
25-
"huey_log",
25+
"django_huey_log",
2626
# ...
2727
]
2828
```

example/manage.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env python
22
"""Django's command-line utility for administrative tasks."""
3+
34
import os
45
import sys
56

67

78
def main():
89
"""Run administrative tasks."""
9-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
10+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
1011
try:
1112
from django.core.management import execute_from_command_line
1213
except ImportError as exc:
@@ -18,5 +19,5 @@ def main():
1819
execute_from_command_line(sys.argv)
1920

2021

21-
if __name__ == '__main__':
22-
main()
22+
if __name__ == "__main__":
23+
main()

example/settings.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from pathlib import Path
32

43
BASE_DIR = Path(__file__).resolve().parent.parent
@@ -55,7 +54,7 @@
5554
STATIC_URL = "static/"
5655

5756
HUEY = {
58-
'huey_class': 'huey.SqliteHuey',
59-
'name': 'test-huey',
60-
'filename': BASE_DIR / 'huey_db.sqlite3',
61-
}
57+
"huey_class": "huey.SqliteHuey",
58+
"name": "test-huey",
59+
"filename": BASE_DIR / "huey_db.sqlite3",
60+
}

example/tasks.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
from huey.contrib.djhuey import task, db_task
21
import time
32

3+
from huey.contrib.djhuey import task
4+
5+
46
@task()
57
def success_task(name):
68
print(f"Hello {name}!")
79
time.sleep(1)
810
return f"Done {name}"
911

12+
1013
@task()
1114
def failure_task():
1215
time.sleep(0.5)
13-
raise ValueError("This task was designed to fail!")
16+
raise ValueError("This task was designed to fail!")

example/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
urlpatterns = [
55
path("admin/", admin.site.urls),
6-
]
6+
]

pyproject.toml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Log and monitor Huey task attempts in the Django admin"
55
readme = "README.md"
66
requires-python = ">=3.10"
77
dependencies = [
8-
"django>=4.2",
8+
"django>=5.0",
99
"huey>=2.5.0",
1010
]
1111

@@ -17,4 +17,33 @@ build-backend = "hatchling.build"
1717
packages = ["src/django_huey_log"]
1818

1919
[tool.hatch.build.targets.wheel.sources]
20-
"src" = "django_huey_log"
20+
"src" = "django_huey_log"
21+
22+
[project.optional-dependencies]
23+
test = [
24+
"pytest>=7.0",
25+
"pytest-django>=4.5",
26+
]
27+
dev = [
28+
"ruff==0.14.13",
29+
]
30+
31+
[tool.pytest.ini_options]
32+
DJANGO_SETTINGS_MODULE = "example.settings"
33+
python_files = ["tests.py", "test_*.py"]
34+
pythonpath = ["."]
35+
36+
[tool.ruff]
37+
# Target version for the generated code
38+
target-version = "py310"
39+
line-length = 88
40+
41+
[tool.ruff.lint]
42+
# Enable Pyflakes (F) and pycodestyle (E, W) codes by default.
43+
# Also common: I (isort), B (flake8-bugbear), UP (pyupgrade)
44+
select = ["E", "F", "W", "I", "B", "UP"]
45+
ignore = []
46+
47+
[tool.ruff.format]
48+
quote-style = "double"
49+
indent-style = "space"

src/django_huey_log/admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.contrib import admin
2+
23
from .models import HueyTaskAttempt
34

45

src/django_huey_log/migrations/0001_initial.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
class Migration(migrations.Migration):
8-
98
initial = True
109

1110
dependencies = []

src/django_huey_log/signals.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

33
import traceback as tb
4-
from datetime import datetime, timezone as dt_timezone
4+
from datetime import datetime
5+
from datetime import timezone as dt_timezone
56

67
from django.utils import timezone
78
from huey.contrib.djhuey import HUEY
@@ -48,7 +49,8 @@ def _task_eta(task):
4849

4950
def _upsert_attempt(task, status: str, **fields):
5051
# Single-row “current attempt” strategy keyed by task_id + started_at bucket:
51-
# For simplicity: just create new rows for EXECUTING, then update the latest row for completion/error.
52+
# For simplicity: just create new rows for EXECUTING, then update the latest
53+
# row for completion/error.
5254
task_id = str(getattr(task, "id", "") or getattr(task, "task_id", ""))
5355

5456
if status == HueyTaskAttempt.Status.EXECUTING:

0 commit comments

Comments
 (0)