aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/api/schemas/latest/patchwork.yaml2
-rw-r--r--docs/api/schemas/patchwork.j22
-rw-r--r--docs/api/schemas/v1.0/patchwork.yaml2
-rw-r--r--docs/api/schemas/v1.1/patchwork.yaml2
-rw-r--r--patchwork/api/check.py4
-rw-r--r--patchwork/tests/api/test_check.py17
6 files changed, 29 insertions, 0 deletions
diff --git a/docs/api/schemas/latest/patchwork.yaml b/docs/api/schemas/latest/patchwork.yaml
index e3ba69c..724b05e 100644
--- a/docs/api/schemas/latest/patchwork.yaml
+++ b/docs/api/schemas/latest/patchwork.yaml
@@ -1316,6 +1316,8 @@ components:
nullable: true
CheckCreate:
type: object
+ required:
+ - state
properties:
state:
title: State
diff --git a/docs/api/schemas/patchwork.j2 b/docs/api/schemas/patchwork.j2
index 7d34863..5e2f5e4 100644
--- a/docs/api/schemas/patchwork.j2
+++ b/docs/api/schemas/patchwork.j2
@@ -1319,6 +1319,8 @@ components:
nullable: true
CheckCreate:
type: object
+ required:
+ - state
properties:
state:
title: State
diff --git a/docs/api/schemas/v1.0/patchwork.yaml b/docs/api/schemas/v1.0/patchwork.yaml
index 11e3ae3..02f3a15 100644
--- a/docs/api/schemas/v1.0/patchwork.yaml
+++ b/docs/api/schemas/v1.0/patchwork.yaml
@@ -1311,6 +1311,8 @@ components:
nullable: true
CheckCreate:
type: object
+ required:
+ - state
properties:
state:
title: State
diff --git a/docs/api/schemas/v1.1/patchwork.yaml b/docs/api/schemas/v1.1/patchwork.yaml
index 4e81ac3..0c086ed 100644
--- a/docs/api/schemas/v1.1/patchwork.yaml
+++ b/docs/api/schemas/v1.1/patchwork.yaml
@@ -1316,6 +1316,8 @@ components:
nullable: true
CheckCreate:
type: object
+ required:
+ - state
properties:
state:
title: State
diff --git a/patchwork/api/check.py b/patchwork/api/check.py
index 4d2181d..07d7cb9 100644
--- a/patchwork/api/check.py
+++ b/patchwork/api/check.py
@@ -12,6 +12,7 @@ from rest_framework.generics import RetrieveAPIView
from rest_framework.serializers import CurrentUserDefault
from rest_framework.serializers import HiddenField
from rest_framework.serializers import HyperlinkedModelSerializer
+from rest_framework.serializers import ValidationError
from patchwork.api.base import CheckHyperlinkedIdentityField
from patchwork.api.base import MultipleFieldLookupMixin
@@ -36,6 +37,9 @@ class CheckSerializer(HyperlinkedModelSerializer):
user = UserSerializer(default=CurrentUserDefault())
def run_validation(self, data):
+ if 'state' not in data or data['state'] == '':
+ raise ValidationError({'state': ["A check must have a state."]})
+
for val, label in Check.STATE_CHOICES:
if label != data['state']:
continue
diff --git a/patchwork/tests/api/test_check.py b/patchwork/tests/api/test_check.py
index 1cfdff6..24451ab 100644
--- a/patchwork/tests/api/test_check.py
+++ b/patchwork/tests/api/test_check.py
@@ -151,6 +151,23 @@ class TestCheckAPI(utils.APITestCase):
self.assertEqual(status.HTTP_400_BAD_REQUEST, resp.status_code)
self.assertEqual(0, Check.objects.all().count())
+ @utils.store_samples('check-create-error-missing-state')
+ def test_create_missing_state(self):
+ """Create a check using invalid values.
+
+ Ensure we handle the state being absent.
+ """
+ check = {
+ 'target_url': 'http://t.co',
+ 'description': 'description',
+ 'context': 'context',
+ }
+
+ self.client.force_authenticate(user=self.user)
+ resp = self.client.post(self.api_url(), check)
+ self.assertEqual(status.HTTP_400_BAD_REQUEST, resp.status_code)
+ self.assertEqual(0, Check.objects.all().count())
+
@utils.store_samples('check-create-error-not-found')
def test_create_invalid_patch(self):
"""Ensure we handle non-existent patches."""