Skip to content

Commit

Permalink
Merge pull request #63 from cfpb/feature/wagtail-3-and-4
Browse files Browse the repository at this point in the history
Add support for Wagtail 3 and Wagtail 4
  • Loading branch information
chosak committed Nov 10, 2022
2 parents 8678816 + 4097908 commit 30ee26f
Show file tree
Hide file tree
Showing 17 changed files with 371 additions and 97 deletions.
45 changes: 28 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.8

- name: Install dependencies
run: |
Expand All @@ -31,25 +31,36 @@ jobs:

strategy:
matrix:
toxenv:
- py36-dj32-wag215
- py39-dj32-wag215
- py39-dj40-wag216
python: ['3.8', '3.10']
django: ['3.2']
wagtail: ['2.15','3.0','4.0']
include:
- toxenv: py36-dj32-wag215
python-version: 3.6
- toxenv: py39-dj32-wag215
python-version: 3.9
- toxenv: py39-dj40-wag216
python-version: 3.9
- python: '3.8'
django: '4.0'
wagtail: '3.0'
- python: '3.10'
django: '4.0'
wagtail: '3.0'
- python: '3.8'
django: '4.0'
wagtail: '4.0'
- python: '3.10'
django: '4.0'
wagtail: '4.0'
- python: '3.8'
django: '4.1'
wagtail: '4.0'
- python: '3.10'
django: '4.1'
wagtail: '4.0'

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.python }}

- name: Install dependencies
run: |
Expand All @@ -61,6 +72,6 @@ jobs:
tox
coveralls
env:
TOXENV: ${{ matrix.toxenv }}
TOXENV: python${{ matrix.python }}-django${{ matrix.django }}-wagtail${{ matrix.wagtail }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_SERVICE_NAME: github
18 changes: 15 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,28 @@ Compatibility
This code has been tested for compatibility with:

* Python 3.6+
* Django 3.2 (LTS), Django 4.0 (Current)
* Wagtail 2.15 (LTS), Wagtail 2.16 (Current)
* Django 3.2 (LTS), 4.0, 4.1
* Wagtail 2.15 (LTS), 3.0, 4.0

It should be compatible with all intermediate versions, as well.
If you find that it is not, please `file an issue <https://github.com/cfpb/wagtail-inventory/issues/new>`_.

Testing
-------

Run unit tests with ``tox`` to test against select supported package combinations.
Running project unit tests requires `tox <https://tox.wiki/en/latest/>`_:

.. code-block:: bash
$ tox
To run the test app interactively, run:

.. code-block:: bash
$ tox -e interactive
Now you can visit http://localhost:8000/admin/ in a browser and log in with ``admin`` / ``changeme``.

Open source licensing info
--------------------------
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

install_requires = [
"tqdm>=4.15.0,<5",
"wagtail>=2.15,<3",
"wagtail>=2.15,<4.1",
]


Expand All @@ -23,16 +23,17 @@
version="1.5",
include_package_data=True,
packages=find_packages(),
python_requires=">=3.6",
python_requires=">=3.8",
install_requires=install_requires,
extras_require={"testing": testing_extras},
classifiers=[
"Framework :: Django",
"Framework :: Django :: 2.2",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Wagtail",
"Framework :: Wagtail :: 2",
"Framework :: Wagtail :: 3",
"Framework :: Wagtail :: 4",
"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
"License :: Public Domain",
"Programming Language :: Python",
Expand Down
66 changes: 66 additions & 0 deletions testmanage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python

import argparse
import os
import shutil
import sys
import warnings

from django.core.management import execute_from_command_line


os.environ["DJANGO_SETTINGS_MODULE"] = "wagtailinventory.tests.settings"


def make_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
"--deprecation",
choices=["all", "pending", "imminent", "none"],
default="imminent",
)
return parser


def parse_args(args=None):
return make_parser().parse_known_args(args)


def runtests():
args, rest = parse_args()

only_wagtail = r"^wagtail(\.|$)"
if args.deprecation == "all":
# Show all deprecation warnings from all packages
warnings.simplefilter("default", DeprecationWarning)
warnings.simplefilter("default", PendingDeprecationWarning)
elif args.deprecation == "pending":
# Show all deprecation warnings from wagtail
warnings.filterwarnings(
"default", category=DeprecationWarning, module=only_wagtail
)
warnings.filterwarnings(
"default", category=PendingDeprecationWarning, module=only_wagtail
)
elif args.deprecation == "imminent":
# Show only imminent deprecation warnings from wagtail
warnings.filterwarnings(
"default", category=DeprecationWarning, module=only_wagtail
)
elif args.deprecation == "none":
# Deprecation warnings are ignored by default
pass

argv = [sys.argv[0]] + rest

try:
execute_from_command_line(argv)
finally:
from wagtail.tests.settings import MEDIA_ROOT, STATIC_ROOT

shutil.rmtree(STATIC_ROOT, ignore_errors=True)
shutil.rmtree(MEDIA_ROOT, ignore_errors=True)


if __name__ == "__main__":
runtests()
49 changes: 33 additions & 16 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,56 @@
skipsdist=True
envlist=
lint,
py{36,39}-dj32-wag215,
py39-dj40-wag216
python{3.8,3.10}-django{3.2}-wagtail{2.15,3.0,4.0}
python{3.8,3.10}-django{4.0}-wagtail{3.0,4.0}
python{3.8,3.10}-django{4.1}-wagtail{4.0}

[testenv]
install_command=pip install -e ".[testing]" -U {opts} {packages}
commands=
coverage erase
coverage run {envbindir}/django-admin test {posargs}
coverage report -m
setenv=
DJANGO_SETTINGS_MODULE=wagtailinventory.tests.settings
coverage run {toxinidir}/testmanage.py test {posargs}
coverage report --show-missing --fail-under=100

basepython=
py36: python3.6
py39: python3.9
python3.8: python3.8
python3.10: python3.10

deps=
mock>=1.0.0
dj32: Django>=3.2,<3.3
dj40: Django>=4.0,<4.1
wag215: wagtail>=2.15,<2.16
wag216: wagtail>=2.16,<2.17
django3.2: Django>=3.2,<3.3
django4.0: Django>=4.0,<4.1
django4.1: Django>=4.1,<4.2
wagtail2.15: wagtail>=2.15,<2.16
wagtail3.0: wagtail>=3.0,<3.1
wagtail4.0: wagtail>=4.0,<4.1

[testenv:lint]
basepython=python3.9
basepython=python3.8
deps=
black
flake8
isort
commands=
black --check wagtailinventory setup.py
flake8 wagtailinventory setup.py
isort --check-only --diff wagtailinventory
black --check wagtailinventory setup.py testmanage.py
flake8 wagtailinventory setup.py testmanage.py
isort --check-only --diff wagtailinventory testmanage.py

[testenv:interactive]
basepython=python3.8

commands_pre=
python {toxinidir}/testmanage.py makemigrations
python {toxinidir}/testmanage.py migrate
python {toxinidir}/testmanage.py shell -c "from django.contrib.auth.models import User;(not User.objects.filter(username='admin').exists()) and User.objects.create_superuser('admin', 'super@example.com', 'changeme')"
python {toxinidir}/testmanage.py loaddata wagtailinventory/fixtures/test_blocks.json
python {toxinidir}/testmanage.py block_inventory

commands=
{posargs:python testmanage.py runserver 0.0.0.0:8000}

setenv=
INTERACTIVE=1

[isort]
combine_as_imports=1
Expand Down
32 changes: 0 additions & 32 deletions wagtailinventory/fixtures/test_blocks.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
[
{
"model": "auth.user",
"fields": {
"password": "pbkdf2_sha256$100000$RKUa1ZdWARZL$rG55GlxBES3r1bDuInG/z9IthbzqS43lehVwXGx4Ke4=",
"last_login": "2018-06-11T11:43:09.976",
"is_superuser": true,
"username": "admin",
"first_name": "",
"last_name": "",
"email": "admin@admin.admin",
"is_staff": true,
"is_active": true,
"date_joined": "2018-06-11T11:42:56.375",
"groups": [],
"user_permissions": []
}
},
{
"model": "wagtailcore.page",
"pk": 3,
Expand All @@ -33,9 +16,6 @@
"live": false,
"has_unpublished_changes": true,
"url_path": "/home/single-streamfield-page-no-content/",
"owner": [
"admin"
],
"seo_title": "",
"show_in_menus": false,
"search_description": "",
Expand Down Expand Up @@ -66,9 +46,6 @@
"live": false,
"has_unpublished_changes": true,
"url_path": "/home/single-streamfield-page-content/",
"owner": [
"admin"
],
"seo_title": "",
"show_in_menus": false,
"search_description": "",
Expand Down Expand Up @@ -99,9 +76,6 @@
"live": false,
"has_unpublished_changes": true,
"url_path": "/home/multiple-streamfields-page/",
"owner": [
"admin"
],
"seo_title": "",
"show_in_menus": false,
"search_description": "",
Expand Down Expand Up @@ -132,9 +106,6 @@
"live": false,
"has_unpublished_changes": true,
"url_path": "/home/nested-streamblock-page/",
"owner": [
"admin"
],
"seo_title": "",
"show_in_menus": false,
"search_description": "",
Expand Down Expand Up @@ -165,9 +136,6 @@
"live": false,
"has_unpublished_changes": true,
"url_path": "/home/no-streamfields-page/",
"owner": [
"admin"
],
"seo_title": "",
"show_in_menus": false,
"search_description": "",
Expand Down
3 changes: 1 addition & 2 deletions wagtailinventory/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class PageBlockQueryForm(forms.Form):
)

has = forms.ChoiceField(
choices=((c, c) for c in (INCLUDES_BLOCK, EXCLUDES_BLOCK)),
label=None,
choices=((c, c) for c in (INCLUDES_BLOCK, EXCLUDES_BLOCK)), label=None
)

def __init__(self, *args, **kwargs):
Expand Down
2 changes: 0 additions & 2 deletions wagtailinventory/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ def get_field_blocks(value):
block = getattr(value, "block", None)
blocks = [block] if block else []

if isinstance(value, list):
child_blocks = value
if isinstance(block, StructBlock):
if hasattr(value, "bound_blocks"):
child_blocks = value.bound_blocks.values()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.db.models import Min, Count


def remove_duplicates(apps, schema_editor):
def remove_duplicates(apps, schema_editor): # pragma: no cover
PageBlock = apps.get_model('wagtailinventory', 'PageBlock')

duplicate_pks_to_keep = (
Expand Down
2 changes: 2 additions & 0 deletions wagtailinventory/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@
WAGTAIL_SITE_NAME = "Test Site"

ROOT_URLCONF = "wagtailinventory.tests.urls"

WAGTAILADMIN_BASE_URL = "http://localhost:8000"
Loading

0 comments on commit 30ee26f

Please sign in to comment.