Skip to content

Commit

Permalink
Move test_collection tests to p.a.testing. The existing tests are wri…
Browse files Browse the repository at this point in the history
…tten in a really bad way and now they look even more ugly. Though, it is not really worth the effort to write them from the scratch since we already did this for p.a.collection 2.x and p.a.contenttypes.
  • Loading branch information
Timo Stollenwerk committed Mar 24, 2014
1 parent 4a2d287 commit c44bbab
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 107 deletions.
17 changes: 14 additions & 3 deletions plone/app/collection/testing.py
Expand Up @@ -5,6 +5,7 @@
from plone.testing import z2

from plone.app.testing import TEST_USER_ID
from plone.app.testing import TEST_USER_NAME
from plone.app.testing import setRoles
from plone.app.testing import login
from plone.app.testing import PloneSandboxLayer
Expand All @@ -16,27 +17,37 @@
class PloneAppCollectionLayer(PloneSandboxLayer):

def setUpZope(self, app, configurationContext):
import Products.ATContentTypes
self.loadZCML(package=Products.ATContentTypes)
z2.installProduct(app, 'Products.Archetypes')
z2.installProduct(app, 'Products.ATContentTypes')
z2.installProduct(app, 'plone.app.blob')
z2.installProduct(app, 'plone.app.collection')
import plone.app.collection
xmlconfig.file(
'configure.zcml',
plone.app.collection,
context=configurationContext)

def setUpPloneSite(self, portal):
applyProfile(portal, 'Products.ATContentTypes:default')
applyProfile(portal, 'plone.app.collection:default')
setRoles(portal, TEST_USER_ID, ['Manager'])
login(portal, TEST_USER_NAME)
portal.acl_users.userFolderAddUser('admin',
'secret',
['Manager'],
[])
login(portal, 'admin')
portal.portal_workflow.setDefaultChain("simple_publication_workflow")
setRoles(portal, TEST_USER_ID, ['Manager'])
portal.invokeFactory(
"Folder",
id="test-folder",
title=u"Test Folder"
)

def tearDownZope(self, app):
z2.uninstallProduct(app, 'plone.app.blob')
z2.uninstallProduct(app, 'Products.ATContentTypes')
z2.uninstallProduct(app, 'Products.Archetypes')

PLONEAPPCOLLECTION_FIXTURE = PloneAppCollectionLayer()

Expand Down
161 changes: 57 additions & 104 deletions plone/app/collection/tests/test_collection.py
@@ -1,6 +1,9 @@
from plone.app.portlets.storage import PortletAssignmentMapping
from plone.app.testing import login
from plone.app.testing import logout
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.app.testing import TEST_USER_NAME
from plone.portlets.interfaces import IPortletAssignment
from plone.portlets.interfaces import IPortletDataProvider
from plone.portlets.interfaces import IPortletManager
Expand All @@ -14,8 +17,9 @@
from plone.app.collection.portlets import collectionportlet
from .base import CollectionTestCase, CollectionPortletTestCase
from .base import PACOLLECTION_FUNCTIONAL_TESTING

from plone.app.collection.testing import PLONEAPPCOLLECTION_INTEGRATION_TESTING
import time
import unittest2 as unittest

# default test query
query = [{
Expand All @@ -33,113 +37,88 @@ def getData(filename):
return data


class TestCollection(CollectionTestCase):
class TestCollection(unittest.TestCase):

layer = PLONEAPPCOLLECTION_INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
login(self.portal, TEST_USER_NAME)
try:
self.portal.invokeFactory('Collection', 'col')
except:
pass
self.collection = self.portal['col']

def test_addCollection(self):
portal = self.layer['portal']
login(portal, 'admin')
portal.invokeFactory("Collection",
"collection",
title="New Collection")
collection = portal['collection']
self.assertEqual(collection.Title(), "New Collection")
self.portal.invokeFactory("Collection",
"col1",
title="New Collection")
self.assertEqual(self.portal.col1.Title(), "New Collection")

def test_searchResults(self):
portal = self.layer['portal']
login(portal, 'admin')
# add a collection, so we can add a query to it
portal.invokeFactory("Collection",
"collection",
title="New Collection")
collection = portal['collection']
collection.setQuery(query)
self.assertEqual(collection.getQuery()[0].Title(),
"Collection Test Page")
self.portal.invokeFactory('Document', 'doc1', title='Collection Test Page')
self.collection.setQuery(query)
self.assertEqual(
self.collection.getQuery()[0].Title(),
"Collection Test Page")

def test_listMetaDataFields(self):
portal = self.layer['portal']
login(portal, 'admin')
# add a collection, so we can add a query to it
portal.invokeFactory("Collection",
"collection",
title="New Collection")
collection = portal['collection']
metadatafields = collection.listMetaDataFields()
metadatafields = self.collection.listMetaDataFields()
self.assertTrue(len(metadatafields) > 0)

def test_viewingCollection(self):
portal = self.layer['portal']
login(portal, 'admin')
# add a collection, so we can add a query to it
portal.invokeFactory("Collection",
"collection",
title="New Collection")
collection = portal['collection']
self.portal.invokeFactory('Document', 'doc1', title='Collection Test Page')
# set the query and publish the collection
collection.setQuery(query)
workflow = portal.portal_workflow
workflow.doActionFor(collection, "publish")
self.collection.setQuery(query)
commit()
logout()
# open a browser to see if our page is in the results
browser = Browser(self.layer['app'])
browser.open(collection.absolute_url())
browser.open(self.collection.absolute_url())
self.assertTrue("Collection Test Page" in browser.contents)

def test_collection_templates(self):
portal = self.layer['portal']
login(portal, 'admin')
data = getData('image.png')
# add an image that will be listed by the collection
portal.invokeFactory("Image",
self.portal.invokeFactory("Image",
"image",
title="Image example",
image=data)
# add a collection, so we can add a query to it
portal.invokeFactory("Collection",
"collection",
title="New Collection")
collection = portal['collection']
# Search for images
query = [{
'i': 'Type',
'o': 'plone.app.querystring.operation.string.is',
'v': 'Image',
}]
# set the query and publish the collection
collection.setQuery(query)
workflow = portal.portal_workflow
workflow.doActionFor(collection, "publish")
self.collection.setQuery(query)
commit()
logout()
# open a browser to see if our image is in the results
browser = Browser(self.layer['app'])
browser.handleErrors = False
browser.open(collection.absolute_url())
browser.open(self.collection.absolute_url())
self.assertTrue("Image example" in browser.contents)
# open summary_view template
browser.open('%s/summary_view' % collection.absolute_url())
browser.open('%s/summary_view' % self.collection.absolute_url())
self.assertTrue("Image example" in browser.contents)
# open folder_summary_view template
browser.open('%s/folder_summary_view' % collection.absolute_url())
browser.open('%s/folder_summary_view' % self.collection.absolute_url())
self.assertTrue("Image example" in browser.contents)
# open thumbnail_view template
browser.open('%s/thumbnail_view' % collection.absolute_url())
browser.open('%s/thumbnail_view' % self.collection.absolute_url())
self.assertTrue("Image example" in browser.contents)

def test_getFoldersAndImages(self):
portal = self.layer['portal']
login(portal, 'admin')
# add a collection, so we can add a query to it
portal.invokeFactory("Collection",
"collection",
title="New Collection")
collection = self.collection

# add example folder and a subfolder to it, both with same id
portal.invokeFactory("Folder",
self.portal.invokeFactory("Folder",
"folder1",
title="Folder1")
folder = portal['folder1']
folder = self.portal['folder1']

folder.invokeFactory("Folder",
"folder1",
Expand All @@ -158,61 +137,49 @@ def test_getFoldersAndImages(self):
'o': 'plone.app.querystring.operation.string.is',
'v': 'Folder',
}]
collection = portal['collection']
collection.setQuery(query)
imagecount = collection.getFoldersAndImages()['total_number_of_images']
# The current implementation for getFoldersAndImages will return
# another_image under subfolder and also under folder
self.assertTrue(imagecount == 3)

def test_getFoldersAndImages_returning_images(self):
portal = self.layer['portal']
login(portal, 'admin')
# add a collection, so we can add a query to it
portal.invokeFactory("Collection",
"collection",
title="New Collection")

collection = self.collection
# add example folder
portal.invokeFactory("Folder",
self.portal.invokeFactory("Folder",
"folder1",
title="Folder1")
folder = portal['folder1']
folder = self.portal['folder1']

# add example image into this folder
folder.invokeFactory("Image",
"image",
title="Image example")

# add another image into the portal root
portal.invokeFactory("Image",
"image",
# add another image into the self.portal root
self.portal.invokeFactory("Image",
"image1",
title="Image example")
query = [{
'i': 'Type',
'o': 'plone.app.querystring.operation.string.is',
'v': 'Image',
}]
collection = portal['collection']
collection.setQuery(query)
imagecount = collection.getFoldersAndImages()['total_number_of_images']
self.assertTrue(imagecount == 2)
self.assertEqual(imagecount, 3)

def test_limit(self):
portal = self.layer['portal']
login(portal, 'admin')
# add a collection, so we can add a query to it
portal.invokeFactory("Collection",
"collection",
title="New Collection")
collection = portal['collection']
collection = self.collection

# add two folders as example content
portal.invokeFactory("Folder",
"folder1",
title="Folder1")
self.portal.invokeFactory(
"Folder",
"folder1",
title="Folder1"
)

portal.invokeFactory("Folder",
self.portal.invokeFactory("Folder",
"folder2",
title="Folder2")
query = [{
Expand All @@ -228,23 +195,9 @@ def test_limit(self):
self.assertTrue(len(results) == 1)

def test_selectedViewFields(self):
portal = self.layer['portal']
login(portal, 'admin')
# add a collection, so we can add a query to it
portal.invokeFactory("Collection",
"collection",
title="New Collection")
collection = portal['collection']
# check if there are selectedViewFields
self.assertTrue(len(collection.selectedViewFields()) > 0)
self.assertTrue(len(self.collection.selectedViewFields()) > 0)

def test_syndication_enabled_by_default(self):
portal = self.layer['portal']
login(portal, 'admin')
# add a collection, so we can add a query to it
portal.invokeFactory("Collection",
"collection",
title="New Collection")
collection = portal['collection']
syn = getToolByName(portal, 'portal_syndication')
self.assertTrue(syn.isSyndicationAllowed(collection))
syn = getToolByName(self.portal, 'portal_syndication')
self.assertTrue(syn.isSyndicationAllowed(self.collection))

0 comments on commit c44bbab

Please sign in to comment.