Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-pettinga committed Dec 18, 2024
2 parents fe4cd76 + 5de67c2 commit 4c381a0
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

class LicensingGroundsView(BaseFormView):
form_class = forms.LicensingGroundsForm
success_url = reverse_lazy("purpose_of_provision")
redirect_after_post = False

def get_form_kwargs(self):
Expand Down
13 changes: 13 additions & 0 deletions django_app/config/env.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# mypy: disable-error-code="attr-defined,misc"
import os
import subprocess

from dbt_copilot_python.database import database_url_from_env
from dbt_copilot_python.network import setup_allowed_hosts
Expand Down Expand Up @@ -80,6 +81,9 @@ class BaseSettings(PydanticBaseSettings):
csp_report_only: bool = True
csp_report_uri: str | None = None

current_branch: str = Field(alias="GIT_BRANCH", default="unknown")
current_tag: str = Field(alias="GIT_TAG", default="")

@computed_field
@property
def redis_url(self) -> str:
Expand Down Expand Up @@ -114,6 +118,15 @@ class LocalSettings(BaseSettings):
profiling_enabled: bool = False
localstack_port: int = 24566

@computed_field
@property
def git_current_branch(self) -> str:
current_branch = subprocess.run(["git", "branch", "--show-current"], capture_output=True)
if current_branch.returncode == 0:
return current_branch.stdout.decode("utf-8").replace("\n", "")
else:
return "unknown"


class TestSettings(LocalSettings):
headless: bool = False
Expand Down
5 changes: 5 additions & 0 deletions django_app/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
"core.context_processors.back_button",
"core.context_processors.session_expiry_times",
"core.context_processors.sentry_configuration_options",
"core.context_processors.environment_information",
],
},
},
Expand Down Expand Up @@ -352,3 +353,7 @@
"payment": [],
"usb": [],
}

# Information about the current environment
CURRENT_BRANCH = env.current_branch
CURRENT_TAG = env.current_tag
2 changes: 2 additions & 0 deletions django_app/config/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@
os.environ["AWS_ENDPOINT_URL"] = f"http://localhost:{env.localstack_port}"

PROTOCOL = "http://"

CURRENT_BRANCH = env.git_current_branch
9 changes: 9 additions & 0 deletions django_app/core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ def sentry_configuration_options(request: HttpRequest) -> dict[str, str | float]
"SENTRY_ENABLE_TRACING": settings.SENTRY_ENABLE_TRACING,
"SENTRY_TRACES_SAMPLE_RATE": settings.SENTRY_TRACES_SAMPLE_RATE,
}


def environment_information(request: HttpRequest) -> dict[str, str]:
"""Add the current environment & branch to the context."""
return {
"current_environment": settings.ENVIRONMENT,
"current_branch": settings.CURRENT_BRANCH,
"current_tag": settings.CURRENT_TAG,
}
23 changes: 19 additions & 4 deletions django_app/core/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,19 @@ <h2 class="govuk-cookie-banner__heading govuk-heading-m">
{% block skip_link %}
<a href="#main-content" class="govuk-skip-link">{% trans 'Skip to main content' %}</a>
{% endblock %}

{% if current_environment != "production" and is_debug_mode %}
<div class="govuk-phase-banner hide-on-print" data-testid="environment_banner" style="background-color: orange;">
<p class="govuk-phase-banner__content" style="margin: 0 auto;">
<span class="govuk-phase-banner__text">
Environment: <strong>{{ current_environment }}</strong><br>
Branch: <strong>{{ current_branch }}</strong><br>
{% if current_tag %}
Tag: <strong>{{ current_tag }}</strong>
{% endif %}
</span>
</p>
</div>
{% endif %}
<header class="govuk-header" role="banner" data-module="govuk-header">
<div class="govuk-header__container govuk-width-container">
<div class="govuk-header__logo hide-on-print">
Expand Down Expand Up @@ -197,7 +209,8 @@ <h2 class="govuk-cookie-banner__heading govuk-heading-m">
{# don't show the feedback text whilst on a feedback page #}
{% if request.resolver_match.app_name != "feedback" %}
– your
<a class="govuk-link" data-testid="collect_feedback_link" target="_blank" href="{% url 'feedback:collect_full_feedback' %}?url={{ request.get_full_path|urlencode }}">feedback</a>
<a class="govuk-link" data-testid="collect_feedback_link" target="_blank"
href="{% url 'feedback:collect_full_feedback' %}?url={{ request.get_full_path|urlencode }}">feedback</a>
will help us to improve it (opens in a new tab).
{% endif %}
</span>
Expand Down Expand Up @@ -249,7 +262,8 @@ <h2 class="govuk-cookie-banner__heading govuk-heading-m">
<h2 class="govuk-visually-hidden">Support links</h2>
<ul class="govuk-footer__inline-list">
<li class="govuk-footer__inline-list-item hide-on-print">
<a class="govuk-footer__link" href="{% url 'cookies_consent' %}?redirect_back_to={{ request.get_full_path|urlencode }}">Cookies</a>
<a class="govuk-footer__link"
href="{% url 'cookies_consent' %}?redirect_back_to={{ request.get_full_path|urlencode }}">Cookies</a>
</li>
<li class="govuk-footer__inline-list-item hide-on-print">
<a class="govuk-footer__link"
Expand Down Expand Up @@ -295,7 +309,8 @@ <h2 class="govuk-visually-hidden">Support links</h2>
</div>
</div>
<script src="{% static 'core/javascript/jquery-3.7.1.js' %}" nonce="{{ request.csp_nonce }}"></script>
<script type="module" src="{% static "core/javascript/govuk-frontend-5.3.0.min.js" %}" nonce="{{ request.csp_nonce }}"></script>
<script type="module" src="{% static "core/javascript/govuk-frontend-5.3.0.min.js" %}"
nonce="{{ request.csp_nonce }}"></script>
<script type="module" nonce="{{ request.csp_nonce }}">
import {initAll} from "{% static "core/javascript/govuk-frontend-5.3.0.min.js" %}"

Expand Down
2 changes: 1 addition & 1 deletion tests/test_frontend/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def licensing_grounds_simple(self, page):

# now we're on the upload documents page
expect(page).to_have_url(re.compile(r".*/upload-documents"))
page.get_by_test_id("upload-documents-continue").click()
page.get_by_role("button", name="Continue").click()


@pytest.fixture(autouse=True)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_frontend/fixtures/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@
"county": "County",
"country": "DE",
}

LEGAL_GROUNDS_HEADERS = {
"legal_only": "Which of these licensing grounds describes the purpose of the relevant activity for which the "
"legal advice is being given? - Apply for a licence to provide sanctioned trade services - GOV.UK",
"legal_excluded": "For the other services you want to provide (excluding legal advisory), which of these "
"licensing grounds describes your purpose for providing them? - Apply for a licence to "
"provide sanctioned trade services - GOV.UK",
"non_legal": "Which of these licensing grounds describes your purpose for providing the sanctioned services? - "
"Apply for a licence to provide sanctioned trade services - GOV.UK",
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
RecipientBase,
StartBase,
)
from tests.test_frontend.fixtures.data import LEGAL_GROUNDS_HEADERS


class TestLicensingGrounds(StartBase, ProviderBase, RecipientBase, LicensingGroundsBase):
Expand All @@ -24,6 +25,13 @@ def test_legal(self):
expect(self.page).to_have_url(re.compile(r".*/add-recipient"))
self.no_more_additions(self.page)
expect(self.page).to_have_url(re.compile(r".*/licensing-grounds"))
expect(self.page).to_have_title(LEGAL_GROUNDS_HEADERS["legal_only"])
self.page.get_by_label("Civil society activities that").check()
self.page.get_by_role("button", name="Continue").click()
expect(self.page).to_have_url(re.compile(r".*/services-purpose"))
self.page.get_by_label("What is your purpose").fill("test")
self.page.get_by_role("button", name="Continue").click()
expect(self.page).to_have_url(re.compile(r".*/upload-documents"))

def test_non_legal(self):
self.page.goto(self.base_url)
Expand All @@ -36,6 +44,13 @@ def test_non_legal(self):
expect(self.page).to_have_url(re.compile(r".*/add-recipient"))
self.no_more_additions(self.page)
expect(self.page).to_have_url(re.compile(r".*/licensing-grounds"))
expect(self.page).to_have_title(LEGAL_GROUNDS_HEADERS["non_legal"])
self.page.get_by_label("The delivery of humanitarian").check()
self.page.get_by_role("button", name="Continue").click()
expect(self.page).to_have_url(re.compile(r".*/services-purpose"))
self.page.get_by_label("What is your purpose").fill("test")
self.page.get_by_role("button", name="Continue").click()
expect(self.page).to_have_url(re.compile(r".*/upload-documents"))

def test_legal_and_other(self):
self.page.goto(self.base_url)
Expand All @@ -48,6 +63,14 @@ def test_legal_and_other(self):
expect(self.page).to_have_url(re.compile(r".*/add-recipient"))
self.no_more_additions(self.page)
expect(self.page).to_have_url(re.compile(r".*/licensing-grounds"))
expect(self.page).to_have_title(LEGAL_GROUNDS_HEADERS["legal_only"])
self.page.get_by_label("Civil society activities that").check()
self.page.get_by_role("button", name="Continue").click()
expect(self.page).to_have_url(re.compile(r".*/other-licensing-grounds"))
expect(self.page).to_have_title(LEGAL_GROUNDS_HEADERS["legal_excluded"])
self.page.get_by_label("The delivery of humanitarian").check()
self.page.get_by_role("button", name="Continue").click()
expect(self.page).to_have_url(re.compile(r".*/services-purpose"))
self.page.get_by_label("What is your purpose").fill("test")
self.page.get_by_role("button", name="Continue").click()
expect(self.page).to_have_url(re.compile(r".*/upload-documents"))
31 changes: 31 additions & 0 deletions tests/test_frontend/test_core/test_environment_banner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.test import override_settings
from playwright.sync_api import expect

from tests.test_frontend.conftest import PlaywrightTestBase


class TestEnvironmentBanner(PlaywrightTestBase):
"""Tests the non-production banner appears"""

@override_settings(ENVIRONMENT="production", DEBUG=False)
def test_banner_does_not_appear_on_production(self):
self.page.goto(self.base_url)
expect(self.page.get_by_test_id("environment_banner")).to_be_hidden()

@override_settings(ENVIRONMENT="production", DEBUG=True)
def test_banner_does_not_appear_debug_true(self):
self.page.goto(self.base_url)
expect(self.page.get_by_test_id("environment_banner")).to_be_hidden()

@override_settings(ENVIRONMENT="local", DEBUG=True)
def test_banner_appears(self):
self.page.goto(self.base_url)
expect(self.page.get_by_test_id("environment_banner")).to_be_visible()
expect(self.page.get_by_text("Environment: local")).to_be_visible()

@override_settings(ENVIRONMENT="local", DEBUG=True, CURRENT_BRANCH="test-branch", CURRENT_TAG="v1.0.0")
def test_banner_content(self):
self.page.goto(self.base_url)
expect(self.page.get_by_text("Environment: local")).to_be_visible()
expect(self.page.get_by_text("Branch: test-branch")).to_be_visible()
expect(self.page.get_by_text("Tag: v1.0.0")).to_be_visible()
19 changes: 18 additions & 1 deletion tests/test_unit/test_core/text_context_processors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from core.context_processors import sentry_configuration_options, session_expiry_times
from core.context_processors import (
environment_information,
sentry_configuration_options,
session_expiry_times,
)
from django.test import override_settings


Expand Down Expand Up @@ -26,3 +30,16 @@ def test_sentry_configuration_options(request_object):
"SENTRY_ENABLE_TRACING": False,
"SENTRY_TRACES_SAMPLE_RATE": 0.0,
}


@override_settings(
ENVIRONMENT="test",
CURRENT_BRANCH="test-branch",
CURRENT_TAG="v1.0.0",
)
def test_environment_information(request_object):
assert environment_information(request_object) == {
"current_environment": "test",
"current_branch": "test-branch",
"current_tag": "v1.0.0",
}

0 comments on commit 4c381a0

Please sign in to comment.