Skip to content

Commit

Permalink
Tests for CP update validation errors during import
Browse files Browse the repository at this point in the history
  • Loading branch information
jerith committed Jan 29, 2024
1 parent ba9cf06 commit bf03020
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions home/tests/bad-whatsapp-template-vars.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,example_values,variation_title,variation_body,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages
Menu 1,0,1303,appointment-reminders,,Appointment reminders,,,,,,,,,,,,,,,,,,8cff04aa-cf08-4120-88b4-e2269b7d5d80,,,,English,,,,,,
Sub 1.13,1,1467,mnch_appointment_child_2,Appointment reminders,Appointment child 2,,,mnch_appointment_child_2,"Hi {{1}}
{{2}} {{4}}",mnch_appointment_child_2,MARKETING,Helen,,,,,,,,,,,0c9857a5-e381-49d7-b2fd-123348c4a373,,,,English,,,,,,
4 changes: 4 additions & 0 deletions home/tests/good-whatsapp-template-vars.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,example_values,variation_title,variation_body,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages
Menu 1,0,1303,appointment-reminders,,Appointment reminders,,,,,,,,,,,,,,,,,,8cff04aa-cf08-4120-88b4-e2269b7d5d80,,,,English,,,,,,
Sub 1.13,1,1467,mnch_appointment_child_2,Appointment reminders,Appointment child 2,,,mnch_appointment_child_2,"Hi {{1}}
{{2}} {{3}}",mnch_appointment_child_2,MARKETING,Helen,,,,,,,,,,,0c9857a5-e381-49d7-b2fd-123348c4a373,,,,English,,,,,,
38 changes: 37 additions & 1 deletion home/tests/test_content_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ def test_missing_related_pages(self, newcsv_impexp: ImportExport) -> None:
def test_invalid_wa_template_category(self, newcsv_impexp: ImportExport) -> None:
"""
Importing a WhatsApp template with an invalid category should raise an
error that results in an error message that gets sent back to the user
error that results in an error message that gets sent back to the user.
"""
with pytest.raises(ImportException) as e:
newcsv_impexp.import_file("bad-whatsapp-template-category.csv")
Expand All @@ -948,6 +948,42 @@ def test_invalid_wa_template_category(self, newcsv_impexp: ImportExport) -> None
== "Validation error: {'whatsapp_template_category': [\"Value 'Marketing' is not a valid choice.\"]}"
)

def test_invalid_wa_template_vars(self, newcsv_impexp: ImportExport) -> None:
"""
Importing a WhatsApp template with invalid variables should raise an
error that results in an error message that gets sent back to the user.
"""
with pytest.raises(ImportException) as e:
newcsv_impexp.import_file("bad-whatsapp-template-vars.csv")

assert e.value.row_num == 3
# FIXME: Find a better way to represent this.
assert (
e.value.message
== "Validation error: {'whatsapp_body': ['Validation error in StreamBlock']}"
)

def test_invalid_wa_template_vars_update(self, newcsv_impexp: ImportExport) -> None:
"""
Updating a valid WhatsApp template with invalid variables should raise
an error that results in an error message that gets sent back to the
user. The update validation happens in a different code path from the
initial import.
"""
newcsv_impexp.import_file("good-whatsapp-template-vars.csv")

# Update an existing page, which does the validation in
# `page.save_revision()` rather than `parent.add_child()`.
with pytest.raises(ImportException) as e:
newcsv_impexp.import_file("bad-whatsapp-template-vars.csv", purge=False)

assert e.value.row_num == 3
# FIXME: Find a better way to represent this.
assert (
e.value.message
== "Validation error: {'whatsapp_body': ['Validation error in StreamBlock']}"
)


# "old-xlsx" has at least three bugs, so we don't bother testing it.
@pytest.fixture(params=["old-csv", "new-csv", "new-xlsx"])
Expand Down

0 comments on commit bf03020

Please sign in to comment.