@@ -711,3 +711,125 @@ def test_list_ofa_admin_data_file_years_no_self_stt(
711711 assert response .status_code == status .HTTP_200_OK
712712
713713 assert response .data == [2020 , 2021 , 2022 ]
714+
715+
716+ class TestDataFileQuerysetFiltering :
717+ """Tests for the get_queryset filtering logic with program_type and is_program_audit combinations.
718+
719+ Note: Program integrity audit (is_program_audit=True) only applies to TANF files.
720+ Tribal, SSP, and FRA files do not have audit variants.
721+ """
722+
723+ root_url = "/v1/data_files/"
724+
725+ @pytest .fixture
726+ def tanf_non_audit_file (self , data_analyst , stt ):
727+ """Create a TANF file with is_program_audit=False."""
728+ return DataFile .create_new_version (
729+ {
730+ "original_filename" : "tanf_non_audit.txt" ,
731+ "user" : data_analyst ,
732+ "stt" : stt ,
733+ "year" : 2024 ,
734+ "quarter" : "Q1" ,
735+ "section" : "Active Case Data" ,
736+ "program_type" : DataFile .ProgramType .TANF ,
737+ "is_program_audit" : False ,
738+ }
739+ )
740+
741+ @pytest .fixture
742+ def tanf_audit_file (self , data_analyst , stt ):
743+ """Create a TANF file with is_program_audit=True."""
744+ return DataFile .create_new_version (
745+ {
746+ "original_filename" : "tanf_audit.txt" ,
747+ "user" : data_analyst ,
748+ "stt" : stt ,
749+ "year" : 2024 ,
750+ "quarter" : "Q1" ,
751+ "section" : "Active Case Data" ,
752+ "program_type" : DataFile .ProgramType .TANF ,
753+ "is_program_audit" : True ,
754+ }
755+ )
756+
757+ @pytest .fixture
758+ def tribal_file (self , data_analyst , stt ):
759+ """Create a TRIBAL file (is_program_audit is always False for Tribal)."""
760+ return DataFile .create_new_version (
761+ {
762+ "original_filename" : "tribal.txt" ,
763+ "user" : data_analyst ,
764+ "stt" : stt ,
765+ "year" : 2024 ,
766+ "quarter" : "Q1" ,
767+ "section" : "Active Case Data" ,
768+ "program_type" : DataFile .ProgramType .TRIBAL ,
769+ "is_program_audit" : False ,
770+ }
771+ )
772+
773+ @pytest .mark .django_db
774+ def test_tanf_non_audit_appears_in_regular_list (
775+ self , api_client , data_analyst , stt , tanf_non_audit_file , tanf_audit_file
776+ ):
777+ """Test TANF file with is_program_audit=False appears in regular file list."""
778+ api_client .login (username = data_analyst .username , password = "test_password" )
779+
780+ response = api_client .get (f"{ self .root_url } ?stt={ stt .id } &year=2024&quarter=Q1" )
781+
782+ assert response .status_code == status .HTTP_200_OK
783+ file_ids = [f ["id" ] for f in response .data ]
784+ assert len (file_ids ) == 1
785+ assert tanf_non_audit_file .id in file_ids
786+ assert tanf_audit_file .id not in file_ids
787+
788+ @pytest .mark .django_db
789+ def test_tanf_audit_appears_in_program_integrity_audit_list (
790+ self , api_client , data_analyst , stt , tanf_non_audit_file , tanf_audit_file
791+ ):
792+ """Test TANF file with is_program_audit=True appears in program-integrity-audit list."""
793+ api_client .login (username = data_analyst .username , password = "test_password" )
794+
795+ response = api_client .get (
796+ f"{ self .root_url } ?stt={ stt .id } &year=2024&quarter=Q1&file_type=program-integrity-audit"
797+ )
798+
799+ assert response .status_code == status .HTTP_200_OK
800+ file_ids = [f ["id" ] for f in response .data ]
801+ assert len (file_ids ) == 1
802+ assert tanf_audit_file .id in file_ids
803+ assert tanf_non_audit_file .id not in file_ids
804+
805+ @pytest .mark .django_db
806+ def test_tribal_appears_in_regular_list (
807+ self , api_client , data_analyst , stt , tribal_file , tanf_audit_file
808+ ):
809+ """Test TRIBAL file appears in regular file list alongside TANF non-audit files."""
810+ api_client .login (username = data_analyst .username , password = "test_password" )
811+
812+ response = api_client .get (f"{ self .root_url } ?stt={ stt .id } &year=2024&quarter=Q1" )
813+
814+ assert response .status_code == status .HTTP_200_OK
815+ file_ids = [f ["id" ] for f in response .data ]
816+ assert len (file_ids ) == 1
817+ assert tribal_file .id in file_ids
818+ assert tanf_audit_file .id not in file_ids
819+
820+ @pytest .mark .django_db
821+ def test_tribal_excluded_from_program_integrity_audit_list (
822+ self , api_client , data_analyst , stt , tribal_file , tanf_audit_file
823+ ):
824+ """Test TRIBAL files are excluded from program-integrity-audit list (only TANF audit files appear)."""
825+ api_client .login (username = data_analyst .username , password = "test_password" )
826+
827+ response = api_client .get (
828+ f"{ self .root_url } ?stt={ stt .id } &year=2024&quarter=Q1&file_type=program-integrity-audit"
829+ )
830+
831+ assert response .status_code == status .HTTP_200_OK
832+ file_ids = [f ["id" ] for f in response .data ]
833+ assert len (file_ids ) == 1
834+ assert tanf_audit_file .id in file_ids
835+ assert tribal_file .id not in file_ids
0 commit comments