{% block messages %} {% if messages %} diff --git a/lacommunaute/utils/enums.py b/lacommunaute/utils/enums.py index a3f452bb8..8fc3a6dea 100644 --- a/lacommunaute/utils/enums.py +++ b/lacommunaute/utils/enums.py @@ -4,3 +4,8 @@ class PeriodAggregation(models.TextChoices): MONTH = "MONTH" WEEK = "WEEK" + + +class Environment(models.TextChoices): + DEV = "DEV" + PROD = "PROD" diff --git a/lacommunaute/utils/settings_context_processors.py b/lacommunaute/utils/settings_context_processors.py index 9469a4a09..7427c13d4 100644 --- a/lacommunaute/utils/settings_context_processors.py +++ b/lacommunaute/utils/settings_context_processors.py @@ -12,4 +12,5 @@ def expose_settings(request): "BASE_TEMPLATE": base_template, "MATOMO_SITE_ID": settings.MATOMO_SITE_ID, "MATOMO_BASE_URL": settings.MATOMO_BASE_URL, + "ENVIRONMENT": settings.ENVIRONMENT, } diff --git a/lacommunaute/utils/tests/tests_middleware.py b/lacommunaute/utils/tests/tests_middleware.py index 40573b400..5313ce39a 100644 --- a/lacommunaute/utils/tests/tests_middleware.py +++ b/lacommunaute/utils/tests/tests_middleware.py @@ -1,5 +1,8 @@ +import pytest from django.test import TestCase, override_settings +from lacommunaute.utils.enums import Environment + class ParkingMiddlewareTest(TestCase): @override_settings(PARKING_PAGE=True) @@ -13,3 +16,17 @@ def test_no_parking_page_middleware(self): response = self.client.get("/") self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "pages/home.html") + + +class TestEnvironmentSettingsMiddleware: + @pytest.mark.parametrize( + "env,expected", + [ + (Environment.PROD, False), + (Environment.DEV, True), + ], + ) + def test_prod_environment(self, client, db, env, expected): + with override_settings(ENVIRONMENT=env): + response = client.get("/") + assert ('id="debug-mode-banner"' in response.content.decode()) == expected From 7be6ee2ac4e973b233bf562520e4436e22f69113 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Wed, 20 Nov 2024 16:34:36 +0100 Subject: [PATCH 3/3] =?UTF-8?q?display=20magic=20link=20in=20messages=20in?= =?UTF-8?q?=20DEV=C2=A0env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/__snapshots__/tests_views.ambr | 7 ++- lacommunaute/users/tests/tests_views.py | 48 +++++++++++++------ lacommunaute/users/views.py | 12 +++-- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/lacommunaute/users/tests/__snapshots__/tests_views.ambr b/lacommunaute/users/tests/__snapshots__/tests_views.ambr index 385e7a69d..23905b0dc 100644 --- a/lacommunaute/users/tests/__snapshots__/tests_views.ambr +++ b/lacommunaute/users/tests/__snapshots__/tests_views.ambr @@ -527,6 +527,9 @@