Skip to content

Commit

Permalink
exclude tile stubs from test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Oct 28, 2016
1 parent 9af0897 commit 2a126e6
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ Changelog
1.0 (unreleased)
----------------

- Nothing changed yet.
- Add persistent tile wrapper
[tomgross]

- Unify names. It is now **HandlebarsTile**
[tomgross]


1.0rc1 (2016-08-29)
Expand Down
1 change: 1 addition & 0 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ zc.buildout = 2.5.1
zc.recipe.egg = 2.0.3
flake8 = 3.0.4
flake8_coding = 1.3.0
flake8-debugger = 1.4.0
i18ndude = 4.0.1
robotframework = 3.0
robotframework-ride = 1.5.2.1
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'plone.testing>=5.0.0',
'plone.app.contenttypes',
'plone.app.robotframework[debug]',
'plone.tiles'
],
},
entry_points="""
Expand Down
17 changes: 15 additions & 2 deletions src/collective/handlebars/browser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@

try:
get_distribution('plone.tiles')
except DistributionNotFound:
except DistributionNotFound: # pragma: no cover
class Tile(BrowserView):
"""Fake Tile which is only a BrowserView"""
class PersistentTile(BrowserView):
"""Fake persistent Tile which is only a BrowserView"""
else: # pragma: no cover
from plone.tiles.tile import Tile
from plone.tiles.tile import PersistentTile


# global handlebars compiler
Expand Down Expand Up @@ -139,7 +142,17 @@ def __call__(self, *args, **kwargs):
return self.main_template(*args, **kwargs)


class HandlebarTile(Tile, HandlebarsMixin):
class HandlebarsTile(Tile, HandlebarsMixin):

def __call__(self, *args, **kwargs):
return self.hbs_snippet()


# BBB
HandlebarTile = HandlebarsTile


class HandlebarsPersistentTile(PersistentTile, HandlebarsMixin):

def __call__(self, *args, **kwargs):
return self.hbs_snippet()
Expand Down
52 changes: 49 additions & 3 deletions src/collective/handlebars/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"""Setup tests for this package."""
from collective.handlebars.testing import COLLECTIVE_HANDLEBARS_INTEGRATION_TESTING # noqa
from collective.handlebars.browser.views import HandlebarsBrowserView
from collective.handlebars.browser.views import HandlebarTile
from collective.handlebars.browser.views import HandlebarsTile
from collective.handlebars.browser.views import HandlebarsPersistentTile

from plone import api
from zope.i18nmessageid import MessageFactory
Expand All @@ -18,7 +19,13 @@
_ = MessageFactory('my.domain')


class DummyHbsTile(HandlebarTile):
class DummyHbsTile(HandlebarsTile):

def get_contents(self):
return {'src': 'foo', 'alt': 'bar'}


class DummyHbsPersistentTile(HandlebarsPersistentTile):

def get_contents(self):
return {'src': 'foo', 'alt': 'bar'}
Expand Down Expand Up @@ -163,7 +170,46 @@ class TestHandlebarTile(unittest.TestCase):
layer = COLLECTIVE_HANDLEBARS_INTEGRATION_TESTING

def setUp(self):
self.tile = HandlebarTile(self.layer['portal'], self.layer['request'])
self.tile = HandlebarsTile(self.layer['portal'], self.layer['request'])
self.template_path = os.path.join(TEST_DATA__DIR,
'_slideshow_slide.js.hbs')

def test_get_contents_default(self):
""" Method `get_tile_data` is not implemented in base class
:return:
"""
view = HandlebarsBrowserView(self.layer['portal'],
self.layer['request'])
self.assertRaises(NotImplementedError, view.get_contents)

def test_get_hbs_template(self):
template = self.tile._get_hbs_template(self.template_path)
self.assertEqual(template({'src': 'foo', 'alt': 'bar'}).strip(),
u'<img src="foo" alt="bar">')

def test_get_partial_key(self):
self.assertEqual(self.tile._get_partial_key(self.template_path),
'_slideshow_slide.js')

def test_call_notemplate(self):
""" An error is raised, if no template is specified """
self.assertRaises(ValueError, self.tile)

def test_call_with_template(self):
tile = DummyHbsTile(self.layer['portal'], self.layer['request'])
setattr(tile, 'index', DummyHbsTemplate(self.template_path))
self.assertEqual(tile().strip(), u'<img src="foo" alt="bar">')


class TestHandlebarPersistentTile(unittest.TestCase):
"""Test that fhnw.web16theme viewlets."""

layer = COLLECTIVE_HANDLEBARS_INTEGRATION_TESTING

def setUp(self):
self.tile = HandlebarsPersistentTile(
self.layer['portal'], self.layer['request'])
self.template_path = os.path.join(TEST_DATA__DIR,
'_slideshow_slide.js.hbs')

Expand Down

0 comments on commit 2a126e6

Please sign in to comment.