Skip to content

Commit

Permalink
[#3864] Fix handling of StufBG responses with one partner
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Feb 12, 2024
1 parent 745cbbe commit 15d8b31
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/openforms/formio/components/np_family_members/stuf_bg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ def get_np_family_members_stuf_bg(
include_partners: bool,
submission: Submission | None = None,
) -> list[tuple[str, str]]:
values = []
attributes: list[str] = []
if include_children:
values.append("inp.heeftAlsKinderen")
attributes.append("inp.heeftAlsKinderen")

if include_partners:
values.append("inp.heeftAlsEchtgenootPartner")
attributes.append("inp.heeftAlsEchtgenootPartner")

with get_client() as client:
data = client.get_values(bsn, values)
data = client.get_values(bsn, attributes)

# Kids
family_members = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from unittest.mock import patch

from django.test import TestCase
from django.test import TestCase, tag
from django.utils.html import format_html
from django.utils.translation import gettext as _

Expand Down Expand Up @@ -150,6 +150,31 @@ def test_get_partners_stuf_bg(self, mock_stufbg_config_get_solo):
self.assertEqual(("123123123", "Belly van Doe"), partners_choices[0])
self.assertEqual(("456456456", "Bully van Doe"), partners_choices[1])

@tag("gh-3864")
@patch("stuf.stuf_bg.client.StufBGConfig.get_solo")
def test_get_single_partner_stuf_bg(self, mock_stufbg_config_get_solo):
stuf_bg_service = StufServiceFactory.build()
mock_stufbg_config_get_solo.return_value = StufBGConfig(service=stuf_bg_service)
soap_response_template = (
TEST_FILES / "stuf_bg_one_family_member.xml"
).read_text()
response_content = render_from_string(soap_response_template, {}).encode(
"utf-8"
)

with requests_mock.Mocker() as m:
m.post(
stuf_bg_service.get_endpoint(type=EndpointType.vrije_berichten),
content=response_content,
)

partners_choices = get_np_family_members_stuf_bg(
bsn="111222333", include_children=False, include_partners=True
)

self.assertEqual(1, len(partners_choices))
self.assertEqual(("123123123", "Belly van Doe"), partners_choices[0])

@patch("stuf.stuf_bg.client.StufBGConfig.get_solo")
def test_get_family_memebers_stuf_bg(self, mock_stufbg_config_get_solo):
stuf_bg_service = StufServiceFactory.build()
Expand Down
1 change: 1 addition & 0 deletions src/stuf/stuf_bg/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def get_values(self, bsn: str, attributes: list[str]) -> dict:
response_data,
process_namespaces=True,
namespaces=NAMESPACE_REPLACEMENTS,
force_list=["inp.heeftAlsEchtgenootPartner", "inp.heeftAlsKinderen"],
)
)

Expand Down

0 comments on commit 15d8b31

Please sign in to comment.