From faab3a7f08580bb012cf9b44227aa5d0f87f38b1 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Thu, 29 Feb 2024 15:23:03 +0100 Subject: [PATCH] [#51] Fixed testapp (see README for instructions) --- .gitignore | 2 + README.rst | 35 +++++++++++++++--- fix.sh | 4 ++ pyproject.toml | 2 +- testapp/__init__.py | 0 {tests => testapp}/media/logo.jpg | Bin {tests => testapp}/settings.py | 14 ++++--- {tests => testapp}/static/css/style.css | 0 {tests => testapp}/static/logo.png | Bin .../static_alternative/logo_copy.png | Bin testapp/urls.py | 13 +++++++ tests/manage.py | 10 ----- tests/urls.py | 7 ---- tox.ini | 4 +- 14 files changed, 60 insertions(+), 31 deletions(-) create mode 100644 testapp/__init__.py rename {tests => testapp}/media/logo.jpg (100%) rename {tests => testapp}/settings.py (90%) rename {tests => testapp}/static/css/style.css (100%) rename {tests => testapp}/static/logo.png (100%) rename {tests => testapp}/static_alternative/logo_copy.png (100%) create mode 100644 testapp/urls.py delete mode 100644 tests/manage.py delete mode 100644 tests/urls.py diff --git a/.gitignore b/.gitignore index a8d0db7..8205100 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ mail_editor.egg-info coverage\.xml junit\.xml + +testapp/mail_editor.db diff --git a/README.rst b/README.rst index 0cf7fd9..019375f 100644 --- a/README.rst +++ b/README.rst @@ -161,13 +161,13 @@ You can set template variables to all of the mail templates in the following fas .. code:: python -# static dictionary -MAIL_EDITOR_BASE_CONTEXT = { - 'url': 'http://www.maykinmedia.nl', -} + # static dictionary + MAIL_EDITOR_BASE_CONTEXT = { + 'url': 'http://www.maykinmedia.nl', + } -# import path to callable that returns a dictionary -MAIL_EDITOR_DYNAMIC_CONTEXT = "dotted.path.to.callable" + # import path to callable that returns a dictionary + MAIL_EDITOR_DYNAMIC_CONTEXT = "dotted.path.to.callable" Installation @@ -180,6 +180,29 @@ Install with pip: pip install mail_editor +Local development +----------------- + +To install and develop the library locally, use:: + +.. code-block:: bash + + pip install -e .[tests,coverage,docs,release] + +When running management commands via ``django-admin``, make sure to add the root +directory to the python path (or use ``python -m django ``): + +.. code-block:: bash + + export PYTHONPATH=. DJANGO_SETTINGS_MODULE=testapp.settings + django-admin check + # or other commands like: + django-admin migrate + django-admin createsuperuser + django-admin runserver + # django-admin makemessages -l nl + + .. _Django Yubin: https://github.com/APSL/django-yubin .. _Sergei Maertens: https://github.com/sergei-maertens .. _langerak-gkv: https://github.com/sergei-maertens/langerak-gkv/blob/master/src/langerak_gkv/mailing/mail_template.py diff --git a/fix.sh b/fix.sh index 6499bcf..6ac6dfb 100755 --- a/fix.sh +++ b/fix.sh @@ -8,3 +8,7 @@ isort --profile black ./tests autoflake --in-place --remove-all-unused-imports -r ./tests black ./tests + +isort --profile black ./testapp +autoflake --in-place --remove-all-unused-imports -r ./testapp +black ./testapp diff --git a/pyproject.toml b/pyproject.toml index 29da416..2bf54fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,7 +79,7 @@ sections=["FUTURE", "STDLIB", "DJANGO", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER [tool.pytest.ini_options] testpaths = ["tests"] -DJANGO_SETTINGS_MODULE = "tests.settings" +DJANGO_SETTINGS_MODULE = "testapp.settings" [tool.bumpversion] current_version = "0.3.5" diff --git a/testapp/__init__.py b/testapp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/media/logo.jpg b/testapp/media/logo.jpg similarity index 100% rename from tests/media/logo.jpg rename to testapp/media/logo.jpg diff --git a/tests/settings.py b/testapp/settings.py similarity index 90% rename from tests/settings.py rename to testapp/settings.py index 49ed34b..5c5e648 100644 --- a/tests/settings.py +++ b/testapp/settings.py @@ -4,11 +4,15 @@ SECRET_KEY = "supersekrit" +USE_TZ = True + +DEBUG = True + DATABASES = { "default": { # Memory resident database, for easy testing. "ENGINE": "django.db.backends.sqlite3", - "NAME": ":memory:", + "NAME": os.path.join(DJANGO_PROJECT_DIR, "mail_editor.db"), } } @@ -20,11 +24,12 @@ "django.contrib.admin", "mail_editor", "ckeditor", + "testapp", ] EMAIL_BACKEND = "django.core.mail.backends.dummy.EmailBackend" -ROOT_URLCONF = "tests.urls" +ROOT_URLCONF = "testapp.urls" MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", @@ -77,7 +82,6 @@ "models.W042", # AutoField warning not relevant for tests ] - STATICFILES_DIRS = [ os.path.join(DJANGO_PROJECT_DIR, "static"), os.path.join(DJANGO_PROJECT_DIR, "static_alternative"), @@ -90,6 +94,6 @@ "django.contrib.staticfiles.finders.AppDirectoriesFinder", ] STATIC_URL = "/static/" -STATIC_ROOT = os.path.join(os.path.dirname(__file__), "static") +STATIC_ROOT = os.path.join(DJANGO_PROJECT_DIR, "static") MEDIA_URL = "/media/" -MEDIA_ROOT = os.path.join(os.path.dirname(__file__), "media") +MEDIA_ROOT = os.path.join(DJANGO_PROJECT_DIR, "media") diff --git a/tests/static/css/style.css b/testapp/static/css/style.css similarity index 100% rename from tests/static/css/style.css rename to testapp/static/css/style.css diff --git a/tests/static/logo.png b/testapp/static/logo.png similarity index 100% rename from tests/static/logo.png rename to testapp/static/logo.png diff --git a/tests/static_alternative/logo_copy.png b/testapp/static_alternative/logo_copy.png similarity index 100% rename from tests/static_alternative/logo_copy.png rename to testapp/static_alternative/logo_copy.png diff --git a/testapp/urls.py b/testapp/urls.py new file mode 100644 index 0000000..64ef82a --- /dev/null +++ b/testapp/urls.py @@ -0,0 +1,13 @@ +from django.conf import settings +from django.conf.urls.static import static +from django.contrib import admin +from django.contrib.staticfiles.urls import staticfiles_urlpatterns +from django.urls import include, path + +urlpatterns = [ + path("maileditor/", include("mail_editor.urls")), + path("admin/", admin.site.urls), +] +urlpatterns += staticfiles_urlpatterns() + static( + settings.MEDIA_URL, document_root=settings.MEDIA_ROOT +) diff --git a/tests/manage.py b/tests/manage.py deleted file mode 100644 index 06531a2..0000000 --- a/tests/manage.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env python -import os -import sys - -if __name__ == "__main__": - os.environ["DJANGO_SETTINGS_MODULE"] = "settings" - - from django.core.management import execute_from_command_line - - execute_from_command_line(sys.argv) diff --git a/tests/urls.py b/tests/urls.py deleted file mode 100644 index ba2bb81..0000000 --- a/tests/urls.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.contrib import admin -from django.urls import include, path - -urlpatterns = [ - path("maileditor/", include("mail_editor.urls")), - path("admin/", admin.site.urls), -] diff --git a/tox.ini b/tox.ini index fd3f690..97725aa 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,7 @@ DJANGO = [testenv] setenv = - DJANGO_SETTINGS_MODULE=tests.settings + DJANGO_SETTINGS_MODULE=testapp.settings PYTHONPATH={toxinidir} extras = tests @@ -40,7 +40,7 @@ commands = isort --check-only --diff . [testenv:black] extras = tests skipsdist = True -commands = black --check mail_editor tests +commands = black --check mail_editor tests testapp [testenv:flake8] extras = tests