Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2912] Fix styling for zgw import-export error messages #1505

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/open_inwoner/openzaak/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,13 @@ def process_file_view(self, request):
error_msg_iterator = ([msg] for msg in msgs_deduped)

error_msg_html = format_html_join(
"\n", "<li>{}</li>", error_msg_iterator
"\n", "<p> - {}</p>", error_msg_iterator
)
error_msg_html_ordered = format_html(
error_msg_html = format_html(
_("It was not possible to import the following items:")
+ f"<ol> {error_msg_html} </ol>"
)
self.message_user(
request, error_msg_html_ordered, messages.ERROR
+ f"<div>{error_msg_html}</div>"
)
self.message_user(request, error_msg_html, messages.ERROR)

return HttpResponseRedirect(
reverse(
Expand Down
18 changes: 9 additions & 9 deletions src/open_inwoner/openzaak/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ def extract_error_data(cls, exc: Exception, jsonl: str):
fields = data.get("fields", None)
if source_config is CatalogusConfig:
items = [
f"Domein = {fields['domein']}",
f"Rsin = {fields['rsin']}",
f"Domein = {fields['domein']!r}",
f"Rsin = {fields['rsin']!r}",
]
if source_config is ZaakTypeConfig:
items = [
f"Identificatie = {fields['identificatie']}",
f"Catalogus domein = {fields['catalogus'][0]}",
f"Catalogus rsin = {fields['catalogus'][1]}",
f"Identificatie = {fields['identificatie']!r}",
f"Catalogus domein = {fields['catalogus'][0]!r}",
f"Catalogus rsin = {fields['catalogus'][1]!r}",
]
if source_config in {
ZaakTypeStatusTypeConfig,
ZaakTypeResultaatTypeConfig,
ZaakTypeInformatieObjectTypeConfig,
}:
items = [
f"omschrijving = {fields['omschrijving']}",
f"ZaakTypeConfig identificatie = {fields['zaaktype_config'][0]}",
f"Catalogus domein = {fields['zaaktype_config'][1]}",
f"Catalogus rsin = {fields['zaaktype_config'][2]}",
f"omschrijving = {fields['omschrijving']!r}",
f"ZaakTypeConfig identificatie = {fields['zaaktype_config'][0]!r}",
f"Catalogus domein = {fields['zaaktype_config'][1]!r}",
f"Catalogus rsin = {fields['zaaktype_config'][2]!r}",
]

return {
Expand Down
29 changes: 15 additions & 14 deletions src/open_inwoner/openzaak/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import html
import json
from unittest import mock

Expand Down Expand Up @@ -280,39 +281,39 @@ def test_import_flow_reports_errors(self) -> None:

response = form.submit().follow()

messages = [str(msg) for msg in response.context["messages"]]
messages = [html.unescape(str(msg)) for msg in response.context["messages"]]
self.assertEqual(len(messages), 2)
self.assertEqual(
_("6 item(s) processed in total, with 6 failing row(s)."),
messages[0],
)
self.assertIn(
"ZaakTypeConfig not found in target environment: Identificatie = ztc-id-a-0, "
"Catalogus domein = DM-0, Catalogus rsin = 123456789",
"ZaakTypeConfig not found in target environment: Identificatie = 'ztc-id-a-0', "
"Catalogus domein = 'DM-0', Catalogus rsin = '123456789'",
messages[1],
)
self.assertIn(
"ZaakTypeStatusTypeConfig not found in target environment: omschrijving = status omschrijving, "
"ZaakTypeConfig identificatie = ztc-id-a-0, Catalogus domein = DM-0, Catalogus rsin = 123456789",
"ZaakTypeStatusTypeConfig not found in target environment: omschrijving = 'status omschrijving', "
"ZaakTypeConfig identificatie = 'ztc-id-a-0', Catalogus domein = 'DM-0', Catalogus rsin = '123456789'",
messages[1],
)
self.assertIn(
"ZaakTypeStatusTypeConfig not found in target environment: omschrijving = bogus, ZaakTypeConfig "
"identificatie = ztc-id-a-0, Catalogus domein = DM-0, Catalogus rsin = 123456789",
"ZaakTypeStatusTypeConfig not found in target environment: omschrijving = 'bogus', ZaakTypeConfig "
"identificatie = 'ztc-id-a-0', Catalogus domein = 'DM-0', Catalogus rsin = '123456789'",
messages[1],
)
self.assertIn(
"ZaakTypeInformatieObjectTypeConfig not found in target environment: omschrijving = informatieobject, "
"ZaakTypeConfig identificatie = ztc-id-a-0, Catalogus domein = DM-0, Catalogus rsin = 123456789",
"ZaakTypeInformatieObjectTypeConfig not found in target environment: omschrijving = 'informatieobject', "
"ZaakTypeConfig identificatie = 'ztc-id-a-0', Catalogus domein = 'DM-0', Catalogus rsin = '123456789'",
messages[1],
)
self.assertIn(
"CatalogusConfig not found in target environment: Domein = DM-0, Rsin = 123456789",
"CatalogusConfig not found in target environment: Domein = 'DM-0', Rsin = '123456789'",
messages[1],
)
self.assertIn(
"ZaakTypeResultaatTypeConfig not found in target environment: omschrijving = resultaat, "
"ZaakTypeConfig identificatie = ztc-id-a-0, Catalogus domein = DM-0, Catalogus rsin = 123456789",
"ZaakTypeResultaatTypeConfig not found in target environment: omschrijving = 'resultaat', "
"ZaakTypeConfig identificatie = 'ztc-id-a-0', Catalogus domein = 'DM-0', Catalogus rsin = '123456789'",
messages[1],
)

Expand Down Expand Up @@ -341,13 +342,13 @@ def test_import_flow_reports_partial_errors(self) -> None:

response = form.submit().follow()

messages = [str(msg) for msg in response.context["messages"]]
messages = [html.unescape(str(msg)) for msg in response.context["messages"]]
self.assertEqual(len(messages), 2)
self.assertEqual(
_("2 item(s) processed in total, with 1 failing row(s)."),
messages[0],
)
self.assertEqual(
"It was not possible to import the following items:<ol> <li>ZaakTypeConfig not found in target environment: Identificatie = ztc-id-a-0, Catalogus domein = DM-0, Catalogus rsin = 123456789</li> </ol>",
"It was not possible to import the following items:<div><p> - ZaakTypeConfig not found in target environment: Identificatie = 'ztc-id-a-0', Catalogus domein = 'DM-0', Catalogus rsin = '123456789'</p></div>",
messages[1],
)
16 changes: 8 additions & 8 deletions src/open_inwoner/openzaak/tests/test_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ def test_import_jsonl_missing_statustype_config(self):
)
)
expected_error = ZGWImportError(
"ZaakTypeStatusTypeConfig not found in target environment: omschrijving = bogus, "
"ZaakTypeConfig identificatie = ztc-id-a-0, Catalogus domein = DM-0, Catalogus rsin = 123456789"
"ZaakTypeStatusTypeConfig not found in target environment: omschrijving = 'bogus', "
"ZaakTypeConfig identificatie = 'ztc-id-a-0', Catalogus domein = 'DM-0', Catalogus rsin = '123456789'"
)
import_expected = dataclasses.asdict(
CatalogusConfigImport(
Expand Down Expand Up @@ -418,8 +418,8 @@ def test_import_jsonl_update_statustype_config_missing_zt_config(self):
)
)
expected_error = ZGWImportError(
"ZaakTypeStatusTypeConfig not found in target environment: omschrijving = status omschrijving, "
"ZaakTypeConfig identificatie = bogus, Catalogus domein = DM-1, Catalogus rsin = 666666666"
"ZaakTypeStatusTypeConfig not found in target environment: omschrijving = 'status omschrijving', "
"ZaakTypeConfig identificatie = 'bogus', Catalogus domein = 'DM-1', Catalogus rsin = '666666666'"
)
import_expected = dataclasses.asdict(
CatalogusConfigImport(
Expand Down Expand Up @@ -464,8 +464,8 @@ def test_import_jsonl_update_reports_duplicates(self):
)
)
expected_error = ZGWImportError(
"Got multiple results for ZaakTypeResultaatTypeConfig: omschrijving = resultaat, "
"ZaakTypeConfig identificatie = ztc-id-a-0, Catalogus domein = DM-0, Catalogus rsin = 123456789"
"Got multiple results for ZaakTypeResultaatTypeConfig: omschrijving = 'resultaat', "
"ZaakTypeConfig identificatie = 'ztc-id-a-0', Catalogus domein = 'DM-0', Catalogus rsin = '123456789'"
)
import_expected = dataclasses.asdict(
CatalogusConfigImport(
Expand Down Expand Up @@ -509,10 +509,10 @@ def test_import_jsonl_fails_with_catalogus_domein_rsin_mismatch(self):
[
# error from trying to load existing CatalogusConfig
"ERROR:open_inwoner.openzaak.import_export:"
"CatalogusConfig not found in target environment: Domein = BAR, Rsin = 987654321",
"CatalogusConfig not found in target environment: Domein = 'BAR', Rsin = '987654321'",
# error from deserializing nested ZGW objects
"ERROR:open_inwoner.openzaak.import_export:"
"ZaakTypeConfig not found in target environment: Identificatie = ztc-id-a-0, Catalogus domein = DM-0, Catalogus rsin = 123456789",
"ZaakTypeConfig not found in target environment: Identificatie = 'ztc-id-a-0', Catalogus domein = 'DM-0', Catalogus rsin = '123456789'",
],
)

Expand Down
Loading