From 714935a8d0570cb4d64dfd7e7e4558792236e8a2 Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Wed, 19 Jun 2024 02:06:54 +0200 Subject: [PATCH] Add tests for Django templates --- pyproject.toml | 4 ++++ tests/test_project/settings.py | 22 ++++++++++++++++++++++ tests/test_templates.py | 33 +++++++++++++++++++++++++++++++++ tox.ini | 7 +++++-- 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 tests/test_project/settings.py create mode 100644 tests/test_templates.py diff --git a/pyproject.toml b/pyproject.toml index 601d361..fb556c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,10 @@ source = "https://github.com/bittner/django-bootstrap-static" [tool.pytest.ini_options] addopts = "--color=yes --doctest-modules --verbose" +python_files = ["tests.py", "test_*.py", "*_tests.py"] +pythonpath = ["tests"] +DJANGO_SETTINGS_MODULE = "test_project.settings" +FAIL_INVALID_TEMPLATE_VARS = true [tool.ruff] extend-exclude = [] diff --git a/tests/test_project/settings.py b/tests/test_project/settings.py new file mode 100644 index 0000000..1426cf4 --- /dev/null +++ b/tests/test_project/settings.py @@ -0,0 +1,22 @@ +"""Minimal Django settings for test project.""" + +INSTALLED_APPS = [ + "django.contrib.staticfiles", + "bootstrap", + "fontawesome", +] + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.request", + ], + }, + }, +] + +STATIC_URL = "static" diff --git a/tests/test_templates.py b/tests/test_templates.py new file mode 100644 index 0000000..beaf59b --- /dev/null +++ b/tests/test_templates.py @@ -0,0 +1,33 @@ +"""Tests for Django templates.""" + +from django.template import Context, Template + +template = """ + {% load static %} + + + + + + ... + + + +""" + + +def test_template(): + """Importing the package should work as described in the README.""" + bootstrap_min_css = "bootstrap/css/bootstrap.min.css" + bootstrap_min_js = "bootstrap/js/bootstrap.bundle.min.js" + fontawesome_min_js = "fontawesome/js/all.min.js" + jquery_min_js = "bootstrap/js/jquery.min.js" + + c = Context() + t = Template(template) + html = t.render(c) + + assert f'' in html + assert f'' in html + assert f'' in html + assert f'' in html diff --git a/tox.ini b/tox.ini index f317465..ebbfe7a 100644 --- a/tox.ini +++ b/tox.ini @@ -6,8 +6,11 @@ envlist = [testenv] description = Unit tests and test coverage -deps = pytest -commands = pytest {posargs} +deps = + django + pytest-django +commands = + pytest {posargs} [testenv:clean] description = Remove bytecode and other debris