Create unit tests and gate PR + deploy on them #1

Closed
opened 2025-04-26 04:56:39 -07:00 by westfarn · 0 comments
Owner

Summary

Write real Django unit tests for SCHA and gate merges + deploy on them passing — same pattern as company_site (also aligned with dta_service “tests before deploy”).

Today schasite/tests.py is an empty stub. Local draft workflows already mirror company_site; this ticket covers shipping meaningful tests and confirming the CI/deploy gate ends up on master.

Reference: how the other repos do it

company_site (preferred model for scha)

Workflow Trigger Purpose
unittests.yml (Unit Tests) push + PR → master uv sync + manage.py test
ci.yml PR → master same unit tests on PRs
deploy.yml workflow_run after Unit Tests succeeds on master only if conclusion == success and original event was push (not PR) → docker build + containerized tests → deploy.sh

Deploy never runs from a PR.

dta_service

  • PR: unit-tests.yml runs manage.py test (with coverage + PR comment).
  • Prod deploy (deploy-prod.yml, workflow_dispatch): job order unit-testsdocker (build + containerized tests) → deploy-prod via needs:.

Same idea: no deploy until tests pass. Prefer company_site’s automated workflow_run chain for scha.

Scope

1. Unit tests

Expand schasite/tests.py (or split into a tests/ package if it gets large). Follow company_site style: TestCase / Client, mock external side effects (Stripe, email, captcha).

Minimum coverage:

  • Public pages render (index, about, calendar, newsletters, dues, membership form, board, useful links)
  • Membership / person model helpers (address string, person accessors, etc.)
  • Membership form validation (happy path + required-field failures)
  • Auth views when DEBUG (login, signup, password reset) — authz redirects when anonymous
  • Stripe endpoints: config/ and create-checkout-session/ with Stripe mocked (no live API calls)
  • CalendarEvent date helpers (has_date, past_event, future_event, no_date)
  • Community post flows that already exist (create/detail/like/report) where stable enough to assert

2. CI on pull requests

  • Land .gitea/workflows/unittests.yml and/or ci.yml so PRs to master run uv sync --frozen + uv run python manage.py test on self-hosted
  • Use test-safe env (DJANGO_ENV=dev, dummy DJANGO_SECRET_KEY) — match company_site
  • Confirm failed tests block merge (required status / branch protection if used)

3. Tests before deploy

  • Land .gitea/workflows/deploy.yml so deploy only starts after Unit Tests succeeds on a push to master (workflow_run + gitea.event.workflow_run.event == 'push')
  • Keep docker job: build image, run containerized manage.py test against compose Postgres, then deploy.sh --app scha --env prod
  • Verify a failing unit-test run does not deploy

Acceptance criteria

  • uv run python manage.py test passes locally with non-trivial assertions (not an empty suite)
  • Opening a PR to master runs unit tests in Gitea Actions
  • Pushing to master runs unit tests; deploy runs only after success
  • Deploy path still includes containerized tests before deploy.sh

Notes

  • Draft workflows already exist in the working tree and match company_site closely; finish by adding real tests and merging the workflow files.
  • No need to copy dta_service coverage-comment machinery unless we want it later.
  • Supersedes the empty body on this issue from 2025-04.
## Summary Write real Django unit tests for SCHA and gate merges + deploy on them passing — same pattern as [company_site](https://git.aimloperations.com/ai_ml_operations/company_site) (also aligned with [dta_service](https://git.aimloperations.com/Ditch_The_Agent/dta_service) “tests before deploy”). Today `schasite/tests.py` is an empty stub. Local draft workflows already mirror company_site; this ticket covers shipping meaningful tests and confirming the CI/deploy gate ends up on `master`. ## Reference: how the other repos do it ### company_site (preferred model for scha) | Workflow | Trigger | Purpose | |----------|---------|---------| | `unittests.yml` (`Unit Tests`) | push + PR → `master` | `uv sync` + `manage.py test` | | `ci.yml` | PR → `master` | same unit tests on PRs | | `deploy.yml` | `workflow_run` after **Unit Tests** succeeds on `master` | only if `conclusion == success` **and** original event was `push` (not PR) → docker build + containerized tests → `deploy.sh` | Deploy never runs from a PR. ### dta_service - PR: `unit-tests.yml` runs `manage.py test` (with coverage + PR comment). - Prod deploy (`deploy-prod.yml`, `workflow_dispatch`): job order `unit-tests` → `docker` (build + containerized tests) → `deploy-prod` via `needs:`. Same idea: no deploy until tests pass. Prefer company_site’s automated `workflow_run` chain for scha. ## Scope ### 1. Unit tests Expand `schasite/tests.py` (or split into a `tests/` package if it gets large). Follow company_site style: `TestCase` / `Client`, mock external side effects (Stripe, email, captcha). Minimum coverage: - [ ] Public pages render (index, about, calendar, newsletters, dues, membership form, board, useful links) - [ ] Membership / person model helpers (address string, person accessors, etc.) - [ ] Membership form validation (happy path + required-field failures) - [ ] Auth views when `DEBUG` (login, signup, password reset) — authz redirects when anonymous - [ ] Stripe endpoints: `config/` and `create-checkout-session/` with Stripe mocked (no live API calls) - [ ] CalendarEvent date helpers (`has_date`, `past_event`, `future_event`, `no_date`) - [ ] Community post flows that already exist (create/detail/like/report) where stable enough to assert ### 2. CI on pull requests - [ ] Land `.gitea/workflows/unittests.yml` and/or `ci.yml` so PRs to `master` run `uv sync --frozen` + `uv run python manage.py test` on self-hosted - [ ] Use test-safe env (`DJANGO_ENV=dev`, dummy `DJANGO_SECRET_KEY`) — match company_site - [ ] Confirm failed tests block merge (required status / branch protection if used) ### 3. Tests before deploy - [ ] Land `.gitea/workflows/deploy.yml` so deploy only starts after **Unit Tests** succeeds on a **push** to `master` (`workflow_run` + `gitea.event.workflow_run.event == 'push'`) - [ ] Keep docker job: build image, run containerized `manage.py test` against compose Postgres, then `deploy.sh --app scha --env prod` - [ ] Verify a failing unit-test run does **not** deploy ## Acceptance criteria - [ ] `uv run python manage.py test` passes locally with non-trivial assertions (not an empty suite) - [ ] Opening a PR to `master` runs unit tests in Gitea Actions - [ ] Pushing to `master` runs unit tests; deploy runs only after success - [ ] Deploy path still includes containerized tests before `deploy.sh` ## Notes - Draft workflows already exist in the working tree and match company_site closely; finish by adding real tests and merging the workflow files. - No need to copy dta_service coverage-comment machinery unless we want it later. - Supersedes the empty body on this issue from 2025-04.
westfarn changed title from Create unittests to Create unit tests and gate PR + deploy on them 2026-07-14 03:15:31 -07:00
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ai_ml_operations/scha#1