Skip to content

Commit

Permalink
Merge pull request #4204 from open-formulieren/backport/4165-26x
Browse files Browse the repository at this point in the history
[#4165] Backport to 2.6.x
  • Loading branch information
SilviaAmAm authored Apr 19, 2024
2 parents 80885fe + c80f12a commit 8b3a058
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.11 on 2024-04-17 08:38

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("cookie_consent", "0002_auto__add_logitem"),
("analytics_tools", "0006_auto_20240112_1046"),
]

operations = [
migrations.AlterField(
model_name="analyticstoolsconfiguration",
name="analytics_cookie_consent_group",
field=models.ForeignKey(
help_text="The cookie group used for analytical cookies. The analytics scripts are loaded only if this cookie group is accepted by the end-user.",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="cookie_consent.cookiegroup",
),
),
]
2 changes: 1 addition & 1 deletion src/openforms/analytics_tools/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class AnalyticsToolsConfiguration(SingletonModel):
"cookie_consent.CookieGroup",
on_delete=models.SET_NULL,
null=True,
blank=True,
blank=False,
help_text=_(
"The cookie group used for analytical cookies. The analytics scripts are "
"loaded only if this cookie group is accepted by the end-user."
Expand Down
12 changes: 12 additions & 0 deletions src/openforms/analytics_tools/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.urls import reverse

from cookie_consent.models import CookieGroup
from django_webtest import WebTest
from maykin_2fa.test import disable_admin_mfa

Expand All @@ -8,6 +9,13 @@

@disable_admin_mfa()
class AnalyticsConfigAdminTests(WebTest):
@classmethod
def setUpTestData(cls) -> None:
super().setUpTestData()
cls.cookie_group = CookieGroup.objects.create(
varname="test group", name="test group"
)

def test_urls_cannot_have_trailing_slashes(self):
superuser = SuperUserFactory.create()
admin_url = reverse(
Expand All @@ -20,6 +28,8 @@ def test_urls_cannot_have_trailing_slashes(self):
change_page = self.app.get(admin_url, user=superuser)
form = change_page.forms["analyticstoolsconfiguration_form"]
form[field] = "https://example.com/"
# Options are loaded dynamically, so force value:
form["analytics_cookie_consent_group"].force_value(self.cookie_group.pk)

response = form.submit()

Expand All @@ -40,6 +50,8 @@ def test_urls_without_trailing_slash_ok(self):
change_page = self.app.get(admin_url, user=superuser)
form = change_page.forms["analyticstoolsconfiguration_form"]
form[field] = "https://example.com"
# Options are loaded dynamically, so force value:
form["analytics_cookie_consent_group"].force_value(self.cookie_group.pk)

response = form.submit()

Expand Down

0 comments on commit 8b3a058

Please sign in to comment.