diff --git a/tests/factories/payment_order.py b/tests/factories/payment_order.py index 1b437b2b3..d612cdc42 100644 --- a/tests/factories/payment_order.py +++ b/tests/factories/payment_order.py @@ -45,12 +45,22 @@ class PaymentOrderBuilder(ModelFactoryBuilder[PaymentOrder]): def for_mock_order(self, reservation: Reservation) -> Self: order_uuid = uuid.uuid4() - base_url = settings.MOCK_VERKKOKAUPPA_BACKEND_URL.strip("/") - checkout_url = reverse("mock_verkkokauppa:checkout", args=[order_uuid]).strip("/") - receipt_url = reverse("admin:tilavarauspalvelu_reservation_change", args=[reservation.id]).strip("/") + + if settings.MOCK_VERKKOKAUPPA_API_ENABLED: + base_url = settings.MOCK_VERKKOKAUPPA_BACKEND_URL.strip("/") + + checkout_path = reverse("mock_verkkokauppa:checkout", args=[order_uuid]).strip("/") + receipt_path = reverse("admin:tilavarauspalvelu_reservation_change", args=[reservation.id]).strip("/") + + checkout_url = f"{base_url}/{checkout_path}/" + receipt_url = f"{base_url}/{receipt_path}/?" + + else: + checkout_url = f"https://checkout-test.test.hel.ninja/{order_uuid}?user={reservation.user.uuid}" + receipt_url = f"https://checkout-test.test.hel.ninja/{order_uuid}/receipt?user={reservation.user.uuid}" return self.set( remote_id=order_uuid, - checkout_url=f"{base_url}/{checkout_url}/", - receipt_url=f"{base_url}/{receipt_url}/?", + checkout_url=checkout_url, + receipt_url=receipt_url, ) diff --git a/tests/helpers.py b/tests/helpers.py index 147774a07..0e50e4d2f 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -1,4 +1,3 @@ -import uuid from collections.abc import Callable from functools import wraps from typing import Any, NamedTuple, ParamSpec, Self, TypeVar @@ -9,9 +8,6 @@ import pytest from django.conf import settings from django.http import HttpRequest -from django.test import override_settings -from django.test.signals import root_urlconf_changed -from django.urls import NoReverseMatch, URLResolver, include, path, reverse from django.utils import translation from django.utils.functional import lazy from django.utils.translation import trans_real @@ -213,37 +209,3 @@ def get_supported_language_variant(self, lang_code: Lang, strict: bool = False) msg = f"Language '{lang_code}' is not supported" raise LookupError(msg) - - -def with_mock_verkkokauppa(func: Callable[P, None]) -> Callable[P, None]: - """Enables mock verkkokauppa API for the duration of the test.""" - - @wraps(func) - def wrapper(*args: P.args, **kwargs: P.kwargs) -> None: - from config.urls import urlpatterns - - urls: URLResolver = path( - "mock_verkkokauppa/", - include("tilavarauspalvelu.api.mock_verkkokauppa_api.urls", namespace="mock_verkkokauppa"), - ) - - missing = False - - # The mock verkkokauppa URLs are registered conditionally, - # so we need to check it they exist and add them to 'urlpatterns' if they don't. - try: - reverse("mock_verkkokauppa:checkout", args=[str(uuid.uuid4())]) - except NoReverseMatch: - missing = True - urlpatterns.append(urls) - root_urlconf_changed(setting="ROOT_URLCONF") - - try: - with override_settings(MOCK_VERKKOKAUPPA_API_ENABLED=True): - func(*args, **kwargs) - finally: - if missing: - urlpatterns.remove(urls) - root_urlconf_changed(setting="ROOT_URLCONF") - - return wrapper diff --git a/tests/test_utils/test_create_test_data.py b/tests/test_utils/test_create_test_data.py index 5fa30bb0c..bf26c26a5 100644 --- a/tests/test_utils/test_create_test_data.py +++ b/tests/test_utils/test_create_test_data.py @@ -2,7 +2,6 @@ import pytest from django.db import models -from tests.helpers import with_mock_verkkokauppa from tilavarauspalvelu.management.commands.create_test_data import create_test_data from tilavarauspalvelu.models import ( AbilityGroup, @@ -47,8 +46,8 @@ @pytest.mark.django_db @pytest.mark.slow -@with_mock_verkkokauppa def test_create_test_data(settings): + settings.MOCK_VERKKOKAUPPA_API_ENABLED = False settings.UPDATE_RESERVATION_UNIT_THUMBNAILS = True all_models = django.apps.apps.app_configs["tilavarauspalvelu"].get_models()