project = ProjectSerializer(read_only=True)
state = StateField()
submitter = PersonSerializer(read_only=True)
- delegate = UserSerializer()
+ delegate = UserSerializer(allow_null=True)
mbox = SerializerMethodField()
series = SeriesSerializer(many=True, read_only=True)
comments = SerializerMethodField()
def validate_delegate(self, value):
"""Check that the delgate is a maintainer of the patch's project."""
+ if not value:
+ return value
+
if not self.instance.project.maintainer_project.filter(
id=value.id).exists():
raise ValidationError("User '%s' is not a maintainer for project "
self.assertEqual(Patch.objects.get(id=patch.id).state, state)
self.assertEqual(Patch.objects.get(id=patch.id).delegate, user)
+ # (who can unset fields too)
+ # we need to send as JSON due to https://stackoverflow.com/q/30677216/
+ resp = self.client.patch(self.api_url(patch.id), {'delegate': None},
+ format='json')
+ self.assertEqual(status.HTTP_200_OK, resp.status_code, resp)
+ self.assertIsNone(Patch.objects.get(id=patch.id).delegate)
+
def test_update_invalid(self):
"""Ensure we handle invalid Patch updates."""
project = create_project()