@@ -468,3 +468,123 @@ def test_generate_complete_submission_xml_namespace_handling(
468468 assert "http://apply.grants.gov/system/Header-V1.0" in root .nsmap .values ()
469469 assert "http://apply.grants.gov/system/Footer-V1.0" in root .nsmap .values ()
470470 assert "http://apply.grants.gov/system/Global-V1.0" in root .nsmap .values ()
471+
472+ def test_get_supported_forms_filters_non_required_not_included (
473+ self , sample_application , sample_application_submission , enable_factory_create
474+ ):
475+ """Test that non-required forms with is_included_in_submission=False are filtered out."""
476+ # Create a non-required form with XML support
477+ optional_form = FormFactory .create (
478+ form_name = "Optional Form" ,
479+ short_form_name = "OPTIONAL_1_0" ,
480+ form_version = "1.0" ,
481+ json_to_xml_schema = FORM_XML_TRANSFORM_RULES , # Has XML support
482+ )
483+
484+ # Create competition form marked as NOT required
485+ competition_form = CompetitionFormFactory .create (
486+ competition = sample_application .competition ,
487+ form = optional_form ,
488+ is_required = False , # NOT required
489+ )
490+
491+ # Create application form with is_included_in_submission=False
492+ ApplicationFormFactory .create (
493+ application = sample_application ,
494+ competition_form = competition_form ,
495+ application_response = {"some_field" : "some_value" },
496+ is_included_in_submission = False , # NOT included
497+ )
498+
499+ assembler = SubmissionXMLAssembler (sample_application , sample_application_submission )
500+ supported_forms = assembler .get_supported_forms ()
501+
502+ # Should only return SF424_4_0 (required), not the optional form
503+ assert len (supported_forms ) == 1
504+ assert supported_forms [0 ].form .short_form_name == "SF424_4_0"
505+
506+ def test_get_supported_forms_includes_non_required_when_included (
507+ self , sample_application , sample_application_submission , enable_factory_create
508+ ):
509+ """Test that non-required forms with is_included_in_submission=True are included."""
510+ # Create a non-required form with XML support
511+ optional_form = FormFactory .create (
512+ form_name = "Optional Form" ,
513+ short_form_name = "OPTIONAL_1_0" ,
514+ form_version = "1.0" ,
515+ json_to_xml_schema = FORM_XML_TRANSFORM_RULES , # Has XML support
516+ )
517+
518+ # Create competition form marked as NOT required
519+ competition_form = CompetitionFormFactory .create (
520+ competition = sample_application .competition ,
521+ form = optional_form ,
522+ is_required = False , # NOT required
523+ )
524+
525+ # Create application form with is_included_in_submission=True
526+ ApplicationFormFactory .create (
527+ application = sample_application ,
528+ competition_form = competition_form ,
529+ application_response = {"some_field" : "some_value" },
530+ is_included_in_submission = True , # IS included
531+ )
532+
533+ assembler = SubmissionXMLAssembler (sample_application , sample_application_submission )
534+ supported_forms = assembler .get_supported_forms ()
535+
536+ # Should return both SF424_4_0 and the optional form
537+ assert len (supported_forms ) == 2
538+ form_names = {form .form .short_form_name for form in supported_forms }
539+ assert "SF424_4_0" in form_names
540+ assert "OPTIONAL_1_0" in form_names
541+
542+ def test_get_supported_forms_includes_required_regardless_of_is_included (
543+ self , sample_application , sample_application_submission , enable_factory_create , db_session
544+ ):
545+ """Test that required forms are included regardless of is_included_in_submission value."""
546+ # Update the existing SF424 form to have is_included_in_submission=False
547+ # (should still be included because it's required)
548+ sample_application .application_forms [0 ].is_included_in_submission = False
549+ db_session .flush ()
550+
551+ assembler = SubmissionXMLAssembler (sample_application , sample_application_submission )
552+ supported_forms = assembler .get_supported_forms ()
553+
554+ # Should still return SF424_4_0 because it's required
555+ assert len (supported_forms ) == 1
556+ assert supported_forms [0 ].form .short_form_name == "SF424_4_0"
557+
558+ def test_get_supported_forms_filters_non_required_null_is_included (
559+ self , sample_application , sample_application_submission , enable_factory_create
560+ ):
561+ """Test that non-required forms with is_included_in_submission=None are filtered out."""
562+ # Create a non-required form with XML support
563+ optional_form = FormFactory .create (
564+ form_name = "Optional Form" ,
565+ short_form_name = "OPTIONAL_1_0" ,
566+ form_version = "1.0" ,
567+ json_to_xml_schema = FORM_XML_TRANSFORM_RULES , # Has XML support
568+ )
569+
570+ # Create competition form marked as NOT required
571+ competition_form = CompetitionFormFactory .create (
572+ competition = sample_application .competition ,
573+ form = optional_form ,
574+ is_required = False , # NOT required
575+ )
576+
577+ # Create application form with is_included_in_submission=None
578+ ApplicationFormFactory .create (
579+ application = sample_application ,
580+ competition_form = competition_form ,
581+ application_response = {"some_field" : "some_value" },
582+ is_included_in_submission = None , # NULL/None
583+ )
584+
585+ assembler = SubmissionXMLAssembler (sample_application , sample_application_submission )
586+ supported_forms = assembler .get_supported_forms ()
587+
588+ # Should only return SF424_4_0 (required), not the optional form
589+ assert len (supported_forms ) == 1
590+ assert supported_forms [0 ].form .short_form_name == "SF424_4_0"
0 commit comments