summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Sital-Singh <mattss@netsight.co.uk>2013-11-26 09:59:48 (GMT)
committerMatthew Sital-Singh <mattss@netsight.co.uk>2013-11-26 09:59:48 (GMT)
commit749584334feea33ab592b3b8ba256c0913439e7e (patch)
tree0f5fc0ce56cba3c959baec91f13abd70d32aee34
parent37fcb36b8c10bce3a45b944b001ec0c4552d753b (diff)
downloadplone.api-749584334feea33ab592b3b8ba256c0913439e7e.zip
plone.api-749584334feea33ab592b3b8ba256c0913439e7e.tar.gz
plone.api-749584334feea33ab592b3b8ba256c0913439e7e.tar.bz2
Add test to ensure UnicodeDecodeErrors not swallowed
This test registers a title indexer that forces a UnicodeException during the creation of an content item, and checks that it is not swallowed by api.content.create
-rw-r--r--CHANGES.rst2
-rw-r--r--src/plone/api/tests/test_content.py32
2 files changed, 34 insertions, 0 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 40e6414..b5293be 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -6,6 +6,8 @@ Changelog
- Add ``api.env.plone_version()`` and ``api.env.zope_version()`` refs. #126.
[hvelarde]
+- Stop UnicodeDecodeErrors being swallowed in ``api.content.create``
+ [mattss]
1.1.0 (2013-10-12)
diff --git a/src/plone/api/tests/test_content.py b/src/plone/api/tests/test_content.py
index 3fa8279..712c1cd 100644
--- a/src/plone/api/tests/test_content.py
+++ b/src/plone/api/tests/test_content.py
@@ -3,12 +3,16 @@
from Acquisition import aq_base
from OFS.CopySupport import CopyError
+from Products.CMFCore.interfaces import IContentish
+from Products.ZCatalog.interfaces import IZCatalog
from plone import api
from plone.api.tests.base import INTEGRATION_TESTING
+from plone.indexer import indexer
from plone.uuid.interfaces import IMutableUUID
from plone.uuid.interfaces import IUUIDGenerator
from zExceptions import BadRequest
from zope.component import getUtility
+from zope.component import getGlobalSiteManager
import mock
import pkg_resources
@@ -233,6 +237,34 @@ class TestPloneApiContent(unittest.TestCase):
self.assertEqual(second_page.id, 'test-document-1')
self.assertEqual(second_page.portal_type, 'Document')
+ def test_create_raises_unicodedecodeerror(self):
+ """Test that the create method raises UnicodeDecodeErrors correctly."""
+ site = getGlobalSiteManager()
+ unicode_exception_message = "This is a fake unicode error"
+
+ # register a title indexer that will force a UnicodeDecodeError
+ # during content reindexing
+ @indexer(IContentish, IZCatalog)
+ def force_unicode_error(object):
+ raise UnicodeDecodeError('ascii', 'x', 1, 5,
+ unicode_exception_message)
+
+ site.registerAdapter(factory=force_unicode_error, name='Title')
+
+ def unregister_indexer():
+ site.unregisterAdapter(factory=force_unicode_error, name='Title')
+
+ self.addCleanup(unregister_indexer)
+
+ with self.assertRaises(UnicodeDecodeError) as ude:
+ api.content.create(
+ type='Folder', id='test-unicode-folder',
+ container=self.portal,
+ )
+
+ # check that the exception is the one we raised
+ self.assertEqual(ude.exception.reason, unicode_exception_message)
+
def test_get_constraints(self):
"""Test the constraints when content is fetched with get."""