Skip to content

Commit

Permalink
Add interactive tox environment
Browse files Browse the repository at this point in the history
This commit adds a new `tox -e interactive` that runs a local test server, to make it easier to test this project.

This is a feature that [wagtail-localize](https://www.wagtail-localize.org/#how-to-run-tests) has that we’ve also added to [wagtail-inventory](https://github.com/cfpb/wagtail-inventory#testing) and [wagtail-treemodeladmin](https://github.com/cfpb/wagtail-treemodeladmin). 🎩 to @chosak for this pattern.
  • Loading branch information
willbarton committed Jan 11, 2023
1 parent dd41c23 commit 038a6b9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ dist/

# IDEs
.idea/
*.db
19 changes: 19 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,22 @@ commands=
coverage combine
coverage xml
diff-cover coverage.xml --compare-branch=origin/main --fail-under=100

[testenv:interactive]
basepython=python3.8

deps=
Django>=3.2,<3.3

commands_pre=
{envbindir}/django-admin makemigrations
{envbindir}/django-admin migrate
{envbindir}/django-admin shell -c "from django.contrib.auth.models import User;(not User.objects.filter(username='admin').exists()) and User.objects.create_superuser('admin', '[email protected]', 'changeme')"
# {envbindir}/django-admin loaddata wagtailflags/tests/wagtailflags/fixtures/treemodeladmin_test.json

commands=
{posargs:{envbindir}/django-admin runserver 0.0.0.0:8000}

setenv=
DJANGO_SETTINGS_MODULE=wagtailflags.tests.settings
INTERACTIVE=1
38 changes: 23 additions & 15 deletions wagtailflags/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import wagtail


DEBUG = True

ALLOWED_HOSTS = ["*"]

USE_TZ = True

SECRET_KEY = "not needed"

ROOT_URLCONF = "wagtailflags.tests.urls"
Expand All @@ -23,45 +26,44 @@
},
}

INSTALLED_APPS = (
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
)

WAGTAIL_APPS = (
"wagtail.contrib.forms",
"wagtail.contrib.modeladmin",
"wagtail.contrib.settings",
"wagtail.admin",
"wagtail.documents",
"wagtail.images",
"wagtail.snippets",
"wagtail.sites",
"wagtail.users",
)

WAGTAILADMIN_RICH_TEXT_EDITORS = {
"default": {"WIDGET": "wagtail.admin.rich_text.DraftailRichTextArea"},
}

# Wagtail 3.0 moves testapp from wagtail.tests to wagtail.test
if wagtail.VERSION >= (3, 0, 0): # pragma: no cover
WAGTAIL_APPS += (
"wagtail",
"wagtail.test.testapp",
)
WAGTAILADMIN_RICH_TEXT_EDITORS["custom"] = {
"WIDGET": "wagtail.test.testapp.rich_text.CustomRichTextArea"
WAGTAILADMIN_RICH_TEXT_EDITORS = {
"default": {"WIDGET": "wagtail.admin.rich_text.DraftailRichTextArea"},
"custom": {
"WIDGET": "wagtail.test.testapp.rich_text.CustomRichTextArea"
},
}
else: # pragma: no cover
WAGTAIL_APPS += (
"wagtail.core",
"wagtail.tests.testapp",
)
WAGTAILADMIN_RICH_TEXT_EDITORS["custom"] = {
"WIDGET": "wagtail.tests.testapp.rich_text.CustomRichTextArea"
WAGTAILADMIN_RICH_TEXT_EDITORS = {
"default": {"WIDGET": "wagtail.admin.rich_text.DraftailRichTextArea"},
"custom": {
"WIDGET": "wagtail.tests.testapp.rich_text.CustomRichTextArea"
},
}

WAGTAILADMIN_BASE_URL = "http://localhost:8000"

MIDDLEWARE = (
"django.middleware.common.CommonMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
Expand All @@ -71,6 +73,13 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
)

INSTALLED_APPS = (
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
)


INSTALLED_APPS = (
(
"django.contrib.admin",
Expand All @@ -88,7 +97,6 @@
)
)

STATIC_ROOT = "/tmp/static/"
STATIC_URL = "/static/"

TEMPLATES = [
Expand Down

0 comments on commit 038a6b9

Please sign in to comment.