Skip to content

Commit

Permalink
Fix a couple of PloneTestCase tests with DX (see plone/plone.app.test…
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer authored Jul 3, 2018
1 parent f776737 commit 88e56ff
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
7 changes: 4 additions & 3 deletions Products/CMFPlone/tests/testCSRFProtection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from plone.app.testing.bbb import PloneTestCase
from plone.keyring.interfaces import IKeyManager
from plone.protect.authenticator import AuthenticatorView
from six import StringIO
from six import BytesIO
from zope.component import queryUtility


Expand All @@ -20,15 +20,16 @@ def test_KeyManager(self):
def checkAuthenticator(self, path, query='', status=200):
credentials = '%s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD)
path = '/' + self.portal.absolute_url(relative=True) + path
data = StringIO(query)
data = BytesIO(query.encode('utf8'))
# without authenticator...
response = self.publish(path=path, basic=credentials, env={},
request_method='POST', stdin=data)
self.assertEqual(response.getStatus(), 403)
# with authenticator...
tag = AuthenticatorView('context', 'request').authenticator()
token = tag.split('"')[5]
data = StringIO(query + '&_authenticator=%s' % token)
query = query + '&_authenticator=%s' % token
data = BytesIO(query.encode('utf8'))
response = self.publish(path=path, basic=credentials, env={},
request_method='POST', stdin=data)
self.assertEqual(response.getStatus(), status)
Expand Down
11 changes: 7 additions & 4 deletions Products/CMFPlone/tests/testCatalogTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.app.testing import TEST_USER_NAME
from plone.app.textfield import RichTextValue
from plone.indexer.wrapper import IndexableObjectWrapper
from plone.uuid.interfaces import IAttributeUUID
from plone.uuid.interfaces import IUUID
Expand Down Expand Up @@ -334,7 +335,8 @@ def testClearFindAndRebuildAddsMissingContent(self):
def testClearFindAndRebuildKeepsModificationDate(self):
# Index the doc for consistency
self.catalog.indexObject(self.folder.doc)
self.folder.doc.setModificationDate(DateTime(0))
self.folder.doc.modification_date = DateTime(0)
# FIXME: Index the doc for consistency
self.catalog.clearFindAndRebuild()
self.assertEqual(self.folder.doc.modified(), DateTime(0))
self.assertEqual(len(self.catalog(modified=DateTime(0))), 1)
Expand Down Expand Up @@ -1285,7 +1287,8 @@ def test_provided(self):
def test_getObjSize(self):
from Products.CMFPlone.CatalogTool import getObjSize
get_size = getObjSize.callable
self.doc.setText(u'a' * 1000)
# FIXME: getObjSize die not count text in DX
self.doc.text = RichTextValue('a' * 1000)
self.doc.reindexObject()
self.assertEqual(get_size(self.doc), '1 KB')

Expand All @@ -1303,11 +1306,11 @@ class TestMetadata(PloneTestCase):

def testLocationAddedToMetdata(self):
self.folder.invokeFactory(
'Document', 'doc', title='document', location="foobar")
'Document', 'doc', title='document', location='foobar')
doc = self.folder.doc
catalog = self.portal.portal_catalog
brain = catalog(UID=doc.UID())[0]
self.assertEqual(brain.location, doc.getLocation())
self.assertEqual(brain.location, doc.location)


class TestObjectProvidedIndexExtender(unittest.TestCase):
Expand Down
39 changes: 22 additions & 17 deletions Products/CMFPlone/tests/testContentTypeScripts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from plone.app.textfield import RichTextValue
from plone.namedfile.file import NamedFile
from Products.CMFPlone.tests import PloneTestCase
from Products.CMFPlone.tests import dummy

Expand All @@ -17,8 +19,9 @@ def getPermissionsOfRole(self, role):
return [p['name'] for p in perms if p['selected']]

def testDocumentCreate(self):
self.folder.invokeFactory('Document', id='doc', text='data')
self.assertEqual(self.folder.doc.EditableBody(), 'data')
self.folder.invokeFactory(
'Document', id='doc', text=RichTextValue(u'data'))
self.assertEqual(self.folder.doc.text.raw, 'data')
self.assertEqual(self.folder.doc.Format(), 'text/plain')

def testEventCreate(self):
Expand All @@ -27,18 +30,20 @@ def testEventCreate(self):
start_date='2003-09-18',
end_date='2003-09-19')
self.assertEqual(self.folder.event.Title(), 'Foo')
self.assertTrue(self.folder.event.start().ISO8601()
self.assertTrue(self.folder.event.start.ISO8601()
.startswith('2003-09-18T00:00:00'))
self.assertTrue(self.folder.event.end().ISO8601()
self.assertTrue(self.folder.event.end.ISO8601()
.startswith('2003-09-19T00:00:00'))

def testFileCreate(self):
self.folder.invokeFactory('File', id='file', file=dummy.File())
self.assertEqual(str(self.folder.file), dummy.TEXT)
self.folder.invokeFactory(
'File', id='file', file=NamedFile(dummy.File()))
self.assertEqual(self.folder.file.file.data, dummy.TEXT)

def testImageCreate(self):
self.folder.invokeFactory('Image', id='image', file=dummy.Image())
self.assertEqual(str(self.folder.image.data), dummy.GIF)
self.folder.invokeFactory(
'Image', id='image', image=NamedImage(dummy.Image()))
self.assertEqual(self.folder.image.image.data, dummy.GIF)

def testFolderCreate(self):
self.folder.invokeFactory('Folder', id='folder', title='Foo',
Expand All @@ -50,12 +55,12 @@ def testLinkCreate(self):
self.folder.invokeFactory('Link', id='link',
remote_url='http://foo.com', title='Foo')
self.assertEqual(self.folder.link.Title(), 'Foo')
self.assertEqual(self.folder.link.getRemoteUrl(), 'http://foo.com')
self.assertEqual(self.folder.link.remote_url, 'http://foo.com')

def testNewsItemCreate(self):
self.folder.invokeFactory('News Item', id='newsitem',
text='data', title='Foo')
self.assertEqual(self.folder.newsitem.EditableBody(), 'data')
text=RichTextValue(u'data'), title='Foo')
self.assertEqual(self.folder.newsitem.text.raw, 'data')
self.assertEqual(self.folder.newsitem.Title(), 'Foo')

# Bug tests
Expand All @@ -77,41 +82,41 @@ class TestFileURL(PloneTestCase.PloneTestCase):
def testFileURLWithHost(self):
self.folder.invokeFactory('Link', id='link',
remote_url='file://foo.com/baz.txt')
self.assertEqual(self.folder.link.getRemoteUrl(),
self.assertEqual(self.folder.link.remote_url,
'file://foo.com/baz.txt')

def testFileURLNoHost(self):
self.folder.invokeFactory('Link', id='link',
remote_url='file:///foo.txt')
self.assertEqual(self.folder.link.getRemoteUrl(), 'file:///foo.txt')
self.assertEqual(self.folder.link.remote_url, 'file:///foo.txt')

def testFileURLFourSlash(self):
self.folder.invokeFactory('Link', id='link',
remote_url='file:////foo.com/baz.txt')
# See urlparse.urlparse()
self.assertEqual(self.folder.link.getRemoteUrl(),
self.assertEqual(self.folder.link.remote_url,
'file://foo.com/baz.txt')

def testFileURLFiveSlash(self):
self.folder.invokeFactory('Link', id='link',
remote_url='file://///foo.com/baz.txt')
# See urlparse.urlparse()
self.assertEqual(self.folder.link.getRemoteUrl(),
self.assertEqual(self.folder.link.remote_url,
'file:///foo.com/baz.txt')

def testFileURLSixSlash(self):
self.folder.invokeFactory('Link', id='link',
remote_url='file://////foo.com/baz.txt')
# See urlparse.urlparse()
self.assertEqual(self.folder.link.getRemoteUrl(),
self.assertEqual(self.folder.link.remote_url,
'file:////foo.com/baz.txt')


class TestImageProps(PloneTestCase.PloneTestCase):

def testImageComputedProps(self):
from OFS.Image import Image
tag = Image.tag.im_func
tag = Image.tag
kw = {'_title': 'some title',
'_alt': 'alt tag',
'height': 100,
Expand Down
7 changes: 4 additions & 3 deletions Products/CMFPlone/tests/testSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from Products.CMFPlone.interfaces import ISearchSchema

from plone.app.contentlisting.interfaces import IContentListing
from plone.app.textfield import RichTextValue

from zope.configuration import xmlconfig
from zope.interface import alsoProvides
Expand Down Expand Up @@ -58,19 +59,19 @@ def setUpZope(self, app, configurationContext):
import plone.app.contentlisting
xmlconfig.file('configure.zcml',
plone.app.contentlisting, context=configurationContext)
z2.installProduct(app, 'Products.ATContentTypes')

def setUpPloneSite(self, portal):
# Install into Plone site using portal_setup
if 'Document' not in portal.portal_types:
applyProfile(portal, 'Products.ATContentTypes:default')
applyProfile(portal, 'plone.app.contenttypes:default')
setRoles(portal, TEST_USER_ID, ['Manager'])
login(portal, TEST_USER_NAME)
for i in range(0, 12):
portal.invokeFactory(
'Document',
'my-page' + str(i),
text='spam spam ham eggs'
text=RichTextValue(
u'spam spam ham eggs', 'text/html', 'text/x-html-safe'),
)
# Sleep before creating the next one, otherwise ordering by date is
# not deterministic.
Expand Down

0 comments on commit 88e56ff

Please sign in to comment.