diff --git a/.circleci/config.yml b/.circleci/config.yml index 68486565..6d3d7791 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -132,6 +132,7 @@ jobs: # we don't run frontend tests with coverage as only unit tests should affect coverage command: | sudo tee -a /etc/hosts \<<<'127.0.0.1 apply-for-a-licence' + sudo tee -a /etc/hosts \<<<'127.0.0.1 view-a-licence' pipenv run playwright install --with-deps firefox pipenv run pytest tests/test_frontend --browser firefox --junitxml=test-results/frontend/results.xml --create-db diff --git a/django_app/apply_for_a_licence/templates/apply_for_a_licence/form_steps/check_your_answers.html b/django_app/apply_for_a_licence/templates/apply_for_a_licence/form_steps/check_your_answers.html index 427fa08e..16f4cfbc 100644 --- a/django_app/apply_for_a_licence/templates/apply_for_a_licence/form_steps/check_your_answers.html +++ b/django_app/apply_for_a_licence/templates/apply_for_a_licence/form_steps/check_your_answers.html @@ -431,7 +431,7 @@

Purpose of the services

{% if form_data.licensing_grounds %}
- {% if form_data.professional_or_business_services.professional_or_business_service|length == 1 and form_data.professional_or_business_services.professional_or_business_service|first == 'legal_advisory' %} + {% if form_data.professional_or_business_services.professional_or_business_services|length == 1 and form_data.professional_or_business_services.professional_or_business_services|first == 'legal_advisory' %}
Licensing grounds for the relevant activity
{% else %}
Licensing grounds
diff --git a/django_app/view_a_licence/templates/view_a_licence/view_a_licence_application.html b/django_app/view_a_licence/templates/view_a_licence/view_a_licence_application.html index 7d41b18d..02a2cb74 100644 --- a/django_app/view_a_licence/templates/view_a_licence/view_a_licence_application.html +++ b/django_app/view_a_licence/templates/view_a_licence/view_a_licence_application.html @@ -264,7 +264,7 @@

Recipient {{ forloop.counter }}

Purpose of the services

-
+
Licensing grounds
@@ -276,8 +276,8 @@

Purpose of the services

{% endfor %}
- {% if form_data.licensing_grounds_legal_advisory %} -
+ {% if licence.licensing_grounds_legal_advisory %} +
Licensing grounds (excluding legal advisory)
diff --git a/tests/conftest.py b/tests/conftest.py index 3c3a4dd3..ecbf9ecf 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,6 +3,7 @@ from django.conf import settings from django.contrib.auth.models import User from django.contrib.sites.models import Site +from django.db import IntegrityError from django.test import Client, RequestFactory from django.utils import timezone @@ -36,12 +37,15 @@ def vl_client(db) -> Client: @pytest.fixture() def staff_user(db): - return User.objects.create_user( - "staff", - "staff@example.com", - is_active=True, - is_staff=True, - ) + try: + return User.objects.create_user( + "staff", + "staff@example.com", + is_active=True, + is_staff=True, + ) + except IntegrityError: + return User.objects.get(username="staff") @pytest.fixture() diff --git a/tests/test_frontend/test_apply_for_a_licence/test_cya_change/__init__.py b/tests/test_frontend/test_apply_for_a_licence/test_cya/__init__.py similarity index 100% rename from tests/test_frontend/test_apply_for_a_licence/test_cya_change/__init__.py rename to tests/test_frontend/test_apply_for_a_licence/test_cya/__init__.py diff --git a/tests/test_frontend/test_apply_for_a_licence/test_cya_change/test_cya_change.py b/tests/test_frontend/test_apply_for_a_licence/test_cya/test_cya_change.py similarity index 100% rename from tests/test_frontend/test_apply_for_a_licence/test_cya_change/test_cya_change.py rename to tests/test_frontend/test_apply_for_a_licence/test_cya/test_cya_change.py diff --git a/tests/test_frontend/test_apply_for_a_licence/test_cya_change/test_cya_remove.py b/tests/test_frontend/test_apply_for_a_licence/test_cya/test_cya_remove.py similarity index 100% rename from tests/test_frontend/test_apply_for_a_licence/test_cya_change/test_cya_remove.py rename to tests/test_frontend/test_apply_for_a_licence/test_cya/test_cya_remove.py diff --git a/tests/test_frontend/test_view_a_licence/__init__.py b/tests/test_frontend/test_view_a_licence/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_frontend/test_view_a_licence/conftest.py b/tests/test_frontend/test_view_a_licence/conftest.py new file mode 100644 index 00000000..ea03bf79 --- /dev/null +++ b/tests/test_frontend/test_view_a_licence/conftest.py @@ -0,0 +1,25 @@ +import pytest +from django.conf import settings + +from tests.test_frontend.conftest import PlaywrightTestBase as BasePlaywrightTestBase + + +class PlaywrightTestBase(BasePlaywrightTestBase): + @property + def base_host(self) -> str: + return settings.VIEW_A_LICENCE_DOMAIN.split(":")[0] + + +@pytest.fixture(autouse=True, scope="function") +def bypass_login(monkeypatch, staff_user): + """Overrides the get_user function to always return the staff user without authentication. + + Effectively bypasses the login process for all frontend tests. + """ + + def patched_get_user(request): + return staff_user + + monkeypatch.setattr("django.contrib.auth.get_user", patched_get_user) + + yield diff --git a/tests/test_frontend/test_view_a_licence/test_views/__init__.py b/tests/test_frontend/test_view_a_licence/test_views/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_frontend/test_view_a_licence/test_views/test_view_a_licence_application_view.py b/tests/test_frontend/test_view_a_licence/test_views/test_view_a_licence_application_view.py new file mode 100644 index 00000000..1c49a499 --- /dev/null +++ b/tests/test_frontend/test_view_a_licence/test_views/test_view_a_licence_application_view.py @@ -0,0 +1,48 @@ +from apply_for_a_licence.choices import ( + LicensingGroundsChoices, + ProfessionalOrBusinessServicesChoices, + TypeOfServicesChoices, + WhoDoYouWantTheLicenceToCoverChoices, +) +from django.urls import reverse +from playwright.sync_api import expect + +from tests.factories import LicenceFactory +from tests.test_frontend.test_view_a_licence.conftest import PlaywrightTestBase + + +class TestViewALicenceApplicationView(PlaywrightTestBase): + def test_legal_grounds_legal_advisory(self): + licence = LicenceFactory.create( + who_do_you_want_the_licence_to_cover=WhoDoYouWantTheLicenceToCoverChoices.business.value, + type_of_service=TypeOfServicesChoices.professional_and_business.value, + professional_or_business_services=[ + ProfessionalOrBusinessServicesChoices.legal_advisory.value, + ProfessionalOrBusinessServicesChoices.architectural.value, + ], + licensing_grounds=[LicensingGroundsChoices.energy.value], + licensing_grounds_legal_advisory=[LicensingGroundsChoices.food.value, LicensingGroundsChoices.safety.value], + ) + licence.assign_reference() + licence.save() + self.page.goto(self.base_url + reverse("view_a_licence:view_application", kwargs={"reference": licence.reference})) + + conditional_box = self.page.get_by_test_id("licensing-grounds-legal-advisory-box") + expect(conditional_box).to_be_visible() + assert "Licensing grounds (excluding legal advisory)" in conditional_box.text_content() + assert LicensingGroundsChoices.food.label in conditional_box.text_content() + assert LicensingGroundsChoices.safety.value in conditional_box.text_content() + + # now checking without legal advisory + licence = LicenceFactory.create( + who_do_you_want_the_licence_to_cover=WhoDoYouWantTheLicenceToCoverChoices.business.value, + type_of_service=TypeOfServicesChoices.professional_and_business.value, + professional_or_business_services=[ProfessionalOrBusinessServicesChoices.architectural.value], + licensing_grounds=[LicensingGroundsChoices.energy.value], + licensing_grounds_legal_advisory=None, + ) + licence.assign_reference() + licence.save() + self.page.goto(self.base_url + reverse("view_a_licence:view_application", kwargs={"reference": licence.reference})) + + assert self.page.get_by_test_id("licensing-grounds-legal-advisory-box").count() == 0