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
71 changes: 71 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: "Tests"

on:
pull_request:
# Heroku's automatic deploys wait for these checks on the merged commit
push:
branches:
- "develop"
- "main"
workflow_dispatch:

permissions:
contents: read

concurrency:
group: tests-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 20

services:
postgres:
# matches docker-compose.yml
image: postgres:16
env:
POSTGRES_DB: lasfera
POSTGRES_USER: lasfera
POSTGRES_PASSWORD: password
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U lasfera"
--health-interval 5s
--health-timeout 5s
--health-retries 10

env:
DJANGO_READ_DOT_ENV_FILE: "false"
DB_HOST: localhost
DB_PORT: "5432"
DB_NAME: lasfera
DB_USER: lasfera
DB_PASS: password

steps:
- uses: actions/checkout@v4

# psycopg2 is built from source and needs the PostgreSQL client headers
- name: Install system packages
run: sudo apt-get update && sudo apt-get install -y libpq-dev

# Poetry has to be installed before setup-python can cache its virtualenv
- name: Install Poetry
run: pipx install poetry==2.2.1

- uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: poetry

- name: Install dependencies
run: poetry install --no-interaction --no-root

- name: Check for missing migrations
run: poetry run python manage.py makemigrations --check --dry-run

- name: Run tests
run: poetry run python manage.py test --noinput
5 changes: 5 additions & 0 deletions config/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
def carto(request):
"""Expose the CARTO API key to templates for the gazetteer basemaps."""
return {"CARTO_API_KEY": settings.CARTO_API_KEY}


def test_site_banner(request):
"""Whether to show the test site banner, on the site and in the admin."""
return {"TEST_SITE_BANNER": settings.TEST_SITE_BANNER}
4 changes: 4 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@

# CARTO API key for the gazetteer basemaps (client-exposed)
CARTO_API_KEY = env("CARTO_API_KEY", default="")
# Show a banner on every page saying this is a test site whose changes won't
# carry over to the live site; turn on for staging
TEST_SITE_BANNER = env.bool("TEST_SITE_BANNER", default=False)

# Application definition

Expand Down Expand Up @@ -121,6 +124,7 @@
"django.contrib.messages.context_processors.messages",
"django.template.context_processors.request",
"config.context_processors.carto",
"config.context_processors.test_site_banner",
],
},
},
Expand Down
15 changes: 15 additions & 0 deletions config/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.test import TestCase, override_settings
from django.urls import reverse

BANNER = "Anything you add or change here may be removed"


class TestSiteBannerTest(TestCase):
def test_hidden_by_default(self):
self.assertNotContains(self.client.get(reverse("dmca")), BANNER)
self.assertNotContains(self.client.get(reverse("admin:login")), BANNER)

@override_settings(TEST_SITE_BANNER=True)
def test_shown_on_site_and_admin(self):
self.assertContains(self.client.get(reverse("dmca")), BANNER)
self.assertContains(self.client.get(reverse("admin:login")), BANNER)
Loading
Loading