Skip to content

Commit

Permalink
✨ [#2303] Always inject toestemming when subscribing to newsletter
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Apr 25, 2024
1 parent b86f8c3 commit 1e5213d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/open_inwoner/laposta/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_lists(self) -> list[LapostaList]:

def create_subscription(self, list_id: str, user_data: UserData) -> Member | None:
response = self.post(
"member", data={"list_id": list_id, **user_data.model_dump()}
"member", json={"list_id": list_id, **user_data.model_dump()}
)

if response.status_code == 400:
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/laposta/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def save(self, request, *args, **kwargs):
ip=get_client_ip(request)[0],
email=user.verified_email,
source_url=None,
custom_fields=None,
custom_fields={"toestemming": "Ja, ik wil de nieuwsbrief ontvangen"},
options=None,
)
limited_to = LapostaConfig.get_solo().limit_list_selection_to
Expand Down
12 changes: 9 additions & 3 deletions src/open_inwoner/laposta/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from unittest.mock import patch
from urllib.parse import parse_qs

from django.test import RequestFactory, TestCase, tag
from django.utils.translation import gettext as _
Expand Down Expand Up @@ -128,8 +127,15 @@ def test_save_form(self, m):
[post_request] = post_matcher.request_history

self.assertEqual(
parse_qs(post_request.body),
{"list_id": ["789"], "ip": ["127.0.0.1"], "email": [self.user.email]},
post_request.json(),
{
"list_id": "789",
"ip": "127.0.0.1",
"email": self.user.email,
"custom_fields": {"toestemming": "Ja, ik wil de nieuwsbrief ontvangen"},
"source_url": None,
"options": None,
},
)

# Because list_id 123 was present in the
Expand Down

0 comments on commit 1e5213d

Please sign in to comment.