Skip to content

Commit

Permalink
Refactor test fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed Jan 30, 2017
1 parent 773991f commit 5f3da58
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 112 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
],
extras_require={
'test': [
'plone.app.contenttypes',
'plone.app.robotframework',
'plone.app.testing [robot]',
'plone.browserlayer',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<?xml version="1.0"?>
<metadata>
<version>1</version>
<dependencies>
<dependency>profile-plone.app.dexterity:default</dependency>
</dependencies>
</metadata>

This file was deleted.

This file was deleted.

This file was deleted.

17 changes: 5 additions & 12 deletions src/collective/behavior/featuredimage/testing.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down
18 changes: 0 additions & 18 deletions src/collective/behavior/featuredimage/testing.zcml

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
24 changes: 11 additions & 13 deletions src/collective/behavior/featuredimage/tests/test_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 5 additions & 7 deletions src/collective/behavior/featuredimage/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@ 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!')
quote = (
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')
14 changes: 14 additions & 0 deletions src/collective/behavior/featuredimage/tests/utils.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 5f3da58

Please sign in to comment.