From d2b50a172f04c70901e83bdd73a26f1f7a126def Mon Sep 17 00:00:00 2001 From: Hlamalani Date: Tue, 9 Apr 2024 12:42:42 +0200 Subject: [PATCH 1/5] import-export tests to use new form validation --- ...ontent_20230911-variations-linked-page.csv | 4 ++-- .../good-whatsapp-template-vars.csv | 2 +- .../whatsapp_footer_max_characters.csv | 2 +- home/tests/test_content_import_export.py | 24 ++++++++++--------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/home/tests/import-export-data/exported_content_20230911-variations-linked-page.csv b/home/tests/import-export-data/exported_content_20230911-variations-linked-page.csv index 359fccf1..0937ecfb 100644 --- a/home/tests/import-export-data/exported_content_20230911-variations-linked-page.csv +++ b/home/tests/import-export-data/exported_content_20230911-variations-linked-page.csv @@ -6,7 +6,7 @@ Menu 4,0,17,whatsapp-template-testing,,whatsapp template testing,,,,,,,,,,,,,,,, Menu 5,0,164,import-export,,Import Export,,,,,,,,,,,,,,,,,497bdc1f-43fc-4925-80a1-e68cb942faa4,,,,English,,,,,,,, Sub 5.1,1,165,cp-import-export,Import Export,CP-Import/export,,,WA import export data,Message 1 contains an image,,,,,,,,,,,,,8ac50daf-de21-4d05-b697-6d983b7ed3d5,"Tag2, Tag1",Quick reply1,"Trigger2, Trigger1",English,,[],/admin/images/usage/4/,,,ma_qa_temp,, ,1,165,cp-import-export,,,,,,,,gender: male,Variation message one for Gender Male,,,,,,,,,,,,,,,,,,,,,, -,2,165,cp-import-export,,,,,,"Message2 has a document attached, lets add some variable placeholders as well {{0}}",,,,,,,,,,,,,,,,,,,[],,/admin/documents/usage/1/,,,, +,2,165,cp-import-export,,,,,,"Message2 has a document attached, lets add some variable placeholders as well {{0}}",,,,,,,,,,,,,,,,,,,[],,/admin/documents/usage/1/,,,example_values, ,2,165,cp-import-export,,,,,,,,gender: empty,Variation message one for Gender Rather not say,,,,,,,,,,,,,,,,,,,,,, ,3,165,cp-import-export,,,,,,Message 3 with no variation but has an audio clip,,,,,,,,,,,,,,,,,,,[],,,/admin/media/usage/1/,,, -Sub 5.2,1,166,ma_qa_temp,Import Export,MA QA Temp,,,,,,,,,,,,,,,,,e9793b5f-f8c7-46c5-8a5e-bd9b8f00fee9,,,,English,,,,,,,, \ No newline at end of file +Sub 5.2,1,166,ma_qa_temp,Import Export,MA QA Temp,,,,,,,,,,,,,,,,,e9793b5f-f8c7-46c5-8a5e-bd9b8f00fee9,,,,English,,,,,,,, diff --git a/home/tests/import-export-data/good-whatsapp-template-vars.csv b/home/tests/import-export-data/good-whatsapp-template-vars.csv index 4a94ed8b..5584f0e8 100644 --- a/home/tests/import-export-data/good-whatsapp-template-vars.csv +++ b/home/tests/import-export-data/good-whatsapp-template-vars.csv @@ -1,4 +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,,,,,, +{{2}} {{3}}",mnch_appointment_child_2,MARKETING,"Helen,Good, Great",,,,,,,,,,,0c9857a5-e381-49d7-b2fd-123348c4a373,,,,English,,,,,, diff --git a/home/tests/import-export-data/whatsapp_footer_max_characters.csv b/home/tests/import-export-data/whatsapp_footer_max_characters.csv index a7e72024..55da7360 100644 --- a/home/tests/import-export-data/whatsapp_footer_max_characters.csv +++ b/home/tests/import-export-data/whatsapp_footer_max_characters.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 ⬇️",,,This is a long list item that exceed character limit.,Health Info SMS Title,*Health Info SMS Body*,Health Info USSD Title,*Health Info USSD Body*,health info,"*Health information* 🏥 +Get information and advice from WHO by tapping on a button below ⬇️",,,,Health Info SMS Title,*Health Info SMS Body*,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,,[],,,,,[],This is a test footer with a very long footer. This footer has reach maximum characters allowed in the footer. 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_content_import_export.py b/home/tests/test_content_import_export.py index 6e2e06a2..9f9c0e79 100644 --- a/home/tests/test_content_import_export.py +++ b/home/tests/test_content_import_export.py @@ -884,7 +884,7 @@ def test_invalid_wa_template_category(self, csv_impexp: ImportExport) -> None: # FIXME: Find a better way to represent this. assert ( e.value.message - == "Validation error: {'whatsapp_template_category': [\"Value 'Marketing' is not a valid choice.\"]}" + == "Validation error: {'whatsapp_template_category': [ValidationError(['Select a valid choice. Marketing is not one of the available choices.'])]}" ) def test_invalid_wa_template_vars(self, csv_impexp: ImportExport) -> None: @@ -899,7 +899,7 @@ def test_invalid_wa_template_vars(self, csv_impexp: ImportExport) -> None: # FIXME: Find a better way to represent this. assert ( e.value.message - == "Validation error: {'whatsapp_body': ['Validation error in StreamBlock']}" + == "Validation error: {'whatsapp_body': [ValidationError(['Validation error in StreamBlock'])]}" ) def test_invalid_wa_template_vars_update(self, csv_impexp: ImportExport) -> None: @@ -920,7 +920,7 @@ def test_invalid_wa_template_vars_update(self, csv_impexp: ImportExport) -> None # FIXME: Find a better way to represent this. assert ( e.value.message - == "Validation error: {'whatsapp_body': ['Validation error in StreamBlock']}" + == "Validation error: {'whatsapp_body': [ValidationError(['Validation error in StreamBlock'])]}" ) def test_cpi_validation_failure(self, csv_impexp: ImportExport) -> None: @@ -1019,7 +1019,10 @@ def test_list_items_maximum_characters(self, csv_impexp: ImportExport) -> None: assert isinstance(e.value, ImportException) assert e.value.row_num == 4 - assert e.value.message == "list_items too long: Item 123456789101234567890" + assert ( + e.value.message + == "Validation error: {'whatsapp_body': [ValidationError(['Validation error in StreamBlock'])]}" + ) def test_import_ordered_sets_csv(self, csv_impexp: ImportExport) -> None: """ @@ -1424,20 +1427,18 @@ def test_variations(self, impexp: ImportExport) -> None: home_page = HomePage.objects.first() imp_exp = PageBuilder.build_cpi(home_page, "import-export", "Import Export") - m1vars = [ - VarMsg("Single male", gender="male", relationship="single"), - VarMsg("Complicated male", gender="male", relationship="complicated"), - ] - cp_imp_exp_wablks = [ WABlk( "Message 1", next_prompt="Next message", buttons=[NextBtn("Next message")], - variation_messages=m1vars, + variation_messages=[ + VarMsg("Var'n for Single", relationship="single"), + VarMsg("Var'n for Complicated", relationship="complicated"), + ], ), WABlk( - "Message 2, variable placeholders as well {{0}}", + "Message 2", buttons=[PageBtn("Import Export", page=imp_exp)], variation_messages=[VarMsg("Var'n for Rather not say", gender="empty")], ), @@ -1449,6 +1450,7 @@ def test_variations(self, impexp: ImportExport) -> None: title="CP-Import/export", bodies=[WABody("WA import export data", cp_imp_exp_wablks)], ) + # Save and publish cp_imp_exp again so the revision numbers match up after import. rev = cp_imp_exp.save_revision() rev.publish() From d341135950eccff9370636902766a0ed9dfdf138 Mon Sep 17 00:00:00 2001 From: Hlamalani Date: Tue, 9 Apr 2024 13:03:57 +0200 Subject: [PATCH 2/5] fix tests --- home/tests/test_content_import_export.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/home/tests/test_content_import_export.py b/home/tests/test_content_import_export.py index 9f9c0e79..4ef53b4f 100644 --- a/home/tests/test_content_import_export.py +++ b/home/tests/test_content_import_export.py @@ -884,7 +884,7 @@ def test_invalid_wa_template_category(self, csv_impexp: ImportExport) -> None: # FIXME: Find a better way to represent this. assert ( e.value.message - == "Validation error: {'whatsapp_template_category': [ValidationError(['Select a valid choice. Marketing is not one of the available choices.'])]}" + == "Validation error: {'whatsapp_template_category': [\"Value 'Marketing' is not a valid choice.\"]}" ) def test_invalid_wa_template_vars(self, csv_impexp: ImportExport) -> None: @@ -899,7 +899,7 @@ def test_invalid_wa_template_vars(self, csv_impexp: ImportExport) -> None: # FIXME: Find a better way to represent this. assert ( e.value.message - == "Validation error: {'whatsapp_body': [ValidationError(['Validation error in StreamBlock'])]}" + == "Validation error: {'whatsapp_body': ['Validation error in StreamBlock']}" ) def test_invalid_wa_template_vars_update(self, csv_impexp: ImportExport) -> None: @@ -920,7 +920,7 @@ def test_invalid_wa_template_vars_update(self, csv_impexp: ImportExport) -> None # FIXME: Find a better way to represent this. assert ( e.value.message - == "Validation error: {'whatsapp_body': [ValidationError(['Validation error in StreamBlock'])]}" + == "Validation error: {'whatsapp_body': ['Validation error in StreamBlock']}" ) def test_cpi_validation_failure(self, csv_impexp: ImportExport) -> None: @@ -1002,13 +1002,17 @@ def test_ContentPage_required_fields(self, csv_impexp: ImportExport) -> None: def test_footer_maximum_characters(self, csv_impexp: ImportExport) -> None: """ - Importing an CSV file with list_items and and footer characters exceeding maximum charactercount + Importing an CSV file with footer and and footer characters exceeding maximum charactercount """ with pytest.raises(ImportException) as e: csv_impexp.import_file("whatsapp_footer_max_characters.csv") assert isinstance(e.value, ImportException) assert e.value.row_num == 4 + assert ( + e.value.message + == "footer too long: This is a test footer with a very long footer. This footer has reach maximum characters allowed in the footer." + ) def test_list_items_maximum_characters(self, csv_impexp: ImportExport) -> None: """ @@ -1021,7 +1025,7 @@ def test_list_items_maximum_characters(self, csv_impexp: ImportExport) -> None: assert e.value.row_num == 4 assert ( e.value.message - == "Validation error: {'whatsapp_body': [ValidationError(['Validation error in StreamBlock'])]}" + == "list_items too long: Item 123456789101234567890" ) def test_import_ordered_sets_csv(self, csv_impexp: ImportExport) -> None: From 7c0f23c2ef1672ebe24bc0ffe6c89cdd68d13f90 Mon Sep 17 00:00:00 2001 From: Hlamalani Date: Tue, 9 Apr 2024 13:07:10 +0200 Subject: [PATCH 3/5] fix tests --- home/tests/test_content_import_export.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/home/tests/test_content_import_export.py b/home/tests/test_content_import_export.py index 4ef53b4f..6d4622c3 100644 --- a/home/tests/test_content_import_export.py +++ b/home/tests/test_content_import_export.py @@ -1023,10 +1023,7 @@ def test_list_items_maximum_characters(self, csv_impexp: ImportExport) -> None: assert isinstance(e.value, ImportException) assert e.value.row_num == 4 - assert ( - e.value.message - == "list_items too long: Item 123456789101234567890" - ) + assert e.value.message == "list_items too long: Item 123456789101234567890" def test_import_ordered_sets_csv(self, csv_impexp: ImportExport) -> None: """ From 2f05168d9decd78a8afbe754004c87a2cc6ed1a5 Mon Sep 17 00:00:00 2001 From: Hlamalani Date: Tue, 9 Apr 2024 13:19:30 +0200 Subject: [PATCH 4/5] update change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ca15b7b..69116a3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Increased SMS limit to 459 characters - Validate character limit fir footer and list items when importing - Add Document upload extension validation +- Update tests to use model validations and update test data --> ## v1.1.0 From 8cb42bd52ddca9cf6204be6836fc4a0b5136ca5f Mon Sep 17 00:00:00 2001 From: Jeremy Thurgood Date: Wed, 10 Apr 2024 09:53:56 +0200 Subject: [PATCH 5/5] Remove variable from non-template import test csv --- .../exported_content_20230911-variations-linked-page.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/home/tests/import-export-data/exported_content_20230911-variations-linked-page.csv b/home/tests/import-export-data/exported_content_20230911-variations-linked-page.csv index 0937ecfb..15161a9b 100644 --- a/home/tests/import-export-data/exported_content_20230911-variations-linked-page.csv +++ b/home/tests/import-export-data/exported_content_20230911-variations-linked-page.csv @@ -6,7 +6,7 @@ Menu 4,0,17,whatsapp-template-testing,,whatsapp template testing,,,,,,,,,,,,,,,, Menu 5,0,164,import-export,,Import Export,,,,,,,,,,,,,,,,,497bdc1f-43fc-4925-80a1-e68cb942faa4,,,,English,,,,,,,, Sub 5.1,1,165,cp-import-export,Import Export,CP-Import/export,,,WA import export data,Message 1 contains an image,,,,,,,,,,,,,8ac50daf-de21-4d05-b697-6d983b7ed3d5,"Tag2, Tag1",Quick reply1,"Trigger2, Trigger1",English,,[],/admin/images/usage/4/,,,ma_qa_temp,, ,1,165,cp-import-export,,,,,,,,gender: male,Variation message one for Gender Male,,,,,,,,,,,,,,,,,,,,,, -,2,165,cp-import-export,,,,,,"Message2 has a document attached, lets add some variable placeholders as well {{0}}",,,,,,,,,,,,,,,,,,,[],,/admin/documents/usage/1/,,,example_values, +,2,165,cp-import-export,,,,,,"Message2 has a document attached",,,,,,,,,,,,,,,,,,,[],,/admin/documents/usage/1/,,,, ,2,165,cp-import-export,,,,,,,,gender: empty,Variation message one for Gender Rather not say,,,,,,,,,,,,,,,,,,,,,, ,3,165,cp-import-export,,,,,,Message 3 with no variation but has an audio clip,,,,,,,,,,,,,,,,,,,[],,,/admin/media/usage/1/,,, Sub 5.2,1,166,ma_qa_temp,Import Export,MA QA Temp,,,,,,,,,,,,,,,,,e9793b5f-f8c7-46c5-8a5e-bd9b8f00fee9,,,,English,,,,,,,,