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
This commit is contained in:
Matthew Sital-Singh 2013-11-26 09:59:48 +00:00
parent 37fcb36b8c
commit 749584334f
2 changed files with 34 additions and 0 deletions

View File

@ -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)

View File

@ -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."""