From 506b53596e26bc575684534c2e2e15bd8dab14c3 Mon Sep 17 00:00:00 2001 From: Fritz Brand Date: Wed, 17 Jan 2024 08:32:47 +0200 Subject: [PATCH] Minor fixes --- home/export_content_pages.py | 7 ++++++- home/import_content_pages.py | 2 +- home/models.py | 8 ++++++++ home/tests/test_models.py | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/home/export_content_pages.py b/home/export_content_pages.py index aa192f06..f8086f37 100644 --- a/home/export_content_pages.py +++ b/home/export_content_pages.py @@ -22,6 +22,7 @@ VariationBlock, ViberBlock, SMSBlock, + USSDBlock, WhatsappBlock, ) @@ -31,7 +32,11 @@ MsgBlocks = tuple[ - WhatsappBlock | None, SMSBlock | None, MessengerBlock | None, ViberBlock | None + WhatsappBlock | None, + SMSBlock | None, + USSDBlock | None, + MessengerBlock | None, + ViberBlock | None, ] diff --git a/home/import_content_pages.py b/home/import_content_pages.py index 85ac4a47..6fb724a8 100644 --- a/home/import_content_pages.py +++ b/home/import_content_pages.py @@ -330,7 +330,7 @@ def add_message_to_shadow_content_page_from_row( if row.is_ussd_message: page.enable_ussd = True - page.ussd_body.append(ShadowSMSBlock(message=row.ussd_body)) + page.ussd_body.append(ShadowUSSDBlock(message=row.ussd_body)) if row.is_messenger_message: page.enable_messenger = True diff --git a/home/models.py b/home/models.py index 5d89ac6d..79d576f3 100644 --- a/home/models.py +++ b/home/models.py @@ -321,6 +321,14 @@ class Meta: icon = "user" form_classname = "whatsapp-message-block struct-block" + def clean(self, value): + result = super().clean(value) + errors = {} + + if errors: + raise StructBlockValidationError(errors) + return result + class ViberBlock(blocks.StructBlock): image = ImageChooserBlock(required=False) diff --git a/home/tests/test_models.py b/home/tests/test_models.py index d362fef9..cec54223 100644 --- a/home/tests/test_models.py +++ b/home/tests/test_models.py @@ -10,6 +10,7 @@ NextMessageButton, PageView, WhatsappBlock, + USSDBlock, ) from .page_builder import PageBuilder, WABlk, WABody @@ -313,3 +314,21 @@ def test_buttons_char_limit(self): with self.assertRaises(StructBlockValidationError) as e: GoToPageButton().clean({"title": "a" * 21}) self.assertEqual(list(e.exception.block_errors.keys()), ["title"]) + + +class USSDBlockTests(TestCase): + def create_message_value( + self, + message="", + ): + return { + "message": message, + } + + def test_clean_text_char_limit(self): + """Text messages should be limited to 160 characters""" + USSDBlock().clean(self.create_message_value(message="a" * 160)) + + with self.assertRaises(StructBlockValidationError) as e: + USSDBlock().clean(self.create_message_value(message="a" * 161)) + self.assertEqual(list(e.exception.block_errors.keys()), ["message"])