From c621abe8f6bcd369c7b260df56441157c63aa11d Mon Sep 17 00:00:00 2001 From: Bryan Brancotte <bryan.brancotte@pasteur.fr> Date: Fri, 28 Feb 2025 18:35:26 +0100 Subject: [PATCH] test context processor --- setup.cfg | 2 +- tests/settings.py | 3 --- tests/templates/tests/foo.html | 5 +++++ tests/tests.py | 23 +++++++++++++++++++++++ tests/urls.py | 2 ++ 5 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 tests/templates/tests/foo.html create mode 100644 tests/tests.py diff --git a/setup.cfg b/setup.cfg index 2552bd3..296070f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = django-live-settings -version = 1.0 +version = 1.0.1 description = A Django app to have some settings stored in db, and editable at runtime long_description = file: README.rst author = Bryan Brancotte diff --git a/tests/settings.py b/tests/settings.py index c0fb94b..7da0b97 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -47,9 +47,6 @@ TEMPLATES = [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', - 'basetheme_bootstrap.context_processors.processors', - 'strass_app.context_processors.enrich_with_status', - 'strass_app.context_processors.add_google_analytics_tracker', "live_settings.context_processors.processors", ], }, diff --git a/tests/templates/tests/foo.html b/tests/templates/tests/foo.html new file mode 100644 index 0000000..2973957 --- /dev/null +++ b/tests/templates/tests/foo.html @@ -0,0 +1,5 @@ +{%if live_settings.blabla__int == 0 %} +IS_0 +{%else%} +IS_NONE +{%endif%} \ No newline at end of file diff --git a/tests/tests.py b/tests/tests.py new file mode 100644 index 0000000..58d8ec6 --- /dev/null +++ b/tests/tests.py @@ -0,0 +1,23 @@ +import logging + +from django.test import TestCase as DjangoTestCase +from django.urls import reverse + +from live_settings import live_settings + +logger = logging.getLogger(__name__) + + +class LiveSettingsTestCase(DjangoTestCase): + + def test_view_works(self): + url = reverse('foo') + + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + self.assertIn("IS_NONE", str(response.content)) + self.assertNotIn("IS_0", str(response.content)) + live_settings.blabla=0 + response = self.client.get(url) + self.assertIn("IS_0", str(response.content)) + self.assertNotIn("IS_NONE", str(response.content)) \ No newline at end of file diff --git a/tests/urls.py b/tests/urls.py index fe64af6..d97c67c 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -1,5 +1,7 @@ from django.urls import path, include +from django.views.generic import TemplateView urlpatterns = [ path('live_settings/', include("live_settings.urls")), + path('foo/', TemplateView.as_view(template_name='tests/foo.html'), name='foo'), ] -- GitLab