Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header redirect to GOV.UK #148

Merged
merged 2 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/categories/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import session, url_for, render_template
from flask import url_for, render_template
from app.categories import bp
from app.categories.views import CategoryPage
from app.categories.constants import (
Expand Down Expand Up @@ -31,12 +31,12 @@ def dispatch_request(self):
(ASYLUM_AND_IMMIGRATION, url_for("categories.asylum_immigration.landing")),
(MENTAL_CAPACITY, url_for("categories.mental_capacity.landing")),
]
session.clear()
return render_template(self.template, listing=listing)


bp.add_url_rule(
"/", view_func=IndexPage.as_view("index", template="categories/index.html")
"/find-your-problem",
view_func=IndexPage.as_view("index", template="categories/index.html"),
)
bp.add_url_rule(
"/more-problems",
Expand Down
3 changes: 3 additions & 0 deletions app/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

class Config(object):
ENVIRONMENT = os.environ.get("CLA_ENVIRONMENT", "production")
GOV_UK_START_PAGE = os.environ.get(
"GOV_UK_START_PAGE", "https://www.gov.uk/check-legal-aid"
)
CONTACT_EMAIL = os.environ.get("CONTACT_EMAIL", "")
CONTACT_PHONE = os.environ.get("CONTACT_PHONE", "")
DEPARTMENT_NAME = os.environ.get("DEPARTMENT_NAME", "MOJ Digital")
Expand Down
14 changes: 10 additions & 4 deletions app/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@
from app.main.forms import CookiesForm


@bp.get("/main")
def index():
return redirect(url_for("categories.index"))
@bp.get("/")
def start_page():
"""Directs the user to the start page of the service, hosted on GOV.UK
This is the endpoint directed to from the header text, clicking this link will reset the users' session.
"""
session.clear()
if current_app.config.get("CLA_ENVIRONMENT") != "production":
return redirect(url_for("categories.index"))
return redirect(current_app.config.get("GOV_UK_START_PAGE"))


@bp.get("/start")
Expand Down Expand Up @@ -96,7 +102,7 @@ def status():
@bp.route("/service-unavailable", methods=["GET"])
def service_unavailable_page():
if not current_app.config["SERVICE_UNAVAILABLE"]:
return redirect(url_for("main.index"))
return redirect(url_for("categories.index"))
abort(503)


Expand Down
8 changes: 4 additions & 4 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@

{% block header %}
{{ govukHeader({
'homepageUrl': url_for('categories.index'),
'serviceName': config['SERVICE_NAME'],
'serviceUrl': url_for('categories.index'),
'useTudorCrown': true
'homepageUrl': "https://www.gov.uk",
'serviceName': config['SERVICE_NAME'],
'serviceUrl': url_for('main.start_page'),
'useTudorCrown': true
}) }}
{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion app/templates/main/session_expired.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1 class="govuk-heading-l">{% trans %}You’ve reached the end of this service{
<p class="govuk-body">{% trans %}You can start again below.{% endtrans %}</p>
{{ govukButton({
"text": _("Start again"),
"href": url_for("main.index"),
"href": url_for("main.start_page"),
"isStartButton": true
}) }}
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/functional_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ def runner(app):

@pytest.fixture(scope="function", autouse=True)
def startup(app, page):
page.goto(url_for("main.index", _external=True))
page.goto(url_for("categories.index", _external=True))
16 changes: 16 additions & 0 deletions tests/functional_tests/test_header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest
from playwright.sync_api import Page, expect


@pytest.mark.usefixtures("live_server")
def test_service_url(page: Page):
expect(page.get_by_role("link", name="Access Civil Legal Aid")).to_have_attribute(
"href", value="/"
)


@pytest.mark.usefixtures("live_server")
def test_gov_uk_url(page: Page):
expect(page.get_by_role("link", name="GOV.UK")).to_have_attribute(
"href", "https://www.gov.uk"
)
2 changes: 1 addition & 1 deletion tests/unit_tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def test_filter_category_url(app):
with app.app_context():
# url is a string
assert category_url_for("categories.index") == "/"
assert category_url_for("categories.index") == "/find-your-problem"
endpoint = {
"endpoint": "find-a-legal-adviser.search",
"category": "mhe",
Expand Down
12 changes: 11 additions & 1 deletion tests/unit_tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ def test_service_unavailable_off(app, client):
app.config["SERVICE_UNAVAILABLE"] = False
response = client.get("/service-unavailable", follow_redirects=True)
assert response.status_code == 200
assert response.request.path == "/"
assert response.request.path == "/find-your-problem"


def test_header_link_clears_session(app, client):
with client.session_transaction() as session:
session["test"] = "test"

client.get("/")

with client.session_transaction() as session:
assert "test" not in session
Loading