From 5f3da5892e6d56126f6a2bb880f183d0a254a64c Mon Sep 17 00:00:00 2001 From: hvelarde Date: Mon, 30 Jan 2017 15:58:21 -0200 Subject: [PATCH] Refactor test fixture --- setup.py | 1 + .../profiles/default/metadata.xml | 3 -- .../profiles/testfixture/metadata.xml | 7 ---- .../profiles/testfixture/types.xml | 4 -- .../testfixture/types/Dexterity_Item.xml | 40 ------------------- .../behavior/featuredimage/testing.py | 17 +++----- .../behavior/featuredimage/testing.zcml | 18 --------- .../featuredimage/tests/Dexterity_Item.xml | 4 -- .../featuredimage/tests/test_behavior.robot | 8 ++-- .../featuredimage/tests/test_behaviors.py | 24 +++++------ .../featuredimage/tests/test_views.py | 12 +++--- .../behavior/featuredimage/tests/utils.py | 14 +++++++ 12 files changed, 40 insertions(+), 112 deletions(-) delete mode 100644 src/collective/behavior/featuredimage/profiles/testfixture/metadata.xml delete mode 100644 src/collective/behavior/featuredimage/profiles/testfixture/types.xml delete mode 100644 src/collective/behavior/featuredimage/profiles/testfixture/types/Dexterity_Item.xml delete mode 100644 src/collective/behavior/featuredimage/testing.zcml delete mode 100644 src/collective/behavior/featuredimage/tests/Dexterity_Item.xml create mode 100644 src/collective/behavior/featuredimage/tests/utils.py diff --git a/setup.py b/setup.py index 28288f6..b14aca5 100644 --- a/setup.py +++ b/setup.py @@ -50,6 +50,7 @@ ], extras_require={ 'test': [ + 'plone.app.contenttypes', 'plone.app.robotframework', 'plone.app.testing [robot]', 'plone.browserlayer', diff --git a/src/collective/behavior/featuredimage/profiles/default/metadata.xml b/src/collective/behavior/featuredimage/profiles/default/metadata.xml index 7030086..cf4492a 100644 --- a/src/collective/behavior/featuredimage/profiles/default/metadata.xml +++ b/src/collective/behavior/featuredimage/profiles/default/metadata.xml @@ -1,7 +1,4 @@ 1 - - profile-plone.app.dexterity:default - diff --git a/src/collective/behavior/featuredimage/profiles/testfixture/metadata.xml b/src/collective/behavior/featuredimage/profiles/testfixture/metadata.xml deleted file mode 100644 index 7030086..0000000 --- a/src/collective/behavior/featuredimage/profiles/testfixture/metadata.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - 1 - - profile-plone.app.dexterity:default - - diff --git a/src/collective/behavior/featuredimage/profiles/testfixture/types.xml b/src/collective/behavior/featuredimage/profiles/testfixture/types.xml deleted file mode 100644 index c464f7f..0000000 --- a/src/collective/behavior/featuredimage/profiles/testfixture/types.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/src/collective/behavior/featuredimage/profiles/testfixture/types/Dexterity_Item.xml b/src/collective/behavior/featuredimage/profiles/testfixture/types/Dexterity_Item.xml deleted file mode 100644 index bf32d69..0000000 --- a/src/collective/behavior/featuredimage/profiles/testfixture/types/Dexterity_Item.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - Dexterity Item - - - - view - True - True - - False - view - - - - False - cmf.AddPortalContent - plone.dexterity.content.Item - - - - - - - collective.behavior.featuredimage.tests:Dexterity_Item.xml - - - - - - - - - - - diff --git a/src/collective/behavior/featuredimage/testing.py b/src/collective/behavior/featuredimage/testing.py index fdb2e9a..e7bff94 100644 --- a/src/collective/behavior/featuredimage/testing.py +++ b/src/collective/behavior/featuredimage/testing.py @@ -1,14 +1,15 @@ # -*- coding: utf-8 -*- -"""Setup testing infrastructure. +"""Setup testing fixture. -For Plone 5 we need to manually install plone.app.contenttypes. +We need to install plone.app.contenttypes always. """ from collective.behavior.featuredimage.interfaces import IPackageSettings +from collective.behavior.featuredimage.tests.utils import enable_featured_image_behavior from plone import api +from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE as PLONE_FIXTURE from plone.app.robotframework.testing import AUTOLOGIN_LIBRARY_FIXTURE from plone.app.testing import FunctionalTesting from plone.app.testing import IntegrationTesting -from plone.app.testing import PLONE_FIXTURE from plone.app.testing import PloneSandboxLayer from plone.formwidget.namedfile.converter import b64encode_file from plone.testing import z2 @@ -32,20 +33,12 @@ class Fixture(PloneSandboxLayer): defaultBases = (PLONE_FIXTURE,) def setUpZope(self, app, configurationContext): - if PLONE_VERSION >= '5.0': - import plone.app.contenttypes - self.loadZCML(package=plone.app.contenttypes) - import collective.behavior.featuredimage self.loadZCML(package=collective.behavior.featuredimage) - self.loadZCML(package=collective.behavior.featuredimage, name='testing.zcml') def setUpPloneSite(self, portal): - if PLONE_VERSION >= '5.0': - self.applyProfile(portal, 'plone.app.contenttypes:default') - self.applyProfile(portal, 'collective.behavior.featuredimage:default') - self.applyProfile(portal, 'collective.behavior.featuredimage:testfixture') + enable_featured_image_behavior('News Item') class RobotFixture(Fixture): diff --git a/src/collective/behavior/featuredimage/testing.zcml b/src/collective/behavior/featuredimage/testing.zcml deleted file mode 100644 index ac9da04..0000000 --- a/src/collective/behavior/featuredimage/testing.zcml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - diff --git a/src/collective/behavior/featuredimage/tests/Dexterity_Item.xml b/src/collective/behavior/featuredimage/tests/Dexterity_Item.xml deleted file mode 100644 index af29eff..0000000 --- a/src/collective/behavior/featuredimage/tests/Dexterity_Item.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/src/collective/behavior/featuredimage/tests/test_behavior.robot b/src/collective/behavior/featuredimage/tests/test_behavior.robot index f76c06f..c61ac79 100644 --- a/src/collective/behavior/featuredimage/tests/test_behavior.robot +++ b/src/collective/behavior/featuredimage/tests/test_behavior.robot @@ -40,15 +40,15 @@ Test CRUD *** Keywords *** -Click Add Dexterity Item +Click Add News Item Open Add New Menu - Click Link css=a#dexterity-item - Page Should Contain Dexterity Item + Click Link css=a#news-item + Page Should Contain News Item Create [arguments] ${title} - Click Add Dexterity Item + Click Add News Item Input Text css=${title_selector} ${title} Click Link Featured Image Select Checkbox css=${featuredimage_enabled_selector} diff --git a/src/collective/behavior/featuredimage/tests/test_behaviors.py b/src/collective/behavior/featuredimage/tests/test_behaviors.py index 8c698f6..c8b1653 100644 --- a/src/collective/behavior/featuredimage/tests/test_behaviors.py +++ b/src/collective/behavior/featuredimage/tests/test_behaviors.py @@ -13,28 +13,26 @@ def setUp(self): self.portal = self.layer['portal'] with api.env.adopt_roles(['Manager']): - self.folder = api.content.create(self.portal, 'Folder', 'folder') - - self.dummy1 = api.content.create(self.folder, 'Dexterity Item', 'd1') + self.obj = api.content.create(self.portal, 'News Item', 'foo') def test_featuredimage_behavior(self): from collective.behavior.featuredimage.behaviors.interfaces import IFeaturedImage - self.assertTrue(IFeaturedImage.providedBy(self.dummy1)) + self.assertTrue(IFeaturedImage.providedBy(self.obj)) def test_fields(self): - self.assertTrue(self.dummy1.featuredimage_enabled) - self.assertIsNone(self.dummy1.featuredimage_quote) - self.assertIsNone(self.dummy1.featuredimage_author) + self.assertTrue(self.obj.featuredimage_enabled) + self.assertIsNone(self.obj.featuredimage_quote) + self.assertIsNone(self.obj.featuredimage_author) - self.dummy1.featuredimage_enabled = True + self.obj.featuredimage_enabled = True quote = ( u'Give me six hours to chop down a tree and ' u'I will spend the first four sharpening the axe.' ) author = u'Abraham Lincoln' - self.dummy1.featuredimage_quote = quote - self.dummy1.featuredimage_author = author - self.assertTrue(self.dummy1.featuredimage_enabled) - self.assertEqual(self.dummy1.featuredimage_quote, quote) - self.assertEqual(self.dummy1.featuredimage_author, author) + self.obj.featuredimage_quote = quote + self.obj.featuredimage_author = author + self.assertTrue(self.obj.featuredimage_enabled) + self.assertEqual(self.obj.featuredimage_quote, quote) + self.assertEqual(self.obj.featuredimage_author, author) diff --git a/src/collective/behavior/featuredimage/tests/test_views.py b/src/collective/behavior/featuredimage/tests/test_views.py index 00d5c96..6f0294d 100644 --- a/src/collective/behavior/featuredimage/tests/test_views.py +++ b/src/collective/behavior/featuredimage/tests/test_views.py @@ -16,11 +16,9 @@ def setUp(self): self.request = self.layer['request'] alsoProvides(self.request, IBrowserLayer) with api.env.adopt_roles(['Manager']): - self.di1 = api.content.create( - self.portal, 'Dexterity Item', 'di1', - title='Extra! Extra!' - ) - self.view = api.content.get_view(u'featuredimage', self.di1, self.request) + self.obj = api.content.create( + self.portal, 'News Item', 'foo', title='Extra! Extra!') + self.view = api.content.get_view(u'featuredimage', self.obj, self.request) def test_quote(self): self.assertEqual(self.view.quote(), 'Extra! Extra!') @@ -28,10 +26,10 @@ def test_quote(self): u'Give me six hours to chop down a tree and ' u'I will spend the first four sharpening the axe.' ) - self.di1.featuredimage_quote = quote + self.obj.featuredimage_quote = quote self.assertEqual(self.view.quote(), quote) def test_author(self): self.assertEqual(self.view.author(), 'test_user_1_') - self.di1.featuredimage_author = u'Abraham Lincoln' + self.obj.featuredimage_author = u'Abraham Lincoln' self.assertEqual(self.view.author(), u'Abraham Lincoln') diff --git a/src/collective/behavior/featuredimage/tests/utils.py b/src/collective/behavior/featuredimage/tests/utils.py new file mode 100644 index 0000000..3460ddb --- /dev/null +++ b/src/collective/behavior/featuredimage/tests/utils.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +from plone.dexterity.interfaces import IDexterityFTI +from zope.component import queryUtility + + +def enable_featured_image_behavior(portal_type): + """Enable Related Items behavior on the specified portal type.""" + fti = queryUtility(IDexterityFTI, name=portal_type) + behavior = 'collective.behavior.featuredimage.behaviors.interfaces.IFeaturedImage' + if behavior in fti.behaviors: + return + behaviors = list(fti.behaviors) + behaviors.append(behavior) + fti.behaviors = tuple(behaviors)