Skip to content

Commit

Permalink
Merge pull request #414 from plone/create_at_collection_fix
Browse files Browse the repository at this point in the history
Fix falining AT Collection creation when using api.content.create.
  • Loading branch information
gforcada committed Sep 14, 2018
2 parents 2626aa4 + d491d6a commit 3e38c4f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Bug fixes:
- fix typos in doc strings
[tkimnguyen]

- Fix failing AT Collection creation when using api.content.create.
[gbastien]


1.8.4 (2018-04-24)
------------------
Expand Down
4 changes: 2 additions & 2 deletions src/plone/api/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def create(
# rename-after-creation and such
# 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})
# '': '' is required so that bool(values) is True.
content.processForm(values={'': ''})

if not id or (safe_id and id):
# Create a new id from title
Expand Down
57 changes: 57 additions & 0 deletions src/plone/api/tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,63 @@ def test_create_at_with_title_in_request(self):

self.assertEqual(page.title, 'Test document')

def test_create_collection(self):
"""Test create a Collection."""
collection = api.content.create(
container=self.portal,
type='Collection',
title='Mandelbrot set',
description='Image gallery of a zoom sequence',
query=[
{
'i': 'Type',
'o': 'plone.app.querystring.operation.string.is',
'v': ['Image'],
},
],
)
self.assertEqual(collection.Title(), 'Mandelbrot set')

@unittest.skipIf(HAS_PACONTENTYPES, 'Archetypes only')
def test_create_at_event(self):
"""https://github.com/plone/plone.api/issues/364"""
from DateTime import DateTime
today = DateTime()
tomorrow = today + 1
event = api.content.create(
container=self.portal,
type='Event',
title=u'My event',
startDate=today,
endDate=tomorrow,
)
self.assertEqual(event.startDate, today)
self.assertEqual(event.endDate, tomorrow)
results = api.content.find(Title=u'My event')
self.assertEqual(len(results), 1)
self.assertEqual(results[0].start, today)
self.assertEqual(results[0].end, tomorrow)

@unittest.skipUnless(HAS_PACONTENTYPES, 'Dexterity only')
def test_create_dx_event(self):
"""Test create a DX event."""
import datetime
today = datetime.datetime.now()
tomorrow = today + datetime.timedelta(days=1)
event = api.content.create(
container=self.portal,
type='Event',
title=u'My event',
start=today,
end=tomorrow,
)
self.assertEqual(event.start, today)
self.assertEqual(event.end, tomorrow)
results = api.content.find(Title=u'My event')
self.assertEqual(len(results), 1)
self.assertEqual(results[0].start, today)
self.assertEqual(results[0].end, tomorrow)

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

Expand Down

0 comments on commit 3e38c4f

Please sign in to comment.