Skip to content

Commit

Permalink
Run main tests against plone.app.contenttypes; skip AT tests if no AT…
Browse files Browse the repository at this point in the history
…ContentTypes
  • Loading branch information
davisagli committed May 8, 2018
1 parent 8e993ae commit e166c40
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 200 deletions.
7 changes: 7 additions & 0 deletions plone/app/iterate/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ def setUpPloneSite(self, portal):
super(DexPloneAppIterateLayer, self).setUpPloneSite(portal)
applyProfile(portal, 'plone.app.iterate:default')

# Disable automatic versioning of core content types
for name in ('Document', 'Event', 'Link', 'News Item'):
fti = portal.portal_types[name]
behaviors = list(fti.behaviors)
behaviors.remove('plone.app.versioningbehavior.behaviors.IVersionable')
fti.behaviors = tuple(behaviors)


PLONEAPPITERATEDEX_FIXTURE = DexPloneAppIterateLayer()
PLONEAPPITERATEDEX_INTEGRATION_TESTING = IntegrationTesting(
Expand Down
25 changes: 16 additions & 9 deletions plone/app/iterate/tests/test_doctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
from plone.app.iterate.testing import PLONEAPPITERATEDEX_FUNCTIONAL_TESTING
from plone.testing import layered
from unittest import TestSuite

import doctest

try:
import Products.ATContentTypes
except ImportError:
HAS_AT = False
else:
HAS_AT = True


def test_suite():
suite = TestSuite()
OPTIONFLAGS = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
suite.addTest(layered(
doctest.DocFileSuite(
'browser.rst',
optionflags=OPTIONFLAGS,
package='plone.app.iterate.tests',
),
layer=PLONEAPPITERATE_FUNCTIONAL_TESTING)
)
if HAS_AT:
suite.addTest(layered(
doctest.DocFileSuite(
'browser.rst',
optionflags=OPTIONFLAGS,
package='plone.app.iterate.tests',
),
layer=PLONEAPPITERATE_FUNCTIONAL_TESTING)
)
suite.addTest(layered(
doctest.DocFileSuite(
'dexterity.rst',
Expand Down
140 changes: 5 additions & 135 deletions plone/app/iterate/tests/test_iterate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
# along with iterate; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##################################################################
"""
"""

from AccessControl import getSecurityManager
from plone.app.iterate.browser.control import Control
from plone.app.iterate.interfaces import ICheckinCheckoutPolicy
from plone.app.iterate.testing import PLONEAPPITERATE_INTEGRATION_TESTING
from plone.app.iterate.testing import PLONEAPPITERATEDEX_INTEGRATION_TESTING
from plone.app.testing import login
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
Expand All @@ -38,7 +36,7 @@

class TestIterations(unittest.TestCase):

layer = PLONEAPPITERATE_INTEGRATION_TESTING
layer = PLONEAPPITERATEDEX_INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
Expand All @@ -58,14 +56,7 @@ def setUp(self):

self.repo = self.portal.portal_repository

def shim_test(self, test_method):

try:
test_method()
except Exception:
import traceback
traceback.print_exc()

@unittest.skip('This test needs to be fixed for Dexterity content.')
def test_workflowState(self):
# ensure baseline workflow state is retained on checkin, including
# security
Expand Down Expand Up @@ -114,102 +105,6 @@ def test_baselineVersionCreated(self):
history = self.repo.getHistory(doc2)
self.assertEqual(len(history), 1)

def test_wcNewForwardReferencesCopied(self):
# ensure that new wc references are copied back to the baseline on
# checkin
doc = self.portal.docs.doc1
doc.addReference(self.portal.docs)
self.assertEqual(len(doc.getReferences('zebra')), 0)
wc = ICheckinCheckoutPolicy(doc).checkout(self.portal.workarea)
wc.addReference(self.portal.docs.doc2, 'zebra')
doc = ICheckinCheckoutPolicy(wc).checkin('updated')
self.assertEqual(len(doc.getReferences('zebra')), 1)

def test_wcNewBackwardReferencesCopied(self):
# ensure that new wc back references are copied back to the baseline on
# checkin

doc = self.portal.docs.doc1
self.assertEqual(len(doc.getBackReferences('zebra')), 0)
wc = ICheckinCheckoutPolicy(doc).checkout(self.portal.workarea)
self.portal.docs.doc2.addReference(wc, 'zebra')
self.assertEqual(len(wc.getBackReferences('zebra')), 1)
doc = ICheckinCheckoutPolicy(wc).checkin('updated')
self.assertEqual(len(doc.getBackReferences('zebra')), 1)

def test_baselineReferencesMaintained(self):
# ensure that baseline references are maintained when the object is
# checked in copies forward, bkw are not copied, but are maintained.

doc = self.portal.docs.doc1
doc.addReference(self.portal.docs, 'elephant')
self.portal.docs.doc2.addReference(doc)

wc = ICheckinCheckoutPolicy(doc).checkout(self.portal.workarea)

doc = ICheckinCheckoutPolicy(wc).checkin('updated')

# TODO: This fails in Plone 4.1. The new optimized catalog lookups
# in the reference catalog no longer filter out non-existing reference
# objects. In both Plone 4.0 and 4.1 there's two references, one of
# them is a stale catalog entry in the reference catalog. The real fix
# is to figure out how the stale catalog entry gets in there
self.assertEqual(len(doc.getReferences()), 1)
self.assertEqual(len(doc.getBackReferences()), 1)

def test_baselineBrokenReferencesRemoved(self):
# When the baseline has a reference to a deleted object, a
# checkout should not fail with a ReferenceException.

doc = self.portal.docs.doc1
doc.addReference(self.portal.docs.doc2, 'pony')
self.portal.docs._delOb('doc2')
# _delOb is low level enough that the reference does not get cleaned
# up.
self.assertEqual(len(doc.getReferences()), 1)

wc = ICheckinCheckoutPolicy(doc).checkout(self.portal.workarea)
# The working copy has one reference: its original.
self.assertEqual(len(wc.getReferences()), 1)
self.assertEqual(wc.getReferences()[0].id, 'doc1')

doc = ICheckinCheckoutPolicy(wc).checkin('updated')
# The checkin removes the broken reference.
self.assertEqual(len(doc.getReferences()), 0)

def test_baselineNoCopyReferences(self):
# ensure that custom state is maintained with the no copy adapter

# setup the named ref adapter
from zope import component
from Products.Archetypes.interfaces import IBaseObject
from plone.app.iterate import relation, interfaces
from plone.app.iterate.tests.utils import CustomReference

component.provideAdapter(
adapts=(IBaseObject,),
provides=interfaces.ICheckinCheckoutReference,
factory=relation.NoCopyReferenceAdapter,
name='zebra')

doc = self.portal.docs.doc1
ref = doc.addReference(
self.portal.docs, 'zebra', referenceClass=CustomReference)
ref.custom_state = 'hello world'

wc = ICheckinCheckoutPolicy(doc).checkout(self.portal.workarea)

self.assertEqual(len(wc.getReferences('zebra')), 0)

doc = ICheckinCheckoutPolicy(wc).checkin('updated')

self.assertEqual(len(doc.getReferences('zebra')), 1)

ref = doc.getReferenceImpl('zebra')[0]

self.assertTrue(hasattr(ref, 'custom_state'))
self.assertEqual(ref.custom_state, 'hello world')

def test_folderOrder(self):
"""When an item is checked out and then back in, the original
folder order is preserved."""
Expand All @@ -224,7 +119,7 @@ def test_folderOrder(self):

self.repo.save(doc)
wc = ICheckinCheckoutPolicy(doc).checkout(container)
wc.update(text='new document text')
wc.text = 'new document text'

# check that the copy is put after the second document
copy_position = container.getObjectPosition(wc.getId())
Expand All @@ -234,6 +129,7 @@ def test_folderOrder(self):
new_position = container.getObjectPosition(new_doc.getId())
self.assertEqual(new_position, original_position)

@unittest.skip('This test needs to be fixed for Dexterity content.')
def test_folderContents(self):
"""When an folder is checked out, and item is added, and then
the folder is checked back in, the added item is in the new
Expand Down Expand Up @@ -267,32 +163,6 @@ def test_folderContents(self):
self.assertTrue('new folder item text' in
new_folder['new-folder-item'].getText())

def test_checkinObjectLinkedInParentsRichTextField(self):
"""Checnking-in an object that is linked in it's
parent's rich text field. See: https://dev.plone.org/ticket/13462
"""
# create a folderish object with a rich text field
from content import addRichFolder
addRichFolder(self.portal, 'rich_text_folder')
rich_text_folder = self.portal.rich_text_folder

# create the subobject
rich_text_folder.invokeFactory('Document', 'subobject')
subobject = rich_text_folder.subobject
subobject_uid = subobject.UID()

# link (by uid) the subobject in it's parent's rich text field
link_html = '<a class="internal-link" href="resolveuid/{0}">' \
'Link to subobject</a>'
rich_text_folder.setText(link_html.format(subobject_uid))

# try to checkout and checkin the subobject
wc = ICheckinCheckoutPolicy(subobject).checkout(rich_text_folder)
ICheckinCheckoutPolicy(wc).checkin('updated')

# everything went right and the working copy is checked in
self.assertEqual(subobject_uid, wc.UID())

def test_default_page_is_kept_in_folder(self):
# Ensure that a default page that is checked out and back in is still
# the default page.
Expand Down

1 comment on commit e166c40

@jenkins-plone-org
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davisagli Jenkins CI reporting about code analysis
See the full report here: https://jenkins.plone.org/job/package-plone.app.iterate/62/violations

plone/app/iterate/policy.py:57:45: C812 missing trailing comma
plone/app/iterate/policy.py:66:11: T000 Todo note found.
plone/app/iterate/base.py:160:22: W292 no newline at end of file
plone/app/iterate/testing.py:147:80: E501 line too long (83 > 79 characters)
plone/app/iterate/interfaces.py:321:23: C812 missing trailing comma
plone/app/iterate/interfaces.py:328:22: C812 missing trailing comma
plone/app/iterate/__init__.py:48:78: C812 missing trailing comma
plone/app/iterate/setuphandlers.py:11:27: C812 missing trailing comma
plone/app/iterate/containers.py:72:50: C812 missing trailing comma
plone/app/iterate/containers.py:73:14: C812 missing trailing comma
plone/app/iterate/browser/checkout.py:70:33: C812 missing trailing comma
plone/app/iterate/dexterity/copier.py:5:1: I001 isort found an import in the wrong position
plone/app/iterate/dexterity/copier.py:67:19: T000 Todo note found.
plone/app/iterate/dexterity/copier.py:157:50: C812 missing trailing comma
plone/app/iterate/dexterity/utils.py:25:18: C812 missing trailing comma
plone/app/iterate/tests/test_iterate.py:171:80: E501 line too long (97 > 79 characters)
plone/app/iterate/tests/test_iterate_at.py:35:1: I003 isort expected 1 blank line in imports, found 0
plone/app/iterate/tests/test_iterate_at.py:42:5: E301 expected 1 blank line, found 0
plone/app/iterate/tests/test_iterate_at.py:52:80: E501 line too long (85 > 79 characters)
plone/app/iterate/tests/test_iterate_at.py:154:11: T000 Todo note found.
plone/app/iterate/tests/test_iterate_at.py:302:80: E501 line too long (97 > 79 characters)
plone/app/iterate/tests/test_doctests.py:6:1: I003 isort expected 1 blank line in imports, found 0
plone/app/iterate/tests/test_doctests.py:7:1: I003 isort expected 1 blank line in imports, found 0
plone/app/iterate/tests/test_doctests.py:9:5: F401 'Products.ATContentTypes' imported but unused
plone/app/iterate/tests/test_doctests.py:26:54: C812 missing trailing comma
plone/app/iterate/tests/test_doctests.py:34:53: C812 missing trailing comma

Follow these instructions to reproduce it locally.

Please sign in to comment.