diff --git a/home/tests/content2.csv b/home/tests/content2.csv index 66baa5a4..89f9d32f 100644 --- a/home/tests/content2.csv +++ b/home/tests/content2.csv @@ -15,7 +15,7 @@ You can return to this main menu at any time by replying 🏠 Choose what you'd like to know more about by tapping a button below ⬇️",,,5892bccd-8025-419d-9a8e-a6a37b755dbf,menu,"Self-help🌬️, Settings⚙️, Health Info🏥",Main menu🏠,English,,[],,,,,[] Sub 1.1.1,1,,health-info,main menu first time user,health info,,,health info,"*Health information* 🏥 -Get information and advice from WHO by tapping on a button below ⬇️",,,,,,,health info,"*Health information* 🏥 +Get information and advice from WHO by tapping on a button below ⬇️",,,,,Health Info USSD Title,*Health Info USSD Body*,health info,"*Health information* 🏥 Get information and advice from WHO by tapping on a button below ⬇️",,,c9d6309e-173f-4c1d-bbaf-440b1fd4415f,health_info,,,English,,[],,,,,[] Sub 1.1.2,1,,self-help,main menu first time user,self-help,,,self-help,"*Self-help programs* 🌬️ diff --git a/home/tests/test_api.py b/home/tests/test_api.py index fef45625..33ca22ba 100644 --- a/home/tests/test_api.py +++ b/home/tests/test_api.py @@ -14,7 +14,17 @@ VariationBlock, ) -from .page_builder import MBlk, MBody, PageBuilder, SBlk, SBody, WABlk, WABody +from .page_builder import ( + MBlk, + MBody, + PageBuilder, + SBlk, + SBody, + UBlk, + UBody, + WABlk, + WABody, +) from .utils import create_page @@ -47,6 +57,7 @@ def create_test_data(self): "main menu first time user", [MBlk("*Welcome to HealthAlert* 🌍")] ), SBody("main menu first time user", [SBlk("*Welcome to HealthAlert*")]), + UBody("main menu first time user", [UBlk("*Welcome to HealthAlert*")]), ], tags=["menu"], quick_replies=["Self-help", "Settings", "Health Info"], @@ -59,7 +70,8 @@ def create_test_data(self): bodies=[ WABody("health info", [WABlk("*Health information* 🏥")]), MBody("health info", [MBlk("*Health information* 🏥")]), - SBody("health info", [SBlk("*Health information* 🏥")]), + SBody("health info", [SBlk("*Health information* ")]), + UBody("health info", [UBlk("*Health information* ")]), ], tags=["health_info"], ) @@ -70,7 +82,8 @@ def create_test_data(self): bodies=[ WABody("self-help", [WABlk("*Self-help programs* 🌬️")]), MBody("self-help", [MBlk("*Self-help programs* 🌬️")]), - SBody("self-help", [SBlk("*Self-help programs* 🌬️")]), + SBody("self-help", [SBlk("*Self-help programs*")]), + UBody("self-help", [UBlk("*Self-help programs*")]), ], tags=["self_help"], ) @@ -644,6 +657,14 @@ def test_platform_filtering(self, uclient): SBody("self-help-sms", [SBlk("*Self-help programs*SMS")]), ], ) + PageBuilder.build_cp( + parent=main_menu, + slug="self-help-ussd", + title="self-help-ussd", + bodies=[ + UBody("self-help-ussd", [UBlk("*Self-help programs* USSD")]), + ], + ) # it should return only web pages if filtered response = uclient.get("/api/v2/pages/?web=true") @@ -657,6 +678,10 @@ def test_platform_filtering(self, uclient): response = uclient.get("/api/v2/pages/?sms=true") content = json.loads(response.content) assert content["count"] == 1 + # it should return only ussd pages if filtered + response = uclient.get("/api/v2/pages/?ussd=true") + content = json.loads(response.content) + assert content["count"] == 1 # it should return only messenger pages if filtered response = uclient.get("/api/v2/pages/?messenger=true") content = json.loads(response.content) @@ -669,4 +694,32 @@ def test_platform_filtering(self, uclient): response = uclient.get("/api/v2/pages/") content = json.loads(response.content) # exclude home pages and index pages - assert content["count"] == 4 + assert content["count"] == 5 + + def test_ussd_content(self, uclient): + """ + If a ussd 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=[ + UBody("health info", [UBlk("*Health information* U")]), + ], + ) + + # it should return only USSD pages if filtered + response = uclient.get("/api/v2/pages/?ussd=true") + content = json.loads(response.content) + assert content["count"] == 1 diff --git a/home/tests/test_content_import_export.py b/home/tests/test_content_import_export.py index 3e86c91f..b1d11daa 100644 --- a/home/tests/test_content_import_export.py +++ b/home/tests/test_content_import_export.py @@ -31,6 +31,8 @@ PageBuilder, SBlk, SBody, + UBlk, + UBody, VarMsg, VBlk, VBody, @@ -1643,3 +1645,25 @@ def test_export_missing_related_page(self, impexp: ImportExport) -> None: impexp.export_reimport() imported = impexp.get_page_json() assert imported == orig_without_self_help + + def test_ussd_values(self, new_impexp: ImportExport) -> None: + """ + ContentPages with USSD messages are preserved + across export/import. + + NOTE: Old importer can't handle USSD 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=[UBody("HealthAlert menu", [UBlk("*Welcome to HealthAlert* USSD")])], + ) + + orig = new_impexp.get_page_json() + new_impexp.export_reimport() + imported = new_impexp.get_page_json() + assert imported == orig