Skip to content

Commit

Permalink
Add interactive testing environment
Browse files Browse the repository at this point in the history
  • Loading branch information
chosak committed Oct 31, 2022
1 parent afa96cf commit 8bbd71e
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 39 deletions.
14 changes: 13 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,19 @@ If you find that it is not, please `file an issue <https://github.com/cfpb/wagta
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
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()
26 changes: 20 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ envlist=
install_command=pip install -e ".[testing]" -U {opts} {packages}
commands=
coverage erase
coverage run {envbindir}/django-admin test {posargs}
coverage run {toxinidir}/testmanage.py test {posargs}
coverage report --show-missing --fail-under=100
setenv=
DJANGO_SETTINGS_MODULE=wagtailinventory.tests.settings

basepython=
python3.8: python3.8
Expand All @@ -35,9 +33,25 @@ deps=
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
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"

0 comments on commit 8bbd71e

Please sign in to comment.