@@ -253,6 +253,60 @@ def test_list_filter_msgid(self):
253253 resp = self .client .get (self .api_url (), {'msgid' : 'fishfish@fish.fish' })
254254 self .assertEqual (0 , len (resp .data ))
255255
256+ def test_list_filter_labels (self ):
257+ """Filter patches by labels."""
258+ label1 = create_label ()
259+ label2 = create_label ()
260+ label3 = create_label ()
261+
262+ person_obj = create_person (email = 'test@example.com' )
263+ project_obj = create_project (linkname = 'myproject' )
264+ state_obj = create_state (name = 'Under Review' )
265+ patch_kwargs = {
266+ 'state' : state_obj ,
267+ 'project' : project_obj ,
268+ 'submitter' : person_obj ,
269+ }
270+ patch_no_labels = create_patch (** patch_kwargs )
271+ patch1 = create_patch (** patch_kwargs , labels = [label1 ])
272+ patch2 = create_patch (** patch_kwargs , labels = [label1 , label2 ])
273+
274+ resp = self .client .get (self .api_url (), {'labels' : label1 .name })
275+ self .assertEqual ([patch1 .id , patch2 .id ], [x ['id' ] for x in resp .data ])
276+
277+ resp = self .client .get (self .api_url (), {'labels' : label3 .name })
278+ self .assertEqual (0 , len (resp .data ))
279+
280+ resp = self .client .get (self .api_url (), {'labels' : '-' + label2 .name })
281+ self .assertEqual (
282+ [patch_no_labels .id , patch1 .id ], [x ['id' ] for x in resp .data ]
283+ )
284+
285+ resp = self .client .get (
286+ self .api_url (), {'labels' : label1 .name + ',' + label2 .name }
287+ )
288+ self .assertEqual ([patch2 .id ], [x ['id' ] for x in resp .data ])
289+
290+ def test_list_filter_labels_case_insensitive (self ):
291+ label = create_label (name = 'RFC' )
292+
293+ person_obj = create_person (email = 'test@example.com' )
294+ project_obj = create_project (linkname = 'myproject' )
295+ state_obj = create_state (name = 'Under Review' )
296+ patch_kwargs = {
297+ 'state' : state_obj ,
298+ 'project' : project_obj ,
299+ 'submitter' : person_obj ,
300+ }
301+ create_patch (** patch_kwargs )
302+ patch1 = create_patch (** patch_kwargs , labels = [label ])
303+
304+ resp = self .client .get (self .api_url (), {'labels' : 'RFC' })
305+ self .assertEqual ([patch1 .id ], [x ['id' ] for x in resp .data ])
306+
307+ resp = self .client .get (self .api_url (), {'labels' : 'rfc' })
308+ self .assertEqual ([patch1 .id ], [x ['id' ] for x in resp .data ])
309+
256310 @utils .store_samples ('patch-list-1-0' )
257311 def test_list_version_1_0 (self ):
258312 """List patches using API v1.0."""
0 commit comments