@@ -253,6 +253,94 @@ 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_local_global (self ):
291+ """Test filtering for patches with different labels, one local and
292+ one global (without a project) that have the same name.
293+ """
294+ project_obj = create_project (linkname = 'myproject' )
295+ project_obj2 = create_project (linkname = 'myproject2' )
296+
297+ label_local = create_label (name = 'label' , project = project_obj )
298+ label_local2 = create_label (name = 'label' , project = project_obj2 )
299+ label_global = create_label (name = 'label' , project = None )
300+
301+ person_obj = create_person (email = 'test@example.com' )
302+ state_obj = create_state (name = 'Under Review' )
303+ patch_kwargs = {
304+ 'state' : state_obj ,
305+ 'project' : project_obj ,
306+ 'submitter' : person_obj ,
307+ }
308+ patch_no_labels = create_patch (** patch_kwargs )
309+ patch1 = create_patch (** patch_kwargs , labels = [label_local ])
310+ patch2 = create_patch (** patch_kwargs , labels = [label_global ])
311+ patch3 = create_patch (
312+ ** {'project' : project_obj2 , ** patch_kwargs }, labels = [label_local2 ]
313+ )
314+
315+ resp = self .client .get (self .api_url (), {'labels' : 'label' })
316+ self .assertEqual (
317+ [patch1 .id , patch2 .id , patch3 .id ], [x ['id' ] for x in resp .data ]
318+ )
319+
320+ resp = self .client .get (self .api_url (), {'labels' : '-label' })
321+ self .assertEqual ([patch_no_labels .id ], [x ['id' ] for x in resp .data ])
322+
323+ def test_list_filter_labels_case_insensitive (self ):
324+ """Test if filtering by label is case-insensitive."""
325+ label = create_label (name = 'RFC' )
326+
327+ person_obj = create_person (email = 'test@example.com' )
328+ project_obj = create_project (linkname = 'myproject' )
329+ state_obj = create_state (name = 'Under Review' )
330+ patch_kwargs = {
331+ 'state' : state_obj ,
332+ 'project' : project_obj ,
333+ 'submitter' : person_obj ,
334+ }
335+ create_patch (** patch_kwargs )
336+ patch1 = create_patch (** patch_kwargs , labels = [label ])
337+
338+ resp = self .client .get (self .api_url (), {'labels' : 'RFC' })
339+ self .assertEqual ([patch1 .id ], [x ['id' ] for x in resp .data ])
340+
341+ resp = self .client .get (self .api_url (), {'labels' : 'rfc' })
342+ self .assertEqual ([patch1 .id ], [x ['id' ] for x in resp .data ])
343+
256344 @utils .store_samples ('patch-list-1-0' )
257345 def test_list_version_1_0 (self ):
258346 """List patches using API v1.0."""
0 commit comments