-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4163 from open-formulieren/feature/3725-add-broke…
…n-brp-configuration-to-email-digest [#3725] Add detection of BRP broken configuration concerning addressNL component
- Loading branch information
Showing
7 changed files
with
204 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from openforms.forms.models.form import Form | ||
from openforms.plugins.exceptions import InvalidPluginConfiguration | ||
|
||
from .checks import BRKValidatorCheck | ||
|
||
|
||
def check_brk_config_for_addressNL() -> str: | ||
live_forms = Form.objects.live() | ||
|
||
if any(form.has_component("addressNL") for form in live_forms): | ||
try: | ||
BRKValidatorCheck.check_config() | ||
except InvalidPluginConfiguration as e: | ||
return e.args[0] | ||
|
||
return "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,20 @@ | |
|
||
from django.core import mail | ||
from django.test import TestCase, override_settings | ||
from django.utils.translation import gettext as _ | ||
|
||
import requests_mock | ||
from django_yubin.models import Message | ||
from freezegun import freeze_time | ||
|
||
from openforms.config.models import GlobalConfiguration | ||
from openforms.forms.tests.factories import FormFactory | ||
from openforms.contrib.brk.models import BRKConfig | ||
from openforms.contrib.brk.tests.base import BRK_SERVICE | ||
from openforms.forms.tests.factories import ( | ||
FormDefinitionFactory, | ||
FormFactory, | ||
FormStepFactory, | ||
) | ||
from openforms.logging import logevent | ||
from openforms.prefill.registry import register | ||
from openforms.registrations.exceptions import RegistrationFailed | ||
|
@@ -260,3 +268,134 @@ def test_prefill_plugin_failures_are_sent(self): | |
self.assertIn(str(submission_1.id), sent_email.body) | ||
self.assertIn(str(submission_2.id), sent_email.body) | ||
self.assertIn(str(submission.id), sent_email.body) | ||
|
||
@requests_mock.Mocker() | ||
def test_no_email_sent_when_brk_congiguration_is_valid_for_addressNL(self, m): | ||
form = FormFactory.create() | ||
form_definition = FormDefinitionFactory.create( | ||
configuration={ | ||
"display": "form", | ||
"components": [ | ||
{ | ||
"key": "addressNl", | ||
"type": "addressNL", | ||
"label": "AddressNL", | ||
"defaultValue": { | ||
"postcode": "", | ||
"houseLetter": "", | ||
"houseNumber": "", | ||
"houseNumberAddition": "", | ||
}, | ||
} | ||
], | ||
} | ||
) | ||
FormStepFactory.create(form=form, form_definition=form_definition) | ||
|
||
with ( | ||
freeze_time("2023-01-03T01:00:00+01:00"), | ||
patch( | ||
"openforms.emails.tasks.GlobalConfiguration.get_solo", | ||
return_value=GlobalConfiguration( | ||
recipients_email_digest=["[email protected]"] | ||
), | ||
), | ||
patch( | ||
"openforms.contrib.brk.client.BRKConfig.get_solo", | ||
return_value=BRKConfig(service=BRK_SERVICE), | ||
), | ||
): | ||
|
||
m.get( | ||
"https://api.brk.kadaster.nl/esd-eto-apikey/bevragen/v2/kadastraalonroerendezaken?postcode=1234AB&huisnummer=1", | ||
json={"_embedded": {}}, | ||
) | ||
|
||
send_email_digest() | ||
|
||
self.assertEqual(0, len(mail.outbox)) | ||
|
||
def test_broken_brk_configuration_for_addressNL_is_sent(self): | ||
form = FormFactory.create() | ||
form_definition = FormDefinitionFactory.create( | ||
configuration={ | ||
"display": "form", | ||
"components": [ | ||
{ | ||
"key": "addressNl", | ||
"type": "addressNL", | ||
"label": "AddressNL", | ||
"defaultValue": { | ||
"postcode": "", | ||
"houseLetter": "", | ||
"houseNumber": "", | ||
"houseNumberAddition": "", | ||
}, | ||
} | ||
], | ||
} | ||
) | ||
FormStepFactory.create(form=form, form_definition=form_definition) | ||
|
||
with ( | ||
freeze_time("2023-01-03T01:00:00+01:00"), | ||
patch( | ||
"openforms.emails.tasks.GlobalConfiguration.get_solo", | ||
return_value=GlobalConfiguration( | ||
recipients_email_digest=["[email protected]"] | ||
), | ||
), | ||
patch( | ||
"openforms.contrib.brk.client.BRKConfig.get_solo", | ||
return_value=BRKConfig(service=None), | ||
), | ||
): | ||
|
||
send_email_digest() | ||
|
||
sent_email = mail.outbox[0] | ||
|
||
self.assertEqual( | ||
sent_email.subject, "[Open Forms] Daily summary of detected problems" | ||
) | ||
self.assertEqual(sent_email.recipients(), ["[email protected]"]) | ||
self.assertIn( | ||
_( | ||
"The configuration for 'BRK Client' is invalid (KVK endpoint is not configured)." | ||
), | ||
sent_email.body, | ||
) | ||
|
||
def test_no_email_sent_when_brk_congiguration_is_invalid_but_unused(self): | ||
form = FormFactory.create() | ||
form_definition = FormDefinitionFactory.create( | ||
configuration={ | ||
"display": "form", | ||
"components": [ | ||
{ | ||
"key": "textField", | ||
"type": "textfield", | ||
"label": "Text Field", | ||
} | ||
], | ||
} | ||
) | ||
FormStepFactory.create(form=form, form_definition=form_definition) | ||
|
||
with ( | ||
freeze_time("2023-01-03T01:00:00+01:00"), | ||
patch( | ||
"openforms.emails.tasks.GlobalConfiguration.get_solo", | ||
return_value=GlobalConfiguration( | ||
recipients_email_digest=["[email protected]"] | ||
), | ||
), | ||
patch( | ||
"openforms.contrib.brk.client.BRKConfig.get_solo", | ||
return_value=BRKConfig(service=None), | ||
), | ||
): | ||
|
||
send_email_digest() | ||
|
||
self.assertEqual(0, len(mail.outbox)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters