Skip to content

Commit

Permalink
Updates after PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzbrand committed Jan 18, 2024
1 parent 29b52ce commit c10a58b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 5 deletions.
2 changes: 1 addition & 1 deletion home/tests/content2.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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* 🌬️
Expand Down
61 changes: 57 additions & 4 deletions home/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"],
Expand All @@ -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"],
)
Expand All @@ -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"],
)
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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
24 changes: 24 additions & 0 deletions home/tests/test_content_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
PageBuilder,
SBlk,
SBody,
UBlk,
UBody,
VarMsg,
VBlk,
VBody,
Expand Down Expand Up @@ -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

0 comments on commit c10a58b

Please sign in to comment.