[PATCH v4 07/10] REST: Add Patch Checks to the API
andy.doan at linaro.org
Fri May 27 11:12:31 AEST 2016
On 05/25/2016 07:49 AM, Finucane, Stephen wrote:
> On 20 May 14:17, Andy Doan wrote:
>> This exports patch checks via the REST API.
>> The drf-nested-routers package is used to handle the fact Checks are
>> nested under a Patch.
>> Security Constraints:
>> * Anyone (logged in or not) can read all objects.
>> * No one can update/delete objects.
>> * Project maintainers and patch owners may create objects.
>> Signed-off-by: Andy Doan <andy.doan at linaro.org>
> One request, then we're done.
>> patchwork/rest_serializers.py | 35 ++++++++++++++-
>> patchwork/tests/test_rest_api.py | 92 +++++++++++++++++++++++++++++++++++++++-
>> patchwork/urls.py | 6 +--
>> patchwork/views/rest_api.py | 40 ++++++++++++++++-
>> requirements-test.txt | 1 +
>> 5 files changed, 166 insertions(+), 8 deletions(-)
>> diff --git a/patchwork/rest_serializers.py b/patchwork/rest_serializers.py
>> +class ChecksSerializer(ModelSerializer):
>> + class Meta:
>> + model = Check
>> + user = PrimaryKeyRelatedField(read_only=True, default=CurrentUserDefault())
>> + patch = HiddenField(default=CurrentPatchDefault())
>> + def run_validation(self, data):
>> + for val, label in Check.STATE_CHOICES:
>> + if label == data['state']:
>> + data['state'] = val
>> + break
>> + return super(ChecksSerializer, self).run_validation(data)
>> + def to_representation(self, instance):
>> + data = super(ChecksSerializer, self).to_representation(instance)
>> + data['state'] = instance.get_state_display()
>> + data['user'] = instance.user.username
> nit: s/user/username/. Also, should we add a 'user_url' link, as
> suggested for 'people' endpoint?
I actually just made it "user" but show the URL to the user endpoint.
This should be consistent with how things are elsewhere in this patch-set.
>> diff --git a/requirements-test.txt b/requirements-test.txt
>> index b5f976c..cfc242f 100644
>> --- a/requirements-test.txt
>> +++ b/requirements-test.txt
>> @@ -3,3 +3,4 @@ django-debug-toolbar==1.4
I thought about that, but 0.11.1 is current and tested against. I'm not
sure we should advertise an older untested version?
More information about the Patchwork