Skip to content

Commit

Permalink
Merge pull request #1 from torchbox-forks/support/wagtail-51
Browse files Browse the repository at this point in the history
Wagtail 5.1
  • Loading branch information
nickmoreton authored Nov 22, 2023
2 parents 4c9a40e + cfd12bc commit f0dc8d4
Show file tree
Hide file tree
Showing 17 changed files with 507 additions and 5 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/python-tox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Python Tests

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

strategy:
max-parallel: 4
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Test with tox
run: tox
161 changes: 159 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,160 @@
*.pyc
*.egg-info
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
wagtail>=4.1
pytest==6.2.5
pytest-cov==3.0.0
pytest-django==4.5.0
pytest-pythonpath==0.7.3
coverage==6.0
tox-gh-actions>=3.1
20 changes: 17 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
use_setuptools()
from setuptools import setup, find_packages

install_requires = [
'wagtail>=4.1',
]

tests_require = [
"pytest==6.2.5",
"pytest-cov==3.0.0",
"pytest-django==4.5.0",
"pytest-pythonpath==0.7.3",
"coverage==6.0",
]

setup(
name='wagtail-accessibility',
version='0.2.1',
Expand All @@ -22,9 +34,11 @@
author_email='[email protected]',
url='https://github.com/takeflight/wagtail-accessibility',

install_requires=[
'wagtail>=1.0',
],
install_requires=install_requires,
tests_require=tests_require,
extras_require={
"test": tests_require,
},
zip_safe=False,
license='BSD License',

Expand Down
Empty file added tests/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os

import django
from django.test.utils import override_settings
import pytest


def pytest_configure():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings")
django.setup()


@pytest.fixture(scope="session", autouse=True)
def custom_settings(tmpdir_factory):
overrides = override_settings(MEDIA_ROOT=str(tmpdir_factory.mktemp("media")))
overrides.enable()
98 changes: 98 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import os

from wagtail import VERSION as WAGTAIL_VERSION

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

ALLOWED_HOSTS = ["*"]

SECRET_KEY = "ThisIsForTestingOnly"

INSTALLED_APPS = [
"wagtailaccessibility",
"tests.testapp",

'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
'wagtail.snippets',
'wagtail.documents',
'wagtail.images',
'wagtail.search',
'wagtail.admin',
"wagtail",

"taggit",
"modelcluster",

"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.sites",
"django.contrib.staticfiles",
]

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": ":memory:",
}
}

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
]

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
]
},
}
]

ROOT_URLCONF = "tests.urls"

DEFAULT_AUTO_FIELD = "django.db.models.AutoField"

CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "unique-snowflake",
}
}

STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'staticfiles'),
]

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

WAGTAILADMIN_BASE_URL = "http://example.com"

USE_TZ = False
41 changes: 41 additions & 0 deletions tests/test_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from django.conf import settings
from pytest_django.asserts import assertInHTML, assertJSONEqual

from tests.testapp.models import SimplePage


validity = {
'is_valid': True
}

if settings.WAGTAIL_VERSION >= (4, 0):
validity['is_available'] = True


def test_preview(admin_client):
simple_page = SimplePage.objects.first()

post_data = {
'title': "Accessibility",
'slug': 'accessibility',
}

preview_url = "/admin/pages/{}/edit/preview/".format(simple_page.pk)
response = admin_client.post(preview_url, post_data)

# Check the JSON response
assert response.status_code == 200
assertJSONEqual(response.content.decode(), validity)

# Check the user can refresh the preview
preview_session_key = 'wagtail-preview-{}'.format(simple_page.pk)
assert preview_session_key in admin_client.session

response = admin_client.get(preview_url)

# Check the HTML response
assert response.status_code == 200
assertInHTML(
'<script src="/static/js/tota11y.min.js"></script>',
response.content.decode(),
)
Empty file added tests/testapp/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions tests/testapp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class TestAppConfig(AppConfig):
name = "tests.testapp"
Loading

0 comments on commit f0dc8d4

Please sign in to comment.