@@ -529,6 +529,49 @@ def test_update_maintainer_version_1_0(self):
529529 self .assertEqual (Patch .objects .get (id = patch .id ).state , state )
530530 self .assertEqual (Patch .objects .get (id = patch .id ).delegate , user )
531531
532+ def test_update_labels (self ):
533+ """Update labels as maintainer."""
534+ project = create_project ()
535+ project2 = create_project ()
536+ label1 = create_label (name = 'label' , project = project )
537+ label2 = create_label (name = 'label2' )
538+ label_p2 = create_label (name = 'label_p2' , project = project2 )
539+ label1_global = create_label (name = 'label' , project = None )
540+ patch = create_patch (project = project , labels = [label1_global ])
541+ user = create_maintainer (project )
542+
543+ # Test adding labels labels, make sure local labels are prioritized
544+
545+ self .client .authenticate (user = user )
546+ resp = self .client .patch (
547+ self .api_url (patch .id ), {'labels' : [label1 .name , label2 .name ]}
548+ )
549+ self .assertEqual (status .HTTP_200_OK , resp .status_code , resp )
550+ self .assertEqual (
551+ sorted (
552+ Patch .objects .get (id = patch .id ).labels .values_list (
553+ 'id' , flat = True
554+ )
555+ ),
556+ sorted ([label1 .id , label2 .id ]),
557+ )
558+
559+ # Test removing labels
560+
561+ self .client .authenticate (user = user )
562+ resp = self .client .patch (self .api_url (patch .id ), {'labels' : []})
563+ self .assertEqual (status .HTTP_200_OK , resp .status_code , resp )
564+ self .assertEqual (Patch .objects .get (id = patch .id ).labels .count (), 0 )
565+
566+ # Make sure labels from other projects cannot be added
567+
568+ self .client .authenticate (user = user )
569+ resp = self .client .patch (
570+ self .api_url (patch .id ), {'labels' : [label1 .name , label_p2 .name ]}
571+ )
572+ self .assertEqual (status .HTTP_400_BAD_REQUEST , resp .status_code , resp )
573+ self .assertEqual (Patch .objects .get (id = patch .id ).labels .count (), 0 )
574+
532575 @utils .store_samples ('patch-update-error-bad-request' )
533576 def test_update_invalid_state (self ):
534577 """Update patch with invalid fields.
0 commit comments