Skip to content

Commit

Permalink
display ENV banner anywhere except in PROD
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Jan 16, 2025
1 parent 8979bff commit f86dcca
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
16 changes: 9 additions & 7 deletions lacommunaute/templates/layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@
</li>
</ul>
</nav>
{% if ENVIRONMENT == "DEV" %}
<div class="global-messages-container" id="debug-mode-banner">
<div class="alert alert-danger fade show" role="status">
<p class="mb-0">
<strong class="text-uppercase">DEV MODE</strong>
</p>
{% if ENVIRONMENT %}
{% if ENVIRONMENT != "PROD" %}
<div class="global-messages-container" id="debug-mode-banner">
<div class="alert alert-danger fade show" role="status">
<p class="mb-0">
<strong class="text-uppercase">{{ ENVIRONMENT }} MODE</strong>
</p>
</div>
</div>
</div>
{% endif %}
{% endif %}
{% block header %}
{% include "partials/header.html" %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# serializer version: 1
# name: test_prod_environment[DEV-True][Dev]
'''
<div class="global-messages-container" id="debug-mode-banner">
<div class="alert alert-danger fade show" role="status">
<p class="mb-0">
<strong class="text-uppercase">DEV MODE</strong>
</p>
</div>
</div>
'''
# ---
# name: test_prod_environment[TEST-True][Test]
'''
<div class="global-messages-container" id="debug-mode-banner">
<div class="alert alert-danger fade show" role="status">
<p class="mb-0">
<strong class="text-uppercase">TEST MODE</strong>
</p>
</div>
</div>
'''
# ---
9 changes: 7 additions & 2 deletions lacommunaute/utils/tests/tests_context_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
from django.test import override_settings

from lacommunaute.utils.enums import Environment
from lacommunaute.utils.testing import parse_response_to_soup


@pytest.mark.parametrize(
"env,expected",
[
(None, False),
(Environment.PROD, False),
(Environment.TEST, False),
(Environment.TEST, True),
(Environment.DEV, True),
],
)
def test_prod_environment(client, db, env, expected):
def test_prod_environment(client, db, env, expected, snapshot):
with override_settings(ENVIRONMENT=env):
response = client.get("/")
assert ('id="debug-mode-banner"' in response.content.decode()) == expected
if expected:
content = parse_response_to_soup(response, selector="#debug-mode-banner")
assert str(content) == snapshot(name=env.label)


def test_exposed_settings(client, db):
Expand Down

0 comments on commit f86dcca

Please sign in to comment.