Skip to content

Commit

Permalink
[#2221] Refactor tests + mocks with klanten + contactmomenten
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Apr 2, 2024
1 parent 62286e3 commit 5722591
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 235 deletions.
7 changes: 2 additions & 5 deletions src/open_inwoner/cms/cases/tests/test_contactform.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ def setUp(self):
self.klant = generate_oas_component_cached(
"kc",
"schemas/Klant",
uuid="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
url=f"{KLANTEN_ROOT}klant/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
bronorganisatie="123456789",
voornaam="Foo",
Expand Down Expand Up @@ -298,17 +297,15 @@ def _setUpMocks(self, m):
def _setUpExtraMocks(self, m):
self.contactmoment = generate_oas_component_cached(
"cmc",
"schemas/ContactMoment",
uuid="aaaaaaaa-aaaa-aaaa-aaaa-bbbbbbbbbbbb",
"schemas/Contactmoment",
url=f"{CONTACTMOMENTEN_ROOT}contactmoment/aaaaaaaa-aaaa-aaaa-aaaa-bbbbbbbbbbbb",
status=Status.nieuw,
antwoord="",
text="hey!\n\nwaddup?",
)
self.klant_contactmoment = generate_oas_component_cached(
"cmc",
"schemas/KlantContactMoment",
uuid="aaaaaaaa-aaaa-aaaa-aaaa-cccccccccccc",
"schemas/Klantcontactmoment",
url=f"{CONTACTMOMENTEN_ROOT}klantcontactmomenten/aaaaaaaa-aaaa-aaaa-aaaa-cccccccccccc",
klant=self.klant["url"],
contactmoment=self.contactmoment["url"],
Expand Down
6 changes: 2 additions & 4 deletions src/open_inwoner/cms/cases/tests/test_htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,15 @@ def setUp(self) -> None:
)
self.contactmoment = generate_oas_component_cached(
"cmc",
"schemas/ContactMoment",
uuid="aaaaaaaa-aaaa-aaaa-aaaa-bbbbbbbbbbbb",
"schemas/Contactmoment",
url=f"{CONTACTMOMENTEN_ROOT}contactmoment/aaaaaaaa-aaaa-aaaa-aaaa-bbbbbbbbbbbb",
status=Status.nieuw,
antwoord="",
text="hey!\n\nwaddup?",
)
self.klant_contactmoment = generate_oas_component_cached(
"cmc",
"schemas/KlantContactMoment",
uuid="aaaaaaaa-aaaa-aaaa-aaaa-cccccccccccc",
"schemas/Klantcontactmoment",
url=f"{CONTACTMOMENTEN_ROOT}klantcontactmomenten/aaaaaaaa-aaaa-aaaa-aaaa-cccccccccccc",
klant=self.klant["url"],
contactmoment=self.contactmoment["url"],
Expand Down
12 changes: 0 additions & 12 deletions src/open_inwoner/openklant/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ class Klant(ZGWModel):
telefoonnummer: str = ""
emailadres: str = ""

# open-klant OAS
bedrijfsnaam: str = ""
functie: str = ""
adres: dict | None = None
subject: str = ""
subject_type: str = ""
subject_identificatie: dict | None = None

# open-klant non-standard *AFWIJKING*
aanmaakkanaal: str = ""
geverifieerd: bool = False

def get_name_display(self):
return " ".join(
filter(bool, (self.voornaam, self.voorvoegsel_achternaam, self.achternaam))
Expand Down
22 changes: 11 additions & 11 deletions src/open_inwoner/openklant/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ def create_klant(
try:
response = self.post("klanten", json=data)
data = get_json_response(response)
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
except (RequestException, ClientError):
logger.exception("exception while making request")
return

klant = factory(Klant, data)

return klant

def _create_klant_for_bsn(self, user_bsn: str) -> Klant:
params = {"subjectIdentificatie": {"inpBsn": user_bsn}}
payload = {"subjectIdentificatie": {"inpBsn": user_bsn}}

try:
response = self.post("klanten", params=params)
response = self.post("klanten", json=payload)
data = get_json_response(response)
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
except (RequestException, ClientError):
logger.exception("exception while making request")
return None

klant = factory(Klant, data)
Expand All @@ -67,19 +67,19 @@ def _create_klant_for_bsn(self, user_bsn: str) -> Klant:
def _create_klant_for_kvk_or_rsin(
self, user_kvk_or_rsin: str, *, vestigingsnummer=None
) -> list[Klant]:
params = {"subjectIdentificatie": {"innNnpId": user_kvk_or_rsin}}
payload = {"subjectIdentificatie": {"innNnpId": user_kvk_or_rsin}}

if vestigingsnummer:
params = {"subjectIdentificatie": {"vestigingsNummer": vestigingsnummer}}
payload = {"subjectIdentificatie": {"vestigingsNummer": vestigingsnummer}}

try:
response = self.post(
"klanten",
params=params,
json=payload,
)
data = get_json_response(response)
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
except (RequestException, ClientError):
logger.exception("exception while making request")
return None

klant = factory(Klant, data)
Expand Down
2 changes: 0 additions & 2 deletions src/open_inwoner/openklant/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,3 @@ def update_user_from_klant(request):
f"updated user from klant API with fields: {', '.join(sorted(update_data.keys()))}",
content_object=user,
)

return (user, klant)
Loading

0 comments on commit 5722591

Please sign in to comment.