Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzbrand committed Jan 17, 2024
1 parent d64e6ad commit 506b535
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
7 changes: 6 additions & 1 deletion home/export_content_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
VariationBlock,
ViberBlock,
SMSBlock,
USSDBlock,
WhatsappBlock,
)

Expand All @@ -31,7 +32,11 @@


MsgBlocks = tuple[
WhatsappBlock | None, SMSBlock | None, MessengerBlock | None, ViberBlock | None
WhatsappBlock | None,
SMSBlock | None,
USSDBlock | None,
MessengerBlock | None,
ViberBlock | None,
]


Expand Down
2 changes: 1 addition & 1 deletion home/import_content_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions home/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
NextMessageButton,
PageView,
WhatsappBlock,
USSDBlock,
)

from .page_builder import PageBuilder, WABlk, WABody
Expand Down Expand Up @@ -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"])

0 comments on commit 506b535

Please sign in to comment.