1616from services .components import (
1717 ComponentComparison ,
1818 commit_components ,
19- component_filtered_report ,
19+ component_filtered_report , filter_components_by_name_or_id ,
2020)
2121
2222
@@ -158,8 +158,8 @@ def test_base_report(self, base_report_mock):
158158 component_comparison = ComponentComparison (self .comparison , component_go )
159159 assert component_comparison .base_report .files == ["file_1.go" ]
160160 assert (
161- component_comparison .base_report .totals .coverage
162- == report .get ("file_1.go" ).totals .coverage
161+ component_comparison .base_report .totals .coverage
162+ == report .get ("file_1.go" ).totals .coverage
163163 )
164164
165165 @patch ("services.comparison.Comparison.head_report" , new_callable = PropertyMock )
@@ -176,8 +176,8 @@ def test_head_report(self, head_report_mock):
176176 component_comparison = ComponentComparison (self .comparison , component_go )
177177 assert component_comparison .head_report .files == ["file_1.go" ]
178178 assert (
179- component_comparison .head_report .totals .coverage
180- == report .get ("file_1.go" ).totals .coverage
179+ component_comparison .head_report .totals .coverage
180+ == report .get ("file_1.go" ).totals .coverage
181181 )
182182
183183 @patch ("services.comparison.Comparison.git_comparison" , new_callable = PropertyMock )
@@ -221,3 +221,27 @@ def test_patch_totals(self, head_report_mock, git_comparison_mock):
221221
222222 # removed 1 tested line, added 1 tested and 1 untested line
223223 assert component_comparison .patch_totals .coverage == "50.00000"
224+
225+ def test_filter_components_by_name_or_id (self ):
226+ components = [
227+ Component (name = "ComponentA" , component_id = "123" ),
228+ Component (name = "ComponentB" , component_id = "456" ),
229+ Component (name = "ComponentC" , component_id = "789" ),
230+ ]
231+ terms = ["comPOnentA" , "123" , "456" ]
232+
233+ filtered = filter_components_by_name_or_id (components , terms )
234+ self .assertEqual (len (filtered ), 2 )
235+ self .assertEqual (filtered [0 ].name , "ComponentA" )
236+ self .assertEqual (filtered [1 ].component_id , "456" )
237+
238+ def test_filter_components_by_name_or_id_no_matches (self ):
239+ components = [
240+ Component (name = "ComponentA" , component_id = "123" ),
241+ Component (name = "ComponentB" , component_id = "456" ),
242+ Component (name = "ComponentC" , component_id = "789" ),
243+ ]
244+ terms = ["nonexistent" , "000" ]
245+
246+ filtered = filter_components_by_name_or_id (components , terms )
247+ self .assertEqual (len (filtered ), 0 )
0 commit comments