@@ -35,7 +35,8 @@ def test_single_report(self):
3535 self .assertEqual (1 , len (finding1 .unsaved_vulnerability_ids ))
3636 self .assertEqual ("CVE-2025-9232" , finding1 .unsaved_vulnerability_ids [0 ])
3737 self .assertEqual (
38- "b1fcca57-2efd-44d3-89e9-949e29b61936:CVE-2025-9232:libcrypto3" , finding1 .unique_id_from_tool ,
38+ "b1fcca57-2efd-44d3-89e9-949e29b61936:CVE-2025-9232:libcrypto3" ,
39+ finding1 .unique_id_from_tool ,
3940 )
4041 self .assertIn ("vulnerability scan" , finding1 .tags )
4142 self .assertIn ("image-scanner" , finding1 .tags )
@@ -72,7 +73,8 @@ def test_single_report(self):
7273 # Non-CVE policies should not have vulnerability IDs
7374 self .assertIsNone (finding3 .unsaved_vulnerability_ids )
7475 self .assertEqual (
75- "b1fcca57-2efd-44d3-89e9-949e29b61936:CIS-BENCH-001:web-server" , finding3 .unique_id_from_tool ,
76+ "b1fcca57-2efd-44d3-89e9-949e29b61936:CIS-BENCH-001:web-server" ,
77+ finding3 .unique_id_from_tool ,
7678 )
7779 self .assertIn ("compliance check" , finding3 .tags )
7880 self .assertIn ("compliance-scanner" , finding3 .tags )
@@ -113,3 +115,56 @@ def test_parser_metadata(self):
113115
114116 description = parser .get_description_for_scan_types ("OpenReports" )
115117 self .assertEqual ("Import OpenReports JSON report." , description )
118+
119+ def test_get_tests_single_source (self ):
120+ with sample_path ("openreports_single_report.json" ).open (encoding = "utf-8" ) as test_file :
121+ parser = OpenreportsParser ()
122+ tests = parser .get_tests ("OpenReports" , test_file )
123+
124+ # Should have two tests for the two sources
125+ self .assertEqual (len (tests ), 2 )
126+
127+ # Verify test names
128+ test_names = {test .name for test in tests }
129+ self .assertIn ("image-scanner" , test_names )
130+ self .assertIn ("compliance-scanner" , test_names )
131+
132+ # Find the image-scanner test
133+ image_scanner_test = next (t for t in tests if t .name == "image-scanner" )
134+ self .assertEqual ("image-scanner" , image_scanner_test .type )
135+ self .assertIsNone (image_scanner_test .version )
136+ self .assertEqual (2 , len (image_scanner_test .findings ))
137+
138+ # Verify findings are properly created
139+ finding1 = image_scanner_test .findings [0 ]
140+ self .assertEqual ("CVE-2025-9232 in libcrypto3" , finding1 .title )
141+ self .assertEqual ("Low" , finding1 .severity )
142+ # Verify test is not set - check using hasattr to avoid RelatedObjectDoesNotExist
143+ self .assertFalse (hasattr (finding1 , "test" ) and finding1 .test is not None )
144+
145+ def test_get_tests_multiple_sources (self ):
146+ with sample_path ("openreports_list_format.json" ).open (encoding = "utf-8" ) as test_file :
147+ parser = OpenreportsParser ()
148+ tests = parser .get_tests ("OpenReports" , test_file )
149+
150+ # Should have two tests for the two different sources
151+ self .assertEqual (len (tests ), 2 )
152+
153+ # Verify test names
154+ test_names = {test .name for test in tests }
155+ self .assertIn ("policy-scanner" , test_names )
156+ self .assertIn ("image-scanner" , test_names )
157+
158+ # Find the image-scanner test
159+ image_scanner_test = next (t for t in tests if t .name == "image-scanner" )
160+ self .assertEqual (2 , len (image_scanner_test .findings ))
161+
162+ # Find the policy-scanner test
163+ policy_scanner_test = next (t for t in tests if t .name == "policy-scanner" )
164+ self .assertEqual (1 , len (policy_scanner_test .findings ))
165+
166+ # Verify findings have no test set
167+ for test in tests :
168+ for finding in test .findings :
169+ # Check using hasattr to avoid RelatedObjectDoesNotExist
170+ self .assertFalse (hasattr (finding , "test" ) and finding .test is not None )
0 commit comments