Skip to content

Commit

Permalink
Fix export for whatsapp with docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit Vermeulen committed Feb 22, 2024
1 parent 45b1d24 commit 64296be
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion home/export_content_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def add_message_fields(self, msg_blocks: MsgBlocks) -> None:
if "image" in whatsapp.value and whatsapp.value["image"] is not None:
self.image_link = whatsapp.value["image"].file.url
if "document" in whatsapp.value:
self.doc_link = whatsapp.value["document"]
self.doc_link = whatsapp.value["document"].file.url
if "media" in whatsapp.value and whatsapp.value["media"] is not None:
self.media_link = whatsapp.value["media"].file.url
if "next_prompt" in whatsapp.value:
Expand Down
1 change: 1 addition & 0 deletions home/tests/page_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class WABlk(ContentBlock):
buttons: list[Btn] = field(default_factory=list)
list_items: list[str] = field(default_factory=list)
media: int | None = None
document: str | None = None
footer: str = ""

def to_dict(self) -> dict[str, Any]:
Expand Down
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 @@ -15,6 +15,7 @@
from django.core.files.images import ImageFile # type: ignore
from openpyxl import load_workbook
from pytest_django.fixtures import SettingsWrapper
from wagtail.documents.models import Document # type: ignore
from wagtail.images.models import Image # type: ignore
from wagtail.models import Locale, Page # type: ignore
from wagtailmedia.models import Media # type: ignore
Expand Down Expand Up @@ -1076,6 +1077,24 @@ def test_export_wa_with_media(self, impexp: ImportExport) -> None:
# Export should succeed
assert content is not None

def test_export_wa_with_document(self, impexp: ImportExport) -> None:
doc_path = Path("home/tests/test_static") / "test.txt"
doc_wa = mk_doc(doc_path, "wa_document")

home_page = HomePage.objects.first()
main_menu = PageBuilder.build_cpi(home_page, "main-menu", "Main Menu")
_ha_menu = PageBuilder.build_cp(
parent=main_menu,
slug="ha-menu",
title="HealthAlert menu",
bodies=[
WABody("HA menu", [WABlk("Welcome WA", document=doc_wa.id)]),
],
)
content = impexp.export_content(locale="en")
# Export should succeed
assert content is not None


@pytest.fixture(params=["csv", "xlsx"])
def impexp(request: Any, admin_client: Any) -> ImportExport:
Expand All @@ -1098,6 +1117,11 @@ def mk_media(media_path: Path, title: str) -> File:
media.save()
return media

def mk_doc(doc_path: Path, title: str) -> Image:
doc = Document(title=title, file=File(doc_path.open("rb"), name=doc_path.name))
doc.save()
return doc


@pytest.mark.usefixtures("tmp_media_path")
@pytest.mark.django_db
Expand Down
3 changes: 3 additions & 0 deletions home/tests/test_static/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is a test text file.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ac odio eu nisl fermentum vestibulum. Curabitur ac sapien eu odio congue luctus. Suspendisse potenti. Vivamus ut semper velit.

0 comments on commit 64296be

Please sign in to comment.