Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit 8bbf77b

Browse files
bors[bot]peterbe
andcommitted
Merge #1548
1548: v3 api recipe creation without action|arguments test coverage r=mythmon a=peterbe Fixes #1547 There are *now* two unit tests that try to create a recipe with the v3 api but with `action_id` or `arguments` omitted from the JSON posted. That's actually, "natively", tested in django rest framework. Co-authored-by: Peter Bengtsson <[email protected]>
2 parents cbe27f1 + ba379bd commit 8bbf77b

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

normandy/recipes/api/v3/serializers.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,10 @@ def validate_extra_filter_expression(self, value):
153153
def validate(self, data):
154154
data = super().validate(data)
155155
action = data.get("action")
156-
required_error_msg = serializers.PrimaryKeyRelatedField.default_error_messages["required"]
157-
158156
if action is None:
159-
if not self.instance:
160-
raise serializers.ValidationError({"action_id": required_error_msg})
161157
action = self.instance.action
162158

163159
arguments = data.get("arguments")
164-
165-
if arguments is None and not self.instance:
166-
raise serializers.ValidationError({"arguments": required_error_msg})
167-
168160
if arguments is not None:
169161
# Ensure the value is a dict
170162
if not isinstance(arguments, dict):

normandy/recipes/tests/api/v3/test_api.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,32 @@ def test_creation_when_arguments_are_invalid(self, api_client):
263263
recipes = Recipe.objects.all()
264264
assert recipes.count() == 0
265265

266+
def test_creation_when_arguments_is_missing(self, api_client):
267+
action = ActionFactory(
268+
name="foobarbaz",
269+
arguments_schema={
270+
"type": "object",
271+
"properties": {"message": {"type": "string"}},
272+
"required": ["message"],
273+
},
274+
)
275+
res = api_client.post(
276+
"/api/v3/recipe/",
277+
{
278+
"name": "Test Recipe",
279+
"enabled": True,
280+
"extra_filter_expression": "true",
281+
"action_id": action.id,
282+
},
283+
)
284+
assert res.status_code == 400
285+
assert res.json()["arguments"] == [
286+
serializers.PrimaryKeyRelatedField.default_error_messages["required"]
287+
]
288+
289+
recipes = Recipe.objects.all()
290+
assert recipes.count() == 0
291+
266292
def test_creation_when_arguments_is_a_string(self, api_client):
267293
action = ActionFactory(
268294
name="foobarbaz",

0 commit comments

Comments
 (0)