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
34 changes: 34 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,37 @@ jobs:

- name: Run djhtml
run: djhtml pgcommitfest/*/templates/*.html pgcommitfest/*/templates/*.inc --tabwidth=1 --check

test:
runs-on: ubuntu-24.04
name: "Django Tests"

services:
postgres:
image: postgres:18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have assumed PostgreSQL 14 is used in production since it is recommended in README.md. https://github.com/postgres/pgcommitfest?tab=readme-ov-file#ubuntu-instructions It would be good to keep it 1:1. Any idea which PostgreSQL is app deployed with?

env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python with uv
uses: astral-sh/setup-uv@v4

- name: Create CI settings
run: cp pgcommitfest/local_settings_example.py pgcommitfest/local_settings.py

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

- name: Run tests
run: uv run pytest --create-db
1 change: 1 addition & 0 deletions pgcommitfest/commitfest/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Tests for the commitfest application
94 changes: 94 additions & 0 deletions pgcommitfest/commitfest/tests/test_apiv1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from django.test import override_settings

import json
from datetime import date

import pytest

from pgcommitfest.commitfest.models import CommitFest

pytestmark = pytest.mark.django_db


@pytest.fixture
def commitfests():
"""Create test commitfests with various statuses."""
return {
"open": CommitFest.objects.create(
name="2025-01",
status=CommitFest.STATUS_OPEN,
startdate=date(2025, 1, 1),
enddate=date(2025, 1, 31),
draft=False,
),
"in_progress": CommitFest.objects.create(
name="2024-11",
status=CommitFest.STATUS_INPROGRESS,
startdate=date(2024, 11, 1),
enddate=date(2024, 11, 30),
draft=False,
),
"recent_previous": CommitFest.objects.create(
name="2024-09",
status=CommitFest.STATUS_CLOSED,
startdate=date(2024, 9, 1),
enddate=date(2024, 9, 30),
draft=False,
),
"old_previous": CommitFest.objects.create(
name="2024-07",
status=CommitFest.STATUS_CLOSED,
startdate=date(2024, 7, 1),
enddate=date(2024, 7, 31),
draft=False,
),
"draft": CommitFest.objects.create(
name="2025-03-draft",
status=CommitFest.STATUS_OPEN,
startdate=date(2025, 3, 1),
enddate=date(2025, 3, 31),
draft=True,
),
}


def test_needs_ci_endpoint(client, commitfests):
"""Test the /api/v1/commitfests/needs_ci endpoint returns correct data."""
with override_settings(AUTO_CREATE_COMMITFESTS=False):
response = client.get("/api/v1/commitfests/needs_ci")

# Check response metadata
assert response.status_code == 200
assert response["Content-Type"] == "application/json"
assert response["Access-Control-Allow-Origin"] == "*"

# Parse and compare response
data = json.loads(response.content)

expected = {
"commitfests": {
"open": {
"id": commitfests["open"].id,
"name": "2025-01",
"status": "Open",
"startdate": "2025-01-01",
"enddate": "2025-01-31",
},
"in_progress": {
"id": commitfests["in_progress"].id,
"name": "2024-11",
"status": "In Progress",
"startdate": "2024-11-01",
"enddate": "2024-11-30",
},
"draft": {
"id": commitfests["draft"].id,
"name": "2025-03-draft",
"status": "Open",
"startdate": "2025-03-01",
"enddate": "2025-03-31",
},
}
}

assert data == expected
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ dev = [
"pycodestyle",
"ruff",
"djhtml",
"pytest",
"pytest-django",
]

[tool.setuptools.packages.find]
Expand Down Expand Up @@ -47,3 +49,13 @@ section-order = [
[tool.ruff.lint.isort.sections]
# Group all Django imports into a separate section.
django = ["django"]

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "pgcommitfest.settings"
python_files = ["tests.py", "test_*.py", "*_tests.py"]
testpaths = ["pgcommitfest"]
addopts = [
"--reuse-db",
"--strict-markers",
"-vv",
]