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
17 changes: 16 additions & 1 deletion .github/workflows/lint.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Bakerydemo CI
name: CI

on:
push:
Expand Down Expand Up @@ -29,3 +29,18 @@ jobs:
node-version-file: '.nvmrc'
- run: npm ci
- run: make lint-client
test-server:
runs-on: ubuntu-latest
env:
DJANGO_SETTINGS_MODULE: bakerydemo.settings.test
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v4
with:
python-version: '3.12'
cache: 'pip'
cache-dependency-path: 'requirements/*.txt'
- run: pip install -r requirements/development.txt
- run: ./manage.py check
- run: ./manage.py makemigrations --check --noinput
- run: ./manage.py test
Empty file.
68 changes: 68 additions & 0 deletions bakerydemo/base/tests/test_home_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from django.contrib.auth.models import User
from wagtail.models import Page, Site
from wagtail.test.utils import WagtailPageTestCase
from wagtail.test.utils.form_data import nested_form_data, streamfield

from bakerydemo.base.models import HomePage


class HomePageRenderTest(WagtailPageTestCase):
@classmethod
def setUpTestData(cls):
"""
Create the page tree and site once for all tests in this class.

This runs ONCE before all tests, not before each test.
All tests will share this setup, making tests faster.
"""
cls.root = Page.get_first_root_node()

cls.site = Site.objects.create(
hostname="testserver",
root_page=cls.root,
is_default_site=True,
)

cls.home = HomePage(
title="Home",
slug="test-home",
hero_text="Welcome to our site",
hero_cta="Get Started",
)
cls.root.add_child(instance=cls.home)
cls.home.save_revision().publish()

def setUp(self):
super().setUp()

self.user = User.objects.create_superuser(
username="testadmin", email="[email protected]", password="password"
)
self.client.login(username="testadmin", password="password")

def test_homepage_renders(self):
response = self.client.get(self.home.url)

self.assertEqual(response.status_code, 200)

self.assertTemplateUsed(response, "base/home_page.html")

self.assertContains(response, "Welcome to our site")
self.assertContains(response, "Get Started")

def test_can_create_another_homepage(self):
home_page_data = nested_form_data(
{
"title": "Home",
"slug": "test-home-2",
"hero_text": "Welcome",
"hero_cta": "Get Started",
"body": streamfield(
[
("text", "This is some dummy content for the body block"),
]
),
}
)

self.assertCanCreate(self.root, HomePage, home_page_data)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class Migration(migrations.Migration):
migrations.AlterModelOptions(
name="country",
options={
"ordering": ["sort_order", "title"],
"verbose_name": "country of origin",
"verbose_name_plural": "countries of origin",
},
Expand Down
41 changes: 41 additions & 0 deletions bakerydemo/settings/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from .base import * # noqa
from .base import STORAGES
# #############
# General

ALLOWED_HOSTS = ["*"]

# Don't redirect to HTTPS in tests or send the HSTS header
SECURE_SSL_REDIRECT = False
SECURE_HSTS_SECONDS = 0

STORAGES["staticfiles"]["BACKEND"] = (
"django.contrib.staticfiles.storage.StaticFilesStorage"
)

# Use local memory caching instead of redis when testing locally
# to prevent caching shenanigans
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
}
}

# Wagtail
WAGTAILADMIN_BASE_URL = "http://localhost:8000"

# Task queue configuration to ensure tasks run immediately in the test environment
# https://docs.wagtail.org/en/stable/releases/6.4.html#background-tasks-run-at-end-of-current-transaction
TASKS = {
"default": {
"BACKEND": "django_tasks.backends.immediate.ImmediateBackend",
"ENQUEUE_ON_COMMIT": False,
}
}

# #############
# Performance

# By default, Django uses a computationally difficult algorithm for passwords hashing.
# We don't need such a strong algorithm in tests, so use MD5
PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"]