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

Added SMS tests #230

Merged
merged 1 commit into from
Jan 18, 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
12 changes: 12 additions & 0 deletions home/migrations/0044_merge_20240118_1014.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Generated by Django 4.1.11 on 2024-01-18 10:14

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("home", "0041_contentpage_whatsapp_template_lower_case_name"),
("home", "0043_contentpage_enable_ussd_contentpage_ussd_body_and_more"),
]

operations = []
28 changes: 28 additions & 0 deletions home/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,3 +723,31 @@ def test_ussd_content(self, uclient):
response = uclient.get("/api/v2/pages/?ussd=true")
content = json.loads(response.content)
assert content["count"] == 1

def test_sms_content(self, uclient):
"""
If a sms query param is provided, only pages with content for that
platform are returned.
"""
home_page = HomePage.objects.first()
main_menu = PageBuilder.build_cpi(home_page, "main-menu", "Main Menu")
PageBuilder.build_cp(
parent=main_menu,
slug="main-menu-first-time-user",
title="main menu first time user",
bodies=[],
web_body=["Colour"],
)
PageBuilder.build_cp(
parent=main_menu,
slug="health-info",
title="health info",
bodies=[
SBody("health info", [SBlk("*Health information* S")]),
],
)

# it should return only USSD pages if filtered
response = uclient.get("/api/v2/pages/?sms=true")
content = json.loads(response.content)
assert content["count"] == 1
22 changes: 22 additions & 0 deletions home/tests/test_content_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,3 +1667,25 @@ def test_ussd_values(self, new_impexp: ImportExport) -> None:
new_impexp.export_reimport()
imported = new_impexp.get_page_json()
assert imported == orig

def test_sms_values(self, new_impexp: ImportExport) -> None:
"""
ContentPages with SMS messages are preserved
across export/import.

NOTE: Old importer can't handle SMS values.
"""
home_page = HomePage.objects.first()
main_menu = PageBuilder.build_cpi(home_page, "main-menu", "Main Menu")

PageBuilder.build_cp(
parent=main_menu,
slug="ha-menu",
title="HealthAlert menu",
bodies=[SBody("HealthAlert menu", [SBlk("*Welcome to HealthAlert* SMS")])],
)

orig = new_impexp.get_page_json()
new_impexp.export_reimport()
imported = new_impexp.get_page_json()
assert imported == orig
19 changes: 19 additions & 0 deletions home/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
HomePage,
NextMessageButton,
PageView,
SMSBlock,
USSDBlock,
WhatsappBlock,
)
Expand Down Expand Up @@ -332,3 +333,21 @@ def test_clean_text_char_limit(self):
with self.assertRaises(StructBlockValidationError) as e:
USSDBlock().clean(self.create_message_value(message="a" * 161))
self.assertEqual(list(e.exception.block_errors.keys()), ["message"])


class SMSBlockTests(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"""
SMSBlock().clean(self.create_message_value(message="a" * 160))

with self.assertRaises(StructBlockValidationError) as e:
SMSBlock().clean(self.create_message_value(message="a" * 161))
self.assertEqual(list(e.exception.block_errors.keys()), ["message"])