Skip to content

Commit

Permalink
[#2804] Add legacy headers to Haal Centraal API client
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Oct 14, 2024
1 parent 7f883b0 commit 418c06a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/open_inwoner/haalcentraal/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ class BRP_2_1(BRPAPI):

def make_request(self, user_bsn: str) -> requests.Response:
url = "personen"

headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}
if self.config.api_origin_oin: # See Taiga #755
headers["x-origin-oin"] = self.config.api_origin_oin
if self.config.api_doelbinding: # See Taiga #755
headers["x-doelbinding"] = self.config.api_doelbinding

response = self.client.post(
url=url,
json={
Expand All @@ -138,10 +148,7 @@ def make_request(self, user_bsn: str) -> requests.Response:
"type": "RaadpleegMetBurgerservicenummer",
"burgerservicenummer": [user_bsn],
},
headers={
"Content-Type": "application/json",
"Accept": "application/json",
},
headers=headers,
verify=False,
)
return response
Expand Down
13 changes: 13 additions & 0 deletions src/open_inwoner/haalcentraal/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
import requests_mock

from ..api import BRP_2_1
from ..models import HaalCentraalConfig
from .mixins import HaalCentraalMixin


@requests_mock.Mocker()
class BRPClientTest(HaalCentraalMixin, TestCase):
def setUp(self):
config = HaalCentraalConfig.get_solo()
config.api_doelbinding = "test_header_doelbinding"
config.api_origin_oin = "test_header_origin_oin"
config.save()

def test_request_content_type(self, m):
self._setUpMocks_v_2(m)
self._setUpService()
Expand All @@ -20,6 +27,12 @@ def test_request_content_type(self, m):
self.assertEqual(
m.request_history[0].headers["Content-Type"], "application/json"
)
self.assertEqual(
m.request_history[0].headers["x-origin-oin"], "test_header_origin_oin"
)
self.assertEqual(
m.request_history[0].headers["x-doelbinding"], "test_header_doelbinding"
)

data = {
"fields": [
Expand Down

0 comments on commit 418c06a

Please sign in to comment.