Skip to content

Commit

Permalink
[#3362] PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Nov 17, 2023
1 parent 031e3f1 commit 2dbe608
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 17 deletions.
6 changes: 6 additions & 0 deletions docs/developers/backend/core/testing-tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ HTML assertions
.. automodule:: openforms.utils.tests.webtest_base
:members:

Frontend redirects
==================

.. automodule:: openforms.frontend.tests
:members:

Migrations
==========

Expand Down
4 changes: 4 additions & 0 deletions docs/developers/sdk/embedding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ Available options
would be ``https://example.com/basepath?cms_query=1#/startpagina`` (SDK specific query parameters would come
at the end of the URL).

.. warning::
This is a last resort solution - preferably the backend where you embed the form would set up "wildcard" routes to
ensure that refreshing the page works, e.g. ``/some-path/<form-id>/*`` should just load the CMS page for a specific form.

``CSPNonce``:
Recommended. The page's CSP Nonce value if inline styles are blocked by your
`Content Security Policy <https://content-security-policy.com/nonce/>`_. The Open
Expand Down
6 changes: 3 additions & 3 deletions src/openforms/appointments/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from openforms.authentication.constants import FORM_AUTH_SESSION_KEY, AuthAttribute
from openforms.authentication.contrib.digid.constants import DIGID_DEFAULT_LOA
from openforms.forms.tests.factories import FormFactory
from openforms.frontend.tests import FrontendRedirectMixin
from openforms.logging.models import TimelineLogProxy
from openforms.payments.constants import PaymentStatus
from openforms.payments.tests.factories import SubmissionPaymentFactory
Expand All @@ -20,14 +21,13 @@
SubmissionFactory,
SubmissionStepFactory,
)
from openforms.tests.mixins import FrontendRedirectMixin

from ..tokens import submission_appointment_token_generator
from .factories import AppointmentFactory, AppointmentInfoFactory


@freeze_time("2021-07-15T21:15:00Z")
class VerifyCancelAppointmentLinkViewTests(TestCase, FrontendRedirectMixin):
class VerifyCancelAppointmentLinkViewTests(FrontendRedirectMixin, TestCase):
def test_good_token_and_submission_redirect_and_add_submission_to_session(self):
submission = SubmissionFactory.create(
completed=True, form_url="http://maykinmedia.nl/myform"
Expand Down Expand Up @@ -341,7 +341,7 @@ def test_invalid_auth_value_raises_exception(self):


@freeze_time("2021-07-15T21:15:00Z")
class VerifyChangeAppointmentLinkViewTests(TestCase, FrontendRedirectMixin):
class VerifyChangeAppointmentLinkViewTests(FrontendRedirectMixin, TestCase):
def test_good_token_and_submission_redirect_and_add_submission_to_session(self):
submission = SubmissionFactory.from_components(
completed=True,
Expand Down
3 changes: 3 additions & 0 deletions src/openforms/frontend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .frontend import get_frontend_redirect_url

__all__ = ["get_frontend_redirect_url"]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from furl import furl

from openforms.frontend import SDKAction
from .frontend import SDKAction


class FrontendRedirectMixin:
Expand All @@ -26,7 +26,7 @@ def assertRedirectsToFrontend(
:param frontend_base_url: The base URL of the frontend.
:param action: The SDK action performed.
:param action_params: Optional parameters for the action.
:param **kwargs: Additional kwargs to be passed to ``assertRedirects``.
:param `**kwargs`: Additional kwargs to be passed to :meth:`django.test.SimpleTestCase.assertRedirects`.
"""

expected_redirect_url = furl(frontend_base_url)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated by Django 3.2.21 on 2023-11-16 14:57
# Generated by Django 3.2.21 on 2023-11-17 10:40

from django.db import migrations
from django.db.migrations.state import StateApps
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
Expand All @@ -12,9 +13,11 @@ def cleanup_submission_urls(

Submission = apps.get_model("submissions", "Submission")

for submission in Submission.objects.all():
for submission in Submission.objects.iterator():
f = furl(submission.form_url)
f.remove(fragment=True)
if f.path.segments[-1:] == ["startpagina"]:
f.path.segments.remove("startpagina")
submission.form_url = f.url

submission.save()
Expand All @@ -23,7 +26,9 @@ def cleanup_submission_urls(
class Migration(migrations.Migration):

dependencies = [
("submissions", "0078_submission_finalised_registration_backend_key"),
("submissions", "0002_change_json_encoder"),
]

operations = [migrations.RunPython(cleanup_submission_urls)]
operations = [
migrations.RunPython(cleanup_submission_urls, migrations.RunPython.noop)
]
4 changes: 2 additions & 2 deletions src/openforms/submissions/tests/test_resume_form_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from openforms.authentication.constants import FORM_AUTH_SESSION_KEY, AuthAttribute
from openforms.authentication.contrib.digid.constants import DIGID_DEFAULT_LOA
from openforms.config.models import GlobalConfiguration
from openforms.tests.mixins import FrontendRedirectMixin
from openforms.frontend.tests import FrontendRedirectMixin

from ..constants import SUBMISSIONS_SESSION_KEY
from ..tokens import submission_resume_token_generator
from .factories import SubmissionFactory, SubmissionStepFactory


class SubmissionResumeViewTests(TestCase, FrontendRedirectMixin):
class SubmissionResumeViewTests(FrontendRedirectMixin, TestCase):
def test_good_token_and_submission_redirect_and_add_submission_to_session(self):
submission = SubmissionFactory.from_components(
completed=True,
Expand Down
4 changes: 2 additions & 2 deletions src/openforms/submissions/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

from openforms.authentication.constants import FORM_AUTH_SESSION_KEY
from openforms.authentication.contrib.digid.constants import DIGID_DEFAULT_LOA
from openforms.frontend.tests import FrontendRedirectMixin
from openforms.submissions.tests.factories import SubmissionFactory
from openforms.tests.mixins import FrontendRedirectMixin


class SearchSubmissionForCosignView(WebTest, FrontendRedirectMixin):
class SearchSubmissionForCosignView(FrontendRedirectMixin, WebTest):
def setUp(self) -> None:
super().setUp()

Expand Down
8 changes: 4 additions & 4 deletions src/openforms/tests/test_frontend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_frontend_redirect_no_hash(self):
excpected_redirect_url.add(
{
"_of_action": "resume",
"_of_action_params": (json.dumps(action_params)),
"_of_action_params": json.dumps(action_params),
}
)

Expand All @@ -52,7 +52,7 @@ def test_frontend_redirect_hash(self):
excpected_redirect_url.add(
{
"_of_action": "resume",
"_of_action_params": (json.dumps(action_params)),
"_of_action_params": json.dumps(action_params),
}
)

Expand All @@ -78,7 +78,7 @@ def test_frontend_redirect_special_chars(self):
excpected_redirect_url.add(
{
"_of_action": "resume",
"_of_action_params": (json.dumps(action_params)),
"_of_action_params": json.dumps(action_params),
}
)

Expand All @@ -104,7 +104,7 @@ def test_frontend_redirect_query_param(self):
excpected_redirect_url.add(
{
"_of_action": "resume",
"_of_action_params": (json.dumps(action_params)),
"_of_action_params": json.dumps(action_params),
"unrelated_query": "1",
}
)
Expand Down

0 comments on commit 2dbe608

Please sign in to comment.