Skip to content

Commit

Permalink
Prevent to create an empty AT content.
Browse files Browse the repository at this point in the history
See #1386
  • Loading branch information
gbastien committed Apr 27, 2022
1 parent 513bc42 commit d5fc465
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions news/1386.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Prevent to create an empty AT content.
[gbastien]
2 changes: 1 addition & 1 deletion src/plone/restapi/deserializer/atcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __call__(self, validate_all=False, data=None, create=False):
mutator(value, **kwargs)
modified = True

if modified:
if create or modified:
errors = self.validate()
if not validate_all:
errors = {f: e for f, e in errors.items() if f in data}
Expand Down
8 changes: 8 additions & 0 deletions src/plone/restapi/tests/test_atcontent_deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ def test_set_layout(self):
self.deserialize(body='{"layout": "my_new_layout"}')
self.assertEqual("my_new_layout", self.doc1.getLayout())

def test_validation_done_when_create(self):
self.doc1.setTitle("")
self.assertEqual(self.deserialize(body='{}'), self.doc1)
with self.assertRaises(BadRequest) as cm:
self.deserialize(body='', create=True, validate_all=True)
self.assertEqual("Title is required, please correct.",
cm.exception.args[0][1]["message"])


class TestValidationRequest(unittest.TestCase):

Expand Down

0 comments on commit d5fc465

Please sign in to comment.