1111 SERVICE_ONE_ID ,
1212 create_template ,
1313 normalize_spaces ,
14+ sample_uuid ,
1415)
1516
1617
@@ -572,13 +573,43 @@ def test_create_file_redirects_to_manage_files_page(
572573 _follow_redirects = True ,
573574 )
574575 assert mock_create_file .call_args [1 ]["pending" ] # check the created file is set to pending
575- assert normalize_spaces (page .select_one (".govuk-button" )) == "Add to template"
576+ assert normalize_spaces (page .select_one ("form .govuk-button" )) == "Add to template"
577+ assert page .select_one ("form" ).get ("method" ) == "post"
576578 assert (
577- page .select_one (".govuk-button " ).get ("href " )
579+ page .select_one ("form " ).get ("action " )
578580 == f"/services/{ SERVICE_ONE_ID } /templates/{ fake_uuid } /files/{ file_id } /make-live"
579581 )
580582
581583
584+ def test_make_live_is_post_only (client_request , service_one , fake_uuid ):
585+ service_one ["permissions" ] += ["send_files_via_ui" ]
586+ client_request .get (
587+ "main.make_file_live" ,
588+ service_id = SERVICE_ONE_ID ,
589+ template_id = fake_uuid ,
590+ template_email_file_id = fake_uuid ,
591+ _expected_status = 405 ,
592+ _test_page_title = False ,
593+ )
594+
595+
596+ @pytest .mark .parametrize (
597+ "template_content, expected_calls" ,
598+ (
599+ (
600+ "Template content" ,
601+ [
602+ call (
603+ template_id = sample_uuid (),
604+ service_id = SERVICE_ONE_ID ,
605+ content = "Template content\n \n ((test_file_1.csv))" ,
606+ )
607+ ],
608+ ),
609+ ("Already has placeholder ((test_file_1.csv))" , []),
610+ ("Already has placeholder in different case/whitespace ((TEST FILE 1.csv))" , []),
611+ ),
612+ )
582613def test_make_live_endpoint_calls_update_with_correct_args (
583614 client_request ,
584615 service_one ,
@@ -588,6 +619,8 @@ def test_make_live_endpoint_calls_update_with_correct_args(
588619 active_user_with_permissions ,
589620 mock_update_service ,
590621 mock_get_service_email_template ,
622+ template_content ,
623+ expected_calls ,
591624):
592625 service_one ["permissions" ] += ["send_files_via_ui" ]
593626 mocker .patch (
@@ -596,6 +629,7 @@ def test_make_live_endpoint_calls_update_with_correct_args(
596629 "data" : create_template (
597630 template_id = fake_uuid ,
598631 template_type = "email" ,
632+ content = template_content ,
599633 )
600634 },
601635 )
@@ -614,22 +648,17 @@ def test_make_live_endpoint_calls_update_with_correct_args(
614648 )
615649 mock_template_update = mocker .patch ("app.service_api_client.update_service_template" )
616650 mock_template_email_file_update = mocker .patch ("app.models.template_email_file.TemplateEmailFile.update" )
617- client_request .get (
651+ page = client_request .post (
618652 "main.make_file_live" ,
619653 service_id = SERVICE_ONE_ID ,
620654 template_id = fake_uuid ,
621655 template_email_file_id = file_data ["id" ],
622- _expected_status = 302 ,
623- _expected_redirect = url_for (
624- "main.view_template" ,
625- service_id = SERVICE_ONE_ID ,
626- template_id = fake_uuid ,
627- ),
628- )
629- mock_template_update .assert_called_once_with (
630- template_id = fake_uuid , service_id = SERVICE_ONE_ID , content = f"Template content\n \n (({ file_data ['filename' ]} ))"
656+ _follow_redirects = True ,
631657 )
632- mock_template_email_file_update .assert_called_once_with (pending = False )
658+ assert mock_template_update .call_args_list == expected_calls
659+ assert mock_template_email_file_update .call_args_list == [call (pending = False )]
660+ assert normalize_spaces (page .select_one ("h1.folder-heading" )) == "sample template"
661+ assert normalize_spaces (page .select_one (".banner-default-with-tick" )) == "‘test_file_1.csv’ added to template"
633662
634663
635664@pytest .mark .parametrize ("pending" , [True , False ])
@@ -897,48 +926,14 @@ def test_upload_file_page_validates_extentions(
897926 assert not error_message
898927
899928
900- def test_file_upload_calls_template_update (
901- client_request ,
902- fake_uuid ,
903- service_one ,
904- mocker ,
905- ):
906- service_one ["permissions" ] += ["send_files_via_ui" ]
907- service_one ["contact_link" ] = "https://example.com"
908- mocker .patch (
909- "app.service_api_client.get_service_template" ,
910- return_value = {
911- "data" : create_template (
912- template_id = fake_uuid ,
913- template_type = "email" ,
914- content = "This is a file with a file placeholder" ,
915- )
916- },
917- )
918- mock_antivirus = mocker .patch ("app.extensions.antivirus_client.scan" , return_value = True )
919- mock_s3 = mocker .patch ("app.s3_client.s3_template_email_file_upload_client.utils_s3upload" )
920- mock_post = mocker .patch ("app.template_email_file_client.post" )
921- with open ("tests/test_pdf_files/one_page_pdf.pdf" , "rb" ) as file :
922- client_request .post (
923- "main.upload_template_email_files" ,
924- service_id = SERVICE_ONE_ID ,
925- template_id = fake_uuid ,
926- _data = {"file" : file },
927- _expected_status = 302 ,
928- )
929- assert mock_antivirus .called
930- assert mock_s3 .called
931- assert mock_post .called
932-
933-
934929@pytest .mark .parametrize (
935930 "template_content" ,
936931 (
932+ "This is a file with a file placeholder" ,
937933 "This is a file with a file placeholder ((tests/test_pdf_files/one_page_pdf.pdf))" ,
938- "This is a file with a file placeholder ((tests/test_pdf_files/ONE-PAGE PDF.PDF))" ,
939934 ),
940935)
941- def test_upload_file_does_not_update_template_when_placeholder_already_exists (
936+ def test_upload_file_does_not_update_template_content (
942937 client_request ,
943938 fake_uuid ,
944939 service_one ,
0 commit comments