From 96b945c119be8178d4efebc0934fef0f43d580c0 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Fri, 12 Apr 2024 09:24:13 +0200 Subject: [PATCH 1/3] [#2260] Removed StatusTranslation model --- src/open_inwoner/cms/cases/views/status.py | 20 +++--- src/open_inwoner/openzaak/admin.py | 30 -------- src/open_inwoner/openzaak/api_models.py | 5 +- .../0047_delete_statustranslation.py | 16 +++++ src/open_inwoner/openzaak/models.py | 19 ----- src/open_inwoner/openzaak/notifications.py | 8 ++- .../openzaak/resources/__init__.py | 0 .../openzaak/resources/import_resource.py | 33 --------- src/open_inwoner/openzaak/tests/factories.py | 9 --- .../openzaak/tests/test_case_detail.py | 27 -------- src/open_inwoner/openzaak/tests/test_cases.py | 13 ---- .../openzaak/tests/test_notification_utils.py | 7 +- .../openzaak/tests/test_status_translation.py | 33 --------- src/open_inwoner/openzaak/utils.py | 22 +----- .../userfeed/hooks/case_status.py | 10 +-- .../userfeed/tests/hooks/test_case_status.py | 9 +-- .../utils/tests/test_translate.py | 69 ------------------- 17 files changed, 38 insertions(+), 292 deletions(-) create mode 100644 src/open_inwoner/openzaak/migrations/0047_delete_statustranslation.py delete mode 100644 src/open_inwoner/openzaak/resources/__init__.py delete mode 100644 src/open_inwoner/openzaak/resources/import_resource.py delete mode 100644 src/open_inwoner/openzaak/tests/test_status_translation.py delete mode 100644 src/open_inwoner/utils/tests/test_translate.py diff --git a/src/open_inwoner/cms/cases/views/status.py b/src/open_inwoner/cms/cases/views/status.py index 05bf2133f9..04282993f5 100644 --- a/src/open_inwoner/cms/cases/views/status.py +++ b/src/open_inwoner/cms/cases/views/status.py @@ -38,7 +38,6 @@ ) from open_inwoner.openzaak.models import ( OpenZaakConfig, - StatusTranslation, ZaakTypeConfig, ZaakTypeInformatieObjectTypeConfig, ZaakTypeResultaatTypeConfig, @@ -46,8 +45,8 @@ ) from open_inwoner.openzaak.utils import get_role_name_display, is_info_object_visible from open_inwoner.userfeed import hooks +from open_inwoner.utils.glom import glom_multiple from open_inwoner.utils.time import has_new_elements -from open_inwoner.utils.translate import TranslationLookup from open_inwoner.utils.views import CommonPageMixin, LogMixin from ..forms import CaseContactForm, CaseUploadForm @@ -139,7 +138,6 @@ def get_context_data(self, **kwargs): self.log_access_case_detail(self.case) config = OpenZaakConfig.get_solo() - status_translate = StatusTranslation.objects.get_lookup() zaken_client = build_client_openzaak("zaak") @@ -194,7 +192,6 @@ def get_context_data(self, **kwargs): end_statustype_data = self.handle_end_statustype_data( status_types_mapping=status_types_mapping, end_statustype=self.handle_end_statustype(statuses, statustypen), - status_translate=status_translate, ) result_data = self.get_result_data( self.case, self.resulttype_config_mapping, zaken_client @@ -217,7 +214,7 @@ def get_context_data(self, **kwargs): ), "description": self.case.zaaktype.omschrijving, "statuses": self.get_statuses_data( - statuses, status_translate, self.statustype_config_mapping + statuses, self.statustype_config_mapping ), "end_statustype_data": end_statustype_data, "second_status_preview": second_status_preview, @@ -371,7 +368,6 @@ def handle_end_statustype_data( self, status_types_mapping: dict[str, StatusType], end_statustype: StatusType, - status_translate: StatusTranslation, ): """ Prepare data about end statustype for use in context/template @@ -379,9 +375,10 @@ def handle_end_statustype_data( end_statustype_data = None if not status_types_mapping.get(end_statustype.url): end_statustype_data = { - "label": status_translate( - (end_statustype.statustekst or end_statustype.omschrijving), - default=_("No data available"), + "label": ( + end_statustype.statustekst + or end_statustype.omschrijving + or _("No data available") ), "status_indicator": getattr( self.statustype_config_mapping.get(end_statustype.url), @@ -540,19 +537,18 @@ def get_result_data( def get_initiator_display(case: Zaak) -> str: if client := build_client_openzaak("zaak"): roles = client.fetch_case_roles(case.url, RolOmschrijving.initiator) - return ", ".join([get_role_name_display(r) for r in roles]) + return ", ".join(get_role_name_display(r) for r in roles) return "" @staticmethod def get_statuses_data( statuses: list[Status], - lookup: TranslationLookup, statustype_config_mapping: dict | None = None, ) -> list[dict]: return [ { "date": s.datum_status_gezet, - "label": lookup.from_glom_multiple( + "label": glom_multiple( s, ("statustype.statustekst", "statustype.omschrijving"), default=_("No data available"), diff --git a/src/open_inwoner/openzaak/admin.py b/src/open_inwoner/openzaak/admin.py index 73799865d9..f80a1aec70 100644 --- a/src/open_inwoner/openzaak/admin.py +++ b/src/open_inwoner/openzaak/admin.py @@ -5,8 +5,6 @@ from django.forms.models import BaseInlineFormSet from django.utils.translation import gettext_lazy as _, ngettext -from import_export.admin import ImportExportMixin -from import_export.formats import base_formats from solo.admin import SingletonModelAdmin from open_inwoner.ckeditor5.widgets import CKEditorWidget @@ -14,7 +12,6 @@ from .models import ( CatalogusConfig, OpenZaakConfig, - StatusTranslation, UserCaseInfoObjectNotification, UserCaseStatusNotification, ZaakTypeConfig, @@ -22,7 +19,6 @@ ZaakTypeResultaatTypeConfig, ZaakTypeStatusTypeConfig, ) -from .resources.import_resource import StatusTranslationImportResource @admin.register(OpenZaakConfig) @@ -449,29 +445,3 @@ class UserCaseInfoObjectNotificationAdmin(admin.ModelAdmin): def has_change_permission(self, request, obj=None): return False - - -@admin.register(StatusTranslation) -class StatusTranslationAdmin(ImportExportMixin, admin.ModelAdmin): - fields = [ - "status", - "translation", - ] - search_fields = [ - "status", - "translation", - ] - list_display = [ - "id", - "status", - "translation", - ] - list_editable = [ - "status", - "translation", - ] - ordering = ("status",) - - # import-export - resource_class = StatusTranslationImportResource - formats = [base_formats.XLSX, base_formats.CSV] diff --git a/src/open_inwoner/openzaak/api_models.py b/src/open_inwoner/openzaak/api_models.py index 398f9bf2a5..837b5a4ab2 100644 --- a/src/open_inwoner/openzaak/api_models.py +++ b/src/open_inwoner/openzaak/api_models.py @@ -71,11 +71,8 @@ def process_data(self) -> dict: """ Prepare data for template """ - from open_inwoner.openzaak.models import StatusTranslation - status_translate = StatusTranslation.objects.get_lookup() - - status_text = status_translate.from_glom_multiple( + status_text = glom_multiple( self, ("status.statustype.statustekst", "status.statustype.omschrijving"), default="", diff --git a/src/open_inwoner/openzaak/migrations/0047_delete_statustranslation.py b/src/open_inwoner/openzaak/migrations/0047_delete_statustranslation.py new file mode 100644 index 0000000000..9bd1a7e147 --- /dev/null +++ b/src/open_inwoner/openzaak/migrations/0047_delete_statustranslation.py @@ -0,0 +1,16 @@ +# Generated by Django 4.2.11 on 2024-04-12 07:27 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("openzaak", "0046_alter_openzaakconfig_fetch_eherkenning_zaken_with_rsin"), + ] + + operations = [ + migrations.DeleteModel( + name="StatusTranslation", + ), + ] diff --git a/src/open_inwoner/openzaak/models.py b/src/open_inwoner/openzaak/models.py index 450d9ab89c..5d3fefcd02 100644 --- a/src/open_inwoner/openzaak/models.py +++ b/src/open_inwoner/openzaak/models.py @@ -12,7 +12,6 @@ from zgw_consumers.constants import APITypes from open_inwoner.openzaak.managers import ( - StatusTranslationQuerySet, UserCaseInfoObjectNotificationManager, UserCaseStatusNotificationManager, ZaakTypeConfigQueryset, @@ -594,21 +593,3 @@ def has_received_similar_notes_within( return UserCaseInfoObjectNotification.objects.has_received_similar_notes_within( self.user, self.case_uuid, period, collision_key, not_record_id=self.id ) - - -class StatusTranslation(models.Model): - status = models.CharField( - verbose_name=_("Status tekst"), - max_length=255, - unique=True, - ) - translation = models.CharField( - verbose_name=_("Vertaling"), - max_length=255, - ) - - objects = StatusTranslationQuerySet.as_manager() - - class Meta: - verbose_name = _("Status vertaling") - verbose_name_plural = _("Status vertalingen") diff --git a/src/open_inwoner/openzaak/notifications.py b/src/open_inwoner/openzaak/notifications.py index 7f097f3c27..008e9988ad 100644 --- a/src/open_inwoner/openzaak/notifications.py +++ b/src/open_inwoner/openzaak/notifications.py @@ -3,6 +3,7 @@ from django.conf import settings from django.urls import reverse +from django.utils.translation import gettext as _ from mail_editor.helpers import find_template from zgw_consumers.api_models.constants import RolOmschrijving, RolTypes @@ -30,7 +31,6 @@ get_zaak_type_info_object_type_config, is_info_object_visible, is_zaak_visible, - translate_single_status, ) from open_inwoner.userfeed import hooks from open_inwoner.utils.logentry import system_action as log_system_action @@ -592,8 +592,10 @@ def send_case_update_email( } if status: status_type = status.statustype - context["status_description"] = translate_single_status( - status_type.statustekst or status_type.omschrijving + context["status_description"] = ( + status_type.statustekst + or status_type.omschrijving + or _("No data available") ) if extra_context: context.update(extra_context) diff --git a/src/open_inwoner/openzaak/resources/__init__.py b/src/open_inwoner/openzaak/resources/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/open_inwoner/openzaak/resources/import_resource.py b/src/open_inwoner/openzaak/resources/import_resource.py deleted file mode 100644 index 3e44b701d6..0000000000 --- a/src/open_inwoner/openzaak/resources/import_resource.py +++ /dev/null @@ -1,33 +0,0 @@ -from django.utils.translation import gettext_lazy as _ - -from import_export import fields, resources -from import_export.exceptions import ImportExportError - -from open_inwoner.openzaak.models import StatusTranslation - - -class StatusTranslationImportResource(resources.ModelResource): - def before_import(self, dataset, using_transactions, dry_run, **kwargs): - # Validate that file contains all the headers - missing_headers = set(self.get_diff_headers()) - set(dataset.headers) - if missing_headers: - missing_headers = ",\n".join(missing_headers) - raise ImportExportError(_(f"Missing required headers: {missing_headers}")) - - return super().before_import(dataset, using_transactions, dry_run, **kwargs) - - def get_or_init_instance(self, instance_loader, row): - # Replace newlines from excel - for key, value in row.items(): - if isinstance(value, str): - row[key] = value.replace("_x000D_", "\n") - - return super().get_or_init_instance(instance_loader, row) - - status = fields.Field(column_name="status", attribute="status") - translation = fields.Field(column_name="translation", attribute="translation") - - class Meta: - model = StatusTranslation - import_id_fields = ("status",) - fields = ("status", "translation") diff --git a/src/open_inwoner/openzaak/tests/factories.py b/src/open_inwoner/openzaak/tests/factories.py index c33846f35c..63eef20b32 100644 --- a/src/open_inwoner/openzaak/tests/factories.py +++ b/src/open_inwoner/openzaak/tests/factories.py @@ -11,7 +11,6 @@ from open_inwoner.openzaak.api_models import Notification, Rol from open_inwoner.openzaak.models import ( CatalogusConfig, - StatusTranslation, UserCaseInfoObjectNotification, UserCaseStatusNotification, ZaakTypeConfig, @@ -152,14 +151,6 @@ class Meta: model = Notification -class StatusTranslationFactory(factory.django.DjangoModelFactory): - status = factory.Faker("pystr", max_chars=50) - translation = factory.Faker("pystr", max_chars=80) - - class Meta: - model = StatusTranslation - - def generate_rol( type_: str, identification: dict, diff --git a/src/open_inwoner/openzaak/tests/test_case_detail.py b/src/open_inwoner/openzaak/tests/test_case_detail.py index b6f6361f6d..e4d5535cd7 100644 --- a/src/open_inwoner/openzaak/tests/test_case_detail.py +++ b/src/open_inwoner/openzaak/tests/test_case_detail.py @@ -34,7 +34,6 @@ from open_inwoner.openklant.tests.factories import make_contactmoment from open_inwoner.openzaak.constants import StatusIndicators from open_inwoner.openzaak.tests.factories import ( - StatusTranslationFactory, ZaakTypeConfigFactory, ZaakTypeInformatieObjectTypeConfigFactory, ZaakTypeStatusTypeConfigFactory, @@ -1274,32 +1273,6 @@ def test_page_reformats_zaak_identificatie(self, m): # once for the log, once for adding case to context spy_format.assert_called - def test_page_translates_statuses(self, m): - trans_status_new_omschrijving = StatusTranslationFactory( - status=self.status_type_new["omschrijving"], - translation="Translated First Status Type Omschrijving", - ) - trans_status_new_statustekst = StatusTranslationFactory( - status=self.status_type_new["statustekst"], - translation="Translated First Status Type Statustekst", - ) - trans_status_finish_omschrijving = StatusTranslationFactory( - status=self.status_type_finish["omschrijving"], - translation="Translated Second Status Type", - ) - self._setUpMocks(m) - response = self.app.get( - self.case_detail_url, user=self.user, headers={"HX-Request": "true"} - ) - self.assertNotContains(response, trans_status_new_omschrijving.translation) - self.assertNotContains(response, trans_status_new_omschrijving.status) - - self.assertNotContains(response, trans_status_new_statustekst.status) - self.assertContains(response, trans_status_new_statustekst.translation) - - self.assertNotContains(response, trans_status_finish_omschrijving.status) - self.assertContains(response, trans_status_finish_omschrijving.translation) - def test_when_accessing_case_detail_a_timelinelog_is_created(self, m): self._setUpMocks(m) diff --git a/src/open_inwoner/openzaak/tests/test_cases.py b/src/open_inwoner/openzaak/tests/test_cases.py index 6ae0cc88b3..f1df7c519a 100644 --- a/src/open_inwoner/openzaak/tests/test_cases.py +++ b/src/open_inwoner/openzaak/tests/test_cases.py @@ -32,7 +32,6 @@ from .factories import ( CatalogusConfigFactory, ServiceFactory, - StatusTranslationFactory, ZaakTypeConfigFactory, ZaakTypeStatusTypeConfigFactory, ) @@ -761,18 +760,6 @@ def test_reformat_esuite_zaak_identificatie(self, m): actual = Zaak._reformat_esuite_zaak_identificatie(value) self.assertEqual(actual, expected) - def test_list_cases_translates_status(self, m): - st1 = StatusTranslationFactory( - status=self.status_type_initial["omschrijving"], - translation="Translated Status Type", - ) - self._setUpMocks(m) - self.client.force_login(user=self.user) - response = self.client.get(self.inner_url, HTTP_HX_REQUEST="true") - - self.assertNotContains(response, st1.status) - self.assertContains(response, st1.translation) - def test_list_cases_logs_displayed_case_ids(self, m): self._setUpMocks(m) diff --git a/src/open_inwoner/openzaak/tests/test_notification_utils.py b/src/open_inwoner/openzaak/tests/test_notification_utils.py index 7084b63bd3..783a3530a8 100644 --- a/src/open_inwoner/openzaak/tests/test_notification_utils.py +++ b/src/open_inwoner/openzaak/tests/test_notification_utils.py @@ -18,7 +18,6 @@ from open_inwoner.openzaak.tests.factories import generate_rol from ..api_models import Status, StatusType, Zaak, ZaakType -from ..models import StatusTranslation from .test_notification_data import MockAPIData @@ -38,10 +37,6 @@ def test_send_case_update_email(self): case.status = status - StatusTranslation.objects.create( - status=status.statustype.omschrijving, translation="My Translated Status" - ) - case_url = reverse("cases:case_detail", kwargs={"object_id": str(case.uuid)}) # mock `_format_zaak_identificatie`, but then continue with result of actual call @@ -65,7 +60,7 @@ def test_send_case_update_email(self): body_html = email.alternatives[0][0] self.assertIn(case.identificatie, body_html) self.assertIn(case.zaaktype.omschrijving, body_html) - self.assertIn("My Translated Status", body_html) + self.assertIn(status.statustype.omschrijving, body_html) self.assertIn(case_url, body_html) self.assertIn(config.name, body_html) diff --git a/src/open_inwoner/openzaak/tests/test_status_translation.py b/src/open_inwoner/openzaak/tests/test_status_translation.py deleted file mode 100644 index 79718abeb6..0000000000 --- a/src/open_inwoner/openzaak/tests/test_status_translation.py +++ /dev/null @@ -1,33 +0,0 @@ -from django.test import TestCase - -from open_inwoner.openzaak.models import StatusTranslation -from open_inwoner.openzaak.tests.factories import StatusTranslationFactory -from open_inwoner.openzaak.utils import translate_single_status - - -class StatusTranslationModelTest(TestCase): - def test_lookup(self): - StatusTranslationFactory(status="foo", translation="FOO") - StatusTranslationFactory(status="bar", translation="BAR") - - lookup = StatusTranslation.objects.get_lookup() - - tests = [ - # input, expected - ("foo", "FOO"), - ("bar", "BAR"), - ("bazz", "bazz"), - ("", ""), - ] - for value, expected in tests: - with self.subTest(value=value, expected=expected): - actual = lookup(value) - self.assertEqual(expected, actual) - - # NOTE the TranslationLookup helper is further tested in its own file - # src/open_inwoner/utils/tests/test_translate.py - - def test_helper(self): - StatusTranslationFactory(status="foo", translation="FOO") - self.assertEqual("FOO", translate_single_status("foo")) - self.assertEqual("not_translated", translate_single_status("not_translated")) diff --git a/src/open_inwoner/openzaak/utils.py b/src/open_inwoner/openzaak/utils.py index 699e86bc6a..9c484572d5 100644 --- a/src/open_inwoner/openzaak/utils.py +++ b/src/open_inwoner/openzaak/utils.py @@ -1,18 +1,11 @@ import logging -from django.utils.translation import gettext as _ - from zgw_consumers.api_models.constants import RolTypes, VertrouwelijkheidsAanduidingen from open_inwoner.kvk.branches import get_kvk_branch_number from open_inwoner.openzaak.api_models import InformatieObject, Rol, Zaak, ZaakType -from .models import ( - OpenZaakConfig, - StatusTranslation, - ZaakTypeConfig, - ZaakTypeInformatieObjectTypeConfig, -) +from .models import OpenZaakConfig, ZaakTypeConfig, ZaakTypeInformatieObjectTypeConfig logger = logging.getLogger(__name__) @@ -133,19 +126,6 @@ def get_zaak_type_info_object_type_config( return None -def translate_single_status(status_text: str) -> str: - if not status_text: - return _("No data available") - - # in most cases try to cache with StatusTranslation.objects.get_lookup() - try: - return StatusTranslation.objects.values_list("translation", flat=True).get( - status=status_text - ) - except StatusTranslation.DoesNotExist: - return status_text - - def get_user_fetch_parameters(request) -> dict: """ Determine the parameters used to perform ZGW resource fetches diff --git a/src/open_inwoner/userfeed/hooks/case_status.py b/src/open_inwoner/userfeed/hooks/case_status.py index 1d60b6564d..b9e9278768 100644 --- a/src/open_inwoner/userfeed/hooks/case_status.py +++ b/src/open_inwoner/userfeed/hooks/case_status.py @@ -9,7 +9,6 @@ from open_inwoner.accounts.models import User from open_inwoner.openzaak.api_models import Status, Zaak from open_inwoner.openzaak.models import ZaakTypeStatusTypeConfig -from open_inwoner.openzaak.utils import translate_single_status from open_inwoner.userfeed.adapter import FeedItem from open_inwoner.userfeed.adapters import register_item_adapter from open_inwoner.userfeed.choices import FeedItemType @@ -23,8 +22,10 @@ def case_status_notification_received(user: User, case: Zaak, status: Status): "case_uuid": case.uuid, "case_identificatie": case.identificatie, "case_omschrijving": case.omschrijving, - "status_omschrijving": translate_single_status( - status.statustype.statustekst or status.statustype.omschrijving + "status_omschrijving": ( + status.statustype.statustekst + or status.statustype.omschrijving + or _("No data available") ), # new for actionable "catalogus_url": case.zaaktype.catalogus, @@ -90,8 +91,7 @@ def title(self) -> str: @property def message(self) -> str: - status_text = self.get_data("status_omschrijving") - status_text = translate_single_status(status_text) + status_text = self.get_data("status_omschrijving") or _("No data available") html = escape(self.base_message) status = format_html('{}', status_text) html = format_html(html, status=status) diff --git a/src/open_inwoner/userfeed/tests/hooks/test_case_status.py b/src/open_inwoner/userfeed/tests/hooks/test_case_status.py index 97e8e1c7c1..241b434d44 100644 --- a/src/open_inwoner/userfeed/tests/hooks/test_case_status.py +++ b/src/open_inwoner/userfeed/tests/hooks/test_case_status.py @@ -10,7 +10,6 @@ from open_inwoner.openzaak.api_models import Status, StatusType, Zaak, ZaakType from open_inwoner.openzaak.constants import StatusIndicators from open_inwoner.openzaak.tests.factories import ( - StatusTranslationFactory, ZaakTypeConfigFactory, ZaakTypeStatusTypeConfigFactory, ) @@ -79,12 +78,6 @@ def test_status_update(self, mock_get_active_app_names: Mock): status2 = factory(Status, data.status_final) status2.statustype = factory(StatusType, data.status_type_final) - # lets test status translation - status2.statustype.omschrijving = "not_translated" - StatusTranslationFactory( - status="not_translated", translation="translated status" - ) - # receive status update case_status_notification_received(user, case, status2) @@ -99,7 +92,7 @@ def test_status_update(self, mock_get_active_app_names: Mock): strip_tags(item.message), escape( _("Case status has been changed to '{status}'").format( - status="translated status" + status=status2.statustype.omschrijving ) ), ) diff --git a/src/open_inwoner/utils/tests/test_translate.py b/src/open_inwoner/utils/tests/test_translate.py deleted file mode 100644 index ceb5871b3b..0000000000 --- a/src/open_inwoner/utils/tests/test_translate.py +++ /dev/null @@ -1,69 +0,0 @@ -from django.test import TestCase - -from open_inwoner.utils.translate import TranslationLookup - - -class TranslationLookupTest(TestCase): - def test_lookup(self): - values_list = [ - ("foo", "FOO"), - ("bar", "BAR"), - ] - lookup = TranslationLookup(values_list) - - tests = [ - # input, expected - ("foo", "FOO"), - ("bar", "BAR"), - ("bazz", "bazz"), - ("", ""), - ] - for value, expected in tests: - with self.subTest(value=value, expected=expected): - actual = lookup(value) - self.assertEqual(expected, actual) - - # extra - with self.subTest("normal key with default returns key"): - actual = lookup("bazz", default="buzz") - self.assertEqual("bazz", actual) - - with self.subTest("empty key with default return default"): - actual = lookup("", default="buzz") - self.assertEqual("buzz", actual) - - def test_lookup_from_glom(self): - values_list = [ - ("foo", "FOO"), - ("bar", "BAR"), - ] - lookup = TranslationLookup(values_list) - - data = { - "aaa": { - "fff": "foo", - "bbb": "bar", - "zzz": "bazz", - }, - } - - tests = [ - # input, expected - ("aaa.fff", "FOO"), - ("aaa.bbb", "BAR"), - ("aaa.zzz", "bazz"), - ("aaa.xxx", ""), - ("", ""), - ] - for value, expected in tests: - with self.subTest(value=value, expected=expected): - actual = lookup.from_glom(data, value) - self.assertEqual(expected, actual) - - with self.subTest("with default"): - actual = lookup.from_glom(data, "aaa.xxx", default="buzz") - self.assertEqual("buzz", actual) - - with self.subTest("with empty default"): - actual = lookup.from_glom(data, "aaa.xxx", default="") - self.assertEqual("", actual) From 7e0c5a5d6616e154d5d59a49372bb3cf87108f25 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Fri, 12 Apr 2024 10:13:30 +0200 Subject: [PATCH 2/3] Fixed unstable test --- src/open_inwoner/accounts/tests/test_user.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/open_inwoner/accounts/tests/test_user.py b/src/open_inwoner/accounts/tests/test_user.py index 8e07eae6f3..dc060b493f 100644 --- a/src/open_inwoner/accounts/tests/test_user.py +++ b/src/open_inwoner/accounts/tests/test_user.py @@ -97,8 +97,8 @@ def test_has_usable_email(self): self.assertFalse(UserFactory(email="test@localhost").has_usable_email()) self.assertFalse(User.is_usable_email("test@localhost")) - actual = list(User.objects.having_usable_email()) - self.assertEqual(actual, [user_ok1, user_ok2]) + actual = set(User.objects.having_usable_email()) + self.assertEqual(actual, {user_ok1, user_ok2}) def test_plan_contact_new_count_methods(self): owner = UserFactory() From f5151ac5b577b50dacf55559662045fa46464fd3 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Thu, 18 Apr 2024 10:25:06 +0200 Subject: [PATCH 3/3] [#2260] PR feedback: use statustekst instead of omschrijving in tests, add default value --- src/open_inwoner/openzaak/api_models.py | 4 +++- src/open_inwoner/openzaak/tests/test_notification_data.py | 2 +- src/open_inwoner/openzaak/tests/test_notification_utils.py | 2 +- src/open_inwoner/userfeed/tests/hooks/test_case_status.py | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/open_inwoner/openzaak/api_models.py b/src/open_inwoner/openzaak/api_models.py index 837b5a4ab2..83bde4f344 100644 --- a/src/open_inwoner/openzaak/api_models.py +++ b/src/open_inwoner/openzaak/api_models.py @@ -4,6 +4,8 @@ from datetime import date, datetime from typing import Optional, Union +from django.utils.translation import gettext as _ + from dateutil.relativedelta import relativedelta from zgw_consumers.api_models.base import Model, ZGWModel from zgw_consumers.api_models.constants import RolOmschrijving, RolTypes @@ -87,7 +89,7 @@ def process_data(self) -> dict: ), default="", ) - status_text = result_text or status_text + status_text = result_text or status_text or _("No data available") return { "identification": self.identification, diff --git a/src/open_inwoner/openzaak/tests/test_notification_data.py b/src/open_inwoner/openzaak/tests/test_notification_data.py index 03e0c6a277..31c36ceb06 100644 --- a/src/open_inwoner/openzaak/tests/test_notification_data.py +++ b/src/open_inwoner/openzaak/tests/test_notification_data.py @@ -84,7 +84,7 @@ def __init__(self): informeren=True, volgnummer=2, omschrijving="final", - statustekst="", + statustekst="status_type_final_statustekst", isEindStatus=True, ) self.zaak = generate_oas_component_cached( diff --git a/src/open_inwoner/openzaak/tests/test_notification_utils.py b/src/open_inwoner/openzaak/tests/test_notification_utils.py index 783a3530a8..07782f43df 100644 --- a/src/open_inwoner/openzaak/tests/test_notification_utils.py +++ b/src/open_inwoner/openzaak/tests/test_notification_utils.py @@ -60,7 +60,7 @@ def test_send_case_update_email(self): body_html = email.alternatives[0][0] self.assertIn(case.identificatie, body_html) self.assertIn(case.zaaktype.omschrijving, body_html) - self.assertIn(status.statustype.omschrijving, body_html) + self.assertIn(status.statustype.statustekst, body_html) self.assertIn(case_url, body_html) self.assertIn(config.name, body_html) diff --git a/src/open_inwoner/userfeed/tests/hooks/test_case_status.py b/src/open_inwoner/userfeed/tests/hooks/test_case_status.py index 241b434d44..c190dad517 100644 --- a/src/open_inwoner/userfeed/tests/hooks/test_case_status.py +++ b/src/open_inwoner/userfeed/tests/hooks/test_case_status.py @@ -92,7 +92,7 @@ def test_status_update(self, mock_get_active_app_names: Mock): strip_tags(item.message), escape( _("Case status has been changed to '{status}'").format( - status=status2.statustype.omschrijving + status=status2.statustype.statustekst ) ), )