Skip to content

Commit

Permalink
[refs plone#99] Adding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-batranu committed Mar 12, 2018
1 parent 57476b1 commit dbaf047
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/plone/api/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ def create(
if IBaseObject.providedBy(content):
# Will finish Archetypes content item creation process,
# rename-after-creation and such
# Passing values as an empty dict so values set by invokeFactory
# don't get overridden.
# Passing values as a dict with None values so values set by
# invokeFactory don't get overridden.
# None: None is required so that bool(values) is True.
content.processForm(values={None: None})

if not id or (safe_id and id):
Expand Down
37 changes: 37 additions & 0 deletions src/plone/api/tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,43 @@ def unregister_indexer():
# check that the exception is the one we raised
self.assertEqual(ude.exception.reason, unicode_exception_message)

def test_create_at_with_title_in_request(self):
""" Test that content gets created with the correct title, even if
request.form['title'] already exists and has a different value.
This can occur, for example, when adding a Plone with an enabled
product that creates a site structure. In that case, the 'title'
would be that of the portal.
Only AT content types are affected, due to content.processForm.
"""
leaked_title = 'This should not be set on content items'
self.layer['request'].form['title'] = leaked_title

container = self.portal

# Create a folder
folder = api.content.create(
container=container,
type='Folder',
id='test-folder',
title='Test folder'
)
assert folder
self.assertEqual(folder.id, 'test-folder')
self.assertEqual(folder.title, 'Test folder')
self.assertEqual(folder.portal_type, 'Folder')

# Create a document
page = api.content.create(
container=folder,
type='Document',
id='test-document',
title='Test document',
)
assert page
self.assertEqual(page.id, 'test-document')
self.assertEqual(page.title, 'Test document')
self.assertEqual(page.portal_type, 'Document')

def test_get_constraints(self):
"""Test the constraints when content is fetched with get."""

Expand Down

0 comments on commit dbaf047

Please sign in to comment.