Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tooling updates and tests against Wagtail 6.0 #60

Merged
merged 5 commits into from
Feb 15, 2024
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
4 changes: 1 addition & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ jobs:

- name: ⬇️ Install build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flit
python -m flit install --symlink
python -m pip install --upgrade pip flit
- name: 🏗️ Build
run: python -Im flit build
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Ruff

on:
push:
branches:
- main
- 'stable/**'
pull_request:
branches: [main]

jobs:
ruff:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- run: python -Im pip install --user ruff

- name: Run ruff
working-directory: ./src
run: ruff --output-format=github wagtail_headless_preview
11 changes: 6 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches: [main]
pull_request:
branches: [main]

concurrency:
group: ${{ github.head_ref || github.run_id }}
Expand Down Expand Up @@ -52,11 +53,13 @@ jobs:
- name: ⬇️ Install dependencies
run: |
python -Im pip install --upgrade pip setuptools wheel
python -Im pip install --upgrade tox tox-gh-actions
python -Im pip install --upgrade pip setuptools wheel flit tox tox-gh-actions
- name: 🏗️ Build wheel
run: python -Im flit build --format wheel

- name: 🧪 Run tox targets for Python ${{ matrix.python-version }}
run: tox
run: tox --installpkg ./dist/*.whl

- name: ⬆️ Upload coverage data
uses: actions/upload-artifact@v3
Expand All @@ -72,8 +75,6 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
# Use latest Python, so it understands all syntax.
Expand Down
12 changes: 2 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,10 @@ repos:
args: ['--unsafe']
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
hooks:
- id: black
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.9.1]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.14
rev: 'v0.2.1'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![Build status](https://img.shields.io/github/actions/workflow/status/torchbox/wagtail-headless-preview/test.yml)](https://github.com/torchbox/wagtail-headless-preview/actions)
[![PyPI](https://img.shields.io/pypi/v/wagtail-headless-preview.svg)](https://pypi.org/project/wagtail-headless-preview/)
[![black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/torchbox/wagtail-headless-preview/main.svg)](https://results.pre-commit.ci/latest/github/torchbox/wagtail-headless-preview/main)

Expand Down
18 changes: 0 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,6 @@ exclude = [
"runtests.py",
]

[tool.ruff]
target-version = "py38"
select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"E", # pycodestyle errors
"F", # pyflakes
"I", # isort
"S", # flake8-bandit
"W", # pycodestyle warnings
"UP", # pyupgrade
]

[tool.ruff.isort]
known-first-party = ["wagtail-headless-preview"]
lines-between-types = 1
lines-after-imports = 2

[tool.coverage.run]
branch = true
parallel = true
Expand Down
37 changes: 37 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[lint]

extend-select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"DJ", # flake8-django
"E", # pycodestyle errors
"F", # pyflakes
"FBT", # flake8-boolean-trap
"I", # isort
"INT", # flake8-gettext
"PIE", # flake8-pie
"PGH", # pygrep-hooks
"S", # flake8-bandit
"SIM", # flake8-simplify
"W", # pycodestyle warnings
"YTT", # flake8-2020
"UP", # pyupgrade
"RUF100", # unused noqa
]

extend-ignore = [
"E501", # no line length errors
]

fixable = ["C4", "E", "F", "I", "UP"]

[lint.per-file-ignores]
"tests/**.py" = ["S105", "S106"]

[lint.isort]
known-first-party = ["wagtail_headless_preview"]
lines-between-types = 1
lines-after-imports = 2

[format]
docstring-code-format = true
3 changes: 3 additions & 0 deletions src/wagtail_headless_preview/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class PagePreview(models.Model):
content_json = models.TextField()
created_at = models.DateField(auto_now_add=True)

def __str__(self):
return f"PagePreview: {self.token}, {self.created_at}"

def as_page(self):
content = json.loads(self.content_json)
page_model = ContentType.objects.get_for_id(
Expand Down
2 changes: 1 addition & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

SECRET_KEY = "fake_secret_key_to_run_tests" # noqa: S105
SECRET_KEY = "fake_secret_key_to_run_tests"

INSTALLED_APPS = [
"tests.testapp",
Expand Down
12 changes: 5 additions & 7 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from django.urls import reverse
from django.utils.http import urlencode
from wagtail.models import Page
from wagtail_headless_preview.models import PagePreview
from wagtail_headless_preview.settings import headless_preview_settings

from tests.testapp.models import HeadlessPage, SimplePage
from wagtail_headless_preview.models import PagePreview
from wagtail_headless_preview.settings import headless_preview_settings


class TestFrontendViews(TestCase):
Expand All @@ -17,7 +17,7 @@ def setUpTestData(cls):
cls.admin_user = User.objects.create_superuser(
username="admin",
email="[email protected]",
password="password", # noqa: S106
password="password",
)

cls.homepage = Page.objects.get(url_path="/home/").specific
Expand All @@ -31,9 +31,7 @@ def setUpTestData(cls):
cls.page.save_revision()

def setUp(self):
self.client.login(
username=self.admin_user.username, password="password" # noqa: S106
)
self.client.login(username=self.admin_user.username, password="password")

def test_view(self):
self.assertEqual(PagePreview.objects.count(), 0)
Expand Down Expand Up @@ -122,7 +120,7 @@ def setUpTestData(cls):
cls.admin_user = User.objects.create_superuser(
username="admin",
email="[email protected]",
password="password", # noqa: S106
password="password",
)

cls.homepage = Page.objects.get(url_path="/home/").specific
Expand Down
1 change: 1 addition & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import patch

from django.test import TestCase, override_settings

from wagtail_headless_preview.deprecation import pending_deprecation_warning
from wagtail_headless_preview.settings import (
DEFAULTS,
Expand Down
1 change: 1 addition & 0 deletions tests/testapp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from rest_framework.response import Response
from wagtail.api.v2.router import WagtailAPIRouter
from wagtail.api.v2.views import PagesAPIViewSet

from wagtail_headless_preview.models import PagePreview


Expand Down
3 changes: 2 additions & 1 deletion tests/testapp/migrations/0002_headlesspage.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Generated by Django 3.2.11 on 2022-01-29 00:00

import django.db.models.deletion
import wagtail_headless_preview.models

from django.db import migrations, models

import wagtail_headless_preview.models


class Migration(migrations.Migration):
dependencies = [
Expand Down
1 change: 1 addition & 0 deletions tests/testapp/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from wagtail.models import Page

from wagtail_headless_preview.models import HeadlessMixin, HeadlessPreviewMixin


Expand Down
40 changes: 21 additions & 19 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
[tox]
min_version = 4.0
min_version = 4.11

env_list =
py{38,39,310}-django{3.2,4.1}-wagtail{4.1,5.0,5.1,5.2}
py{311}-django{4.1}-wagtail{4.1,5.0,5.1,5.2}
py{311}-django{4.2}-wagtail{5.0,5.1,5.2}
py{311,312}-django{5.0}-wagtail{5.2}
python{3.8,3.9,3.10}-dj{32}-wagtail{41,52}
python{3.11}-dj{41,42}-wagtail{52,60}
python{3.12}-dj{42,50}-wagtail{52,60}

[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311
3.12: py312
3.8: python3.8
3.9: python3.9
3.10: python3.10
3.11: python3.11
3.12: python3.12

[testenv]
package = wheel
wheel_build_env = .pkg
use_frozen_constraints = true
constrain_package_deps = true

pass_env =
FORCE_COLOR
NO_COLOR
Expand All @@ -29,31 +33,29 @@ extras = testing

deps =
django3.2: Django>=3.2, <4.0
django4.1: Django>=4.1, <4.2
django4.2: Django>=4.2, <5.0
django5.0: Django>=5.0, <5.1

wagtail4.1: wagtail>=4.1, <4.2
wagtail5.0: wagtail>=5.0, <5.1
wagtail5.1: wagtail>=5.1, <5.2
wagtail5.2: wagtail>=5.2rc1, <5.3
wagtail41: wagtail>=4.1,<4.2
wagtail5.2: wagtail>=5.2, <6.0
wagtail6.0: wagtail>=6.0, <6.1

install_command = python -Im pip install -U {opts} {packages}
commands =
python -Im coverage run runtests.py test --deprecation all {posargs: -v 2}

[testenv:coverage-report]
base_python = python3.11
; a bit of a hack - we want to keep deps to a minimum here
package = skip
deps =
extras =
install_command = python -Im pip install -U "coverage[toml]>=7.0,<8.0"
coverage>=7.0,<8.0
commands =
python -Im coverage combine
python -Im coverage report -m

[testenv:wagtailmain]
description = Test with latest Wagtail main branch

base_python = python3.12
deps =
wagtailmain: git+https://github.com/wagtail/wagtail.git@main#egg=Wagtail

Expand Down
Loading