Skip to content

Commit

Permalink
reduce deprecated imports
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Jun 26, 2018
1 parent e0f0284 commit 7d5eb0f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 53 deletions.
20 changes: 10 additions & 10 deletions src/plone/app/testing/bbb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from AccessControl import getSecurityManager
from plone.app import testing
from plone.testing import z2
from plone.testing import zope
from Products.CMFPlone.utils import _createObjectByType
from Testing.ZopeTestCase.functional import Functional

Expand Down Expand Up @@ -31,10 +31,10 @@ 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')
zope.installProduct(app, 'Products.Archetypes')
zope.installProduct(app, 'Products.ATContentTypes')
zope.installProduct(app, 'plone.app.blob')
zope.installProduct(app, 'plone.app.collection')

def setUpPloneSite(self, portal):
# restore default workflow
Expand All @@ -47,10 +47,10 @@ def setUpPloneSite(self, portal):
_createMemberarea(portal, testing.TEST_USER_ID)

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


PTC_FIXTURE = PloneTestCaseFixture()
Expand Down Expand Up @@ -114,7 +114,7 @@ def login(self, userName=testing.TEST_USER_NAME):

def loginAsPortalOwner(self, userName=testing.SITE_OWNER_NAME):
"""Log in to the portal as the user who created it."""
z2.login(self.app['acl_users'], userName)
zope.login(self.app['acl_users'], userName)

def logout(self):
"""Log out, i.e. become anonymous."""
Expand Down
24 changes: 12 additions & 12 deletions src/plone/app/testing/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from plone.app.testing.interfaces import TEST_USER_NAME
from plone.testing import Layer
from plone.testing import security
from plone.testing import z2
from plone.testing import zca
from plone.testing import zodb
from plone.testing import zope
from zope.component import getGlobalSiteManager
from zope.component.hooks import getSite
from zope.component.hooks import setHooks
Expand All @@ -27,22 +27,22 @@ def login(portal, userName):
"""Log in as the given user in the given Plone site
"""

z2.login(portal['acl_users'], userName)
zope.login(portal['acl_users'], userName)


def logout():
"""Log out, i.e. become anonymous
"""

z2.logout()
zope.logout()


def setRoles(portal, userId, roles):
"""Set the given user's roles to a tuple of roles.
"""

userFolder = portal['acl_users']
z2.setRoles(userFolder, userId, roles)
zope.setRoles(userFolder, userId, roles)


def tearDownMultiPluginRegistration(pluginName):
Expand Down Expand Up @@ -81,7 +81,7 @@ def quickInstallProduct(portal, productName, reinstall=False):
sm = getSecurityManager()
app = aq_parent(portal)

z2.login(app['acl_users'], SITE_OWNER_NAME)
zope.login(app['acl_users'], SITE_OWNER_NAME)

try:
from Products.CMFPlone.utils import get_installer
Expand Down Expand Up @@ -127,7 +127,7 @@ def applyProfile(portal, profileName, purge_old=None,
sm = getSecurityManager()
app = aq_parent(portal)

z2.login(app['acl_users'], SITE_OWNER_NAME)
zope.login(app['acl_users'], SITE_OWNER_NAME)

try:
setupTool = portal['portal_setup']
Expand Down Expand Up @@ -234,13 +234,13 @@ def persist_profile_upgrade_versions(portal):


@contextlib.contextmanager
def ploneSite(db=None, connection=None, environ=None, flavour=z2):
def ploneSite(db=None, connection=None, environ=None, flavour=zope):
"""Context manager for working with the Plone portal during layer setup::
with ploneSite() as portal:
...
This is based on the ``z2.zopeApp()`` context manager. See the module
This is based on the ``zope.zopeApp()`` context manager. See the module
``plone.testing.z2`` for details.
Do not use this in a test. Use the 'portal' resource from the PloneFixture
Expand Down Expand Up @@ -296,7 +296,7 @@ def setUpZope(self, app, configurationContext):
``configurationContext`` is the ZCML configuration context.
This is the most appropriate place to load ZCML or install Zope 2-
style products, using the ``plone.testing.z2.installProduct`` helper.
style products, using the ``plone.testing.zope.installProduct`` helper.
"""
pass

Expand All @@ -306,7 +306,7 @@ def tearDownZope(self, app):
``app`` is the Zope application root.
This is the most appropriate place to uninstall Zope 2-style products
using the ``plone.testing.z2.uninstallProduct`` helper.
using the ``plone.testing.zope.uninstallProduct`` helper.
"""
pass

Expand Down Expand Up @@ -388,7 +388,7 @@ def setUp(self):

def tearDown(self):

with z2.zopeApp() as app:
with zope.zopeApp() as app:

portal = app[PLONE_SITE_ID]
setHooks()
Expand Down Expand Up @@ -476,7 +476,7 @@ def setUpZope(self, app, configurationContext):
"""
self.setUpZCMLFiles()
for z2Product in self.additional_z2_products:
z2.installProduct(app, z2Product)
zope.installProduct(app, z2Product)

def setUpZCMLFiles(self):
"""Load default ZCML.
Expand Down
8 changes: 4 additions & 4 deletions src/plone/app/testing/helpers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ need to tear that down as well.
... return qi.is_product_installed(product_name)

>>> from plone.testing import Layer
>>> from plone.testing import zca, z2, zodb
>>> from plone.testing import zca, zope, zodb

>>> from plone.app.testing import PLONE_FIXTURE
>>> from plone.app.testing import IntegrationTesting
Expand Down Expand Up @@ -168,7 +168,7 @@ and the results of the profile having been applied.
Let's now simulate a test.

>>> zca.LAYER_CLEANUP.testSetUp()
>>> z2.STARTUP.testSetUp()
>>> zope.STARTUP.testSetUp()
>>> PLONE_FIXTURE.testSetUp()
>>> HELPER_DEMOS_FIXTURE.testSetUp()
>>> HELPER_DEMOS_INTEGRATION_TESTING.testSetUp()
Expand Down Expand Up @@ -214,7 +214,7 @@ Let's now tear down the test.
>>> HELPER_DEMOS_INTEGRATION_TESTING.testTearDown()
>>> HELPER_DEMOS_FIXTURE.testTearDown()
>>> PLONE_FIXTURE.testTearDown()
>>> z2.STARTUP.testTearDown()
>>> zope.STARTUP.testTearDown()
>>> zca.LAYER_CLEANUP.testTearDown()

Our persistent changes from the layer should remain, but those made in a test
Expand Down Expand Up @@ -299,7 +299,7 @@ layer base class which helps implement this pattern.
... PluggableAuthService.registerMultiPlugin("dummy_plugin1")
...
... # Finally, this is a good place to load Zope products,
... # using the plone.testing.z2.installProduct() helper.
... # using the plone.testing.zope.installProduct() helper.
... # Make some other global changes not stored in the ZODB or
... # the global component registry
... someGlobal['test'] = 1
Expand Down
25 changes: 12 additions & 13 deletions src/plone/app/testing/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from plone.app.testing.interfaces import TEST_USER_ROLES
from plone.app.testing.utils import MockMailHost
from plone.testing import Layer
from plone.testing import z2
from plone.testing import zca
from plone.testing import zodb
from plone.testing import zope
Expand All @@ -36,7 +35,7 @@ class PloneFixture(Layer):
role, ``Member``.
"""

defaultBases = (z2.STARTUP,)
defaultBases = (zope.STARTUP,)

# Products that will be installed, plus options
products = (
Expand Down Expand Up @@ -90,7 +89,7 @@ class PloneFixture(Layer):

def setUp(self):

# Stack a new DemoStorage on top of the one from z2.STARTUP.
# Stack a new DemoStorage on top of the one from zope.STARTUP.
self['zodbDB'] = zodb.stackDemoStorage(
self.get('zodbDB'),
name='PloneFixture'
Expand All @@ -99,14 +98,14 @@ def setUp(self):
self.setUpZCML()

# Set up products and the default content
with z2.zopeApp() as app:
with zope.zopeApp() as app:
self.setUpProducts(app)
self.setUpDefaultContent(app)

def tearDown(self):

# Tear down products
with z2.zopeApp() as app:
with zope.zopeApp() as app:
# note: content tear-down happens by squashing the ZODB
self.tearDownProducts(app)

Expand Down Expand Up @@ -179,15 +178,15 @@ def setUpProducts(self, app):

for p, config in self.products:
if config.get('install', True):
z2.installProduct(app, p)
zope.installProduct(app, p)

def tearDownProducts(self, app):
"""Uninstall all old-style products listed in the the ``products``
tuple of this class.
"""
for p, config in reversed(self.products):
if config.get('install', True):
z2.uninstallProduct(app, p)
zope.uninstallProduct(app, p)

# Clean up Wicked turds
# XXX: This may tear down too much state
Expand Down Expand Up @@ -217,7 +216,7 @@ def setUpDefaultContent(self, app):
[]
)

z2.login(app['acl_users'], SITE_OWNER_NAME)
zope.login(app['acl_users'], SITE_OWNER_NAME)

# Create the site with the default set of extension profiles
from Products.CMFPlone.factory import addPloneSite
Expand Down Expand Up @@ -246,7 +245,7 @@ def setUpDefaultContent(self, app):
pas.portal_role_manager.doAssignRoleToPrincipal(TEST_USER_ID, role)

# Log out again
z2.logout()
zope.logout()


# Plone fixture layer instance. Should not be used on its own, but as a base
Expand Down Expand Up @@ -371,7 +370,7 @@ class MockMailHostLayer(Layer):
defaultBases = (PLONE_FIXTURE,)

def setUp(self):
with z2.zopeApp() as app:
with zope.zopeApp() as app:
portal = app[PLONE_SITE_ID]
portal.email_from_address = 'noreply@example.com'
portal.email_from_name = 'Plone Site'
Expand All @@ -383,7 +382,7 @@ def setUp(self):
sm.registerUtility(mailhost, provided=IMailHost)

def tearDown(self):
with z2.zopeApp() as app:
with zope.zopeApp() as app:
portal = app[PLONE_SITE_ID]
_o_mailhost = getattr(portal, '_original_MailHost', None)
if _o_mailhost:
Expand All @@ -399,12 +398,12 @@ def tearDown(self):
MOCK_MAILHOST_FIXTURE = MockMailHostLayer()


class IntegrationTesting(PloneTestLifecycle, z2.IntegrationTesting):
class IntegrationTesting(PloneTestLifecycle, zope.IntegrationTesting):
"""Plone version of the integration testing layer
"""


class FunctionalTesting(PloneTestLifecycle, z2.FunctionalTesting):
class FunctionalTesting(PloneTestLifecycle, zope.FunctionalTesting):
"""Plone version of the functional testing layer
"""

Expand Down
24 changes: 12 additions & 12 deletions src/plone/app/testing/layers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ For testing, we need a testrunner
Plone site fixture
~~~~~~~~~~~~~~~~~~

The ``PLONE_FIXTURE`` layer extends ``STARTUP`` from ``plone.testing.z2`` to
The ``PLONE_FIXTURE`` layer extends ``STARTUP`` from ``plone.testing.zope`` to
set up a Plone site.

**Note:** This layer should only be used as a base layer, and not directly in
Expand Down Expand Up @@ -56,10 +56,10 @@ password are found in the constants ``SITE_OWNER_NAME`` and
has the ``Manager`` role, and is the owner of the site object. You should not
normally use this for testing, unless you need to manipulate the site itself.

>>> from plone.testing import z2, zca
>>> from plone.testing import zope, zca
>>> from plone.app.testing.interfaces import SITE_OWNER_NAME

>>> with z2.zopeApp() as app:
>>> with zope.zopeApp() as app:
... print(app['acl_users'].getUser(SITE_OWNER_NAME))
... print(sorted(app['acl_users'].getUser(SITE_OWNER_NAME).getRolesInContext(app)))
admin
Expand All @@ -73,7 +73,7 @@ Inside the Plone site, the default theme is installed
/++theme++barceloneta/rules.xml

**Note:** Here, we have used the ``ploneSite`` context manager to get hold of
the Plone site root. Like ``z2.zopeApp()``, this is intended for use during
the Plone site root. Like ``zope.zopeApp()``, this is intended for use during
layer setup and tear-down, and will automatically commit any changes unless an
error is raised.

Expand Down Expand Up @@ -128,7 +128,7 @@ Let's set up the layers and attempt to run a test.
Let's now simulate a test

>>> zca.LAYER_CLEANUP.testSetUp()
>>> z2.STARTUP.testSetUp()
>>> zope.STARTUP.testSetUp()
>>> layers.PLONE_FIXTURE.testSetUp()
>>> layers.PLONE_INTEGRATION_TESTING.testSetUp()

Expand Down Expand Up @@ -165,7 +165,7 @@ Let's now simulate test tear-down.

>>> layers.PLONE_INTEGRATION_TESTING.testTearDown()
>>> layers.PLONE_FIXTURE.testTearDown()
>>> z2.STARTUP.testTearDown()
>>> zope.STARTUP.testTearDown()
>>> zca.LAYER_CLEANUP.testTearDown()

At this point, our transaction has been rolled back:
Expand Down Expand Up @@ -217,7 +217,7 @@ Let's set up the layers and attempt to run a test.
Let's now simulate a test

>>> zca.LAYER_CLEANUP.testSetUp()
>>> z2.STARTUP.testSetUp()
>>> zope.STARTUP.testSetUp()
>>> layers.PLONE_FIXTURE.testSetUp()
>>> layers.PLONE_FUNCTIONAL_TESTING.testSetUp()

Expand Down Expand Up @@ -247,7 +247,7 @@ Let's now simulate test tear-down.

>>> layers.PLONE_FUNCTIONAL_TESTING.testTearDown()
>>> layers.PLONE_FIXTURE.testTearDown()
>>> z2.STARTUP.testTearDown()
>>> zope.STARTUP.testTearDown()
>>> zca.LAYER_CLEANUP.testTearDown()

The previous database state should have been restored.
Expand Down Expand Up @@ -311,9 +311,9 @@ Let's now simulate a test. Test setup does nothing beyond what the base layers
do.

>>> zca.LAYER_CLEANUP.testSetUp()
>>> z2.STARTUP.testSetUp()
>>> zope.STARTUP.testSetUp()
>>> layers.PLONE_FIXTURE.testSetUp()
>>> z2.ZSERVER_FIXTURE.testSetUp()
>>> zope.WSGI_SERVER_FIXTURE.testSetUp()
>>> layers.PLONE_ZSERVER.testSetUp()

It is common in a test to use the Python API to change the state of the server
Expand Down Expand Up @@ -347,9 +347,9 @@ We can now look for this new object through the server.
Test tear-down does nothing beyond what the base layers do.

>>> layers.PLONE_ZSERVER.testTearDown()
>>> z2.ZSERVER_FIXTURE.testTearDown()
>>> zope.WSGI_SERVER_FIXTURE.testTearDown()
>>> layers.PLONE_FIXTURE.testTearDown()
>>> z2.STARTUP.testTearDown()
>>> zope.STARTUP.testTearDown()
>>> zca.LAYER_CLEANUP.testTearDown()

>>> 'portal' in layers.PLONE_ZSERVER
Expand Down
Loading

0 comments on commit 7d5eb0f

Please sign in to comment.