Skip to content

Commit

Permalink
Merge pull request #51 from plone/add_copy_of_at_layer
Browse files Browse the repository at this point in the history
add new bbb layer for Archetypes
  • Loading branch information
jensens authored Sep 27, 2018
2 parents bb25ef4 + 4ee0b79 commit 340a19c
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ New features:
- Load negotiator from plone.i18n (PTS removed).
[jensens, ksuess]

- Add copy of bbb.PloneTestCase. For Plone 5.2 the bbb.PloneTestCase will uses Dexterity instead of Archetypes. Adding bbb_at.PloneTestCase for them to use allows to keep the AT tests working. See https://github.com/plone/plone.app.testing/pull/51
[pbauer]

Bug fixes:

- *add item here*
Expand Down
2 changes: 1 addition & 1 deletion plone/app/testing/bbb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""Backwards-compatibility test class for PloneTestCase."""
"""Backwards-compatibility test class for PloneTestCase for Dexterity."""

from AccessControl import getSecurityManager
from plone.app import testing
Expand Down
124 changes: 124 additions & 0 deletions plone/app/testing/bbb_at.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# -*- coding: utf-8 -*-
"""Backwards-compatibility test class for PloneTestCase for Archetypes."""

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

import transaction
import unittest


def _createMemberarea(portal, user_id):
mtool = portal.portal_membership
members = mtool.getMembersFolder()
if members is None:
_createObjectByType('Folder', portal, id='Members')
if not mtool.getMemberareaCreationFlag():
mtool.setMemberareaCreationFlag()
mtool.createMemberArea(user_id)
if mtool.getMemberareaCreationFlag():
mtool.setMemberareaCreationFlag()


class PloneTestCaseFixture(testing.PloneSandboxLayer):

defaultBases = (testing.PLONE_FIXTURE,)

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

def setUpPloneSite(self, portal):
# restore default workflow
testing.applyProfile(portal, 'Products.CMFPlone:testfixture')

# add default content
testing.applyProfile(portal, 'Products.ATContentTypes:content')

# add home folder for default test user
_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')

PTC_FIXTURE = PloneTestCaseFixture()
PTC_FUNCTIONAL_TESTING = testing.FunctionalTesting(
bases=(PTC_FIXTURE,), name='PloneTestCase:Functional')


class PloneTestCase(Functional, unittest.TestCase):

layer = PTC_FUNCTIONAL_TESTING

def setUp(self):
"""Set up before each test."""
self.beforeSetUp()
self.app = self.layer['app']
self.portal = self.layer['portal']
self.folder = self.portal.portal_membership.getHomeFolder(
testing.TEST_USER_ID)
transaction.commit()
self.afterSetUp()

def beforeSetUp(self):
"""Hook to do setup before the portal is created."""
pass

def afterSetUp(self):
"""Hook to do setup after the portal is created."""

def tearDown(self):
"""Tear down after each test."""
self.beforeTearDown()
transaction.abort()
super(PloneTestCase, self).tearDown()
self.afterTearDown()

def beforeTearDown(self):
"""Hook to do teardown before the portal is removed."""

def afterTearDown(self):
"""Hook to do teardown after the portal is removed."""

def setRoles(self, roles, name=testing.TEST_USER_ID):
"""Set the effective roles of a user."""
testing.setRoles(self.portal, name, roles)

def setGroups(self, groups, name=testing.TEST_USER_ID):
'''Changes the user's groups.'''
uf = self.portal['acl_users']
uf.userSetGroups(name, list(groups))
user = getSecurityManager().getUser()
if name == user.getId():
self.login(user.getUserName())

def setPermissions(self, permissions, role='Member'):
"""Changes the permissions assigned to role."""
self.portal.manage_role(role, list(permissions))

def login(self, userName=testing.TEST_USER_NAME):
"""Log in to the portal as the given user."""
testing.login(self.portal, userName)

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)

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

def createMemberarea(self, name):
"""Create a minimal memberarea."""
_createMemberarea(self.portal, name)

1 comment on commit 340a19c

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

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

plone/app/testing/bbb.py:55:1: E305 expected 2 blank lines after class or function definition, found 1
plone/app/testing/bbb.py:99:9: Q001 Remove bad quotes from multiline string.
plone/app/testing/bbb_at.py:55:1: E305 expected 2 blank lines after class or function definition, found 1
plone/app/testing/bbb_at.py:99:9: Q001 Remove bad quotes from multiline string.
plone/app/testing/cleanup.py:39:1: E305 expected 2 blank lines after class or function definition, found 1
plone/app/testing/helpers.py:432:16: D001 found xmlconfig.file( replace it with self.loadZCML(
plone/app/testing/helpers.py:442:25: C812 missing trailing comma
plone/app/testing/helpers.py:488:41: C812 missing trailing comma
plone/app/testing/layers.py:106:32: C812 missing trailing comma
plone/app/testing/layers.py:141:45: C812 missing trailing comma
plone/app/testing/layers.py:167:21: D001 found xmlconfig.file( replace it with self.loadZCML(
plone/app/testing/layers.py:203:11: T000 Todo note found.
plone/app/testing/layers.py:227:15: C812 missing trailing comma
plone/app/testing/layers.py:253:31: C812 missing trailing comma
plone/app/testing/layers.py:264:1: E305 expected 2 blank lines after class or function definition, found 1
plone/app/testing/layers.py:358:39: C812 missing trailing comma
plone/app/testing/layers.py:380:1: E305 expected 2 blank lines after class or function definition, found 1
plone/app/testing/layers.py:382:29: C812 missing trailing comma
plone/app/testing/layers.py:386:28: C812 missing trailing comma
plone/app/testing/layers.py:391:25: C812 missing trailing comma
plone/app/testing/layers.py:395:27: C812 missing trailing comma
plone/app/testing/selenium_layers.py:21:35: C812 missing trailing comma
plone/app/testing/selenium_layers.py:32:1: E305 expected 2 blank lines after class or function definition, found 1

Follow these instructions to reproduce it locally.

Please sign in to comment.