From 2a126e614b3dde9482dffd3e62a8b59f17a6046d Mon Sep 17 00:00:00 2001 From: Tom Gross Date: Fri, 28 Oct 2016 12:17:44 +0000 Subject: [PATCH] exclude tile stubs from test coverage --- CHANGES.rst | 6 ++- buildout.cfg | 1 + setup.py | 1 + src/collective/handlebars/browser/views.py | 17 +++++- src/collective/handlebars/tests/test_views.py | 52 +++++++++++++++++-- 5 files changed, 71 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index acd9db7..9ef629a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) diff --git a/buildout.cfg b/buildout.cfg index 8c8e680..db2ed70 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -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 diff --git a/setup.py b/setup.py index e2351cd..2801e56 100644 --- a/setup.py +++ b/setup.py @@ -52,6 +52,7 @@ 'plone.testing>=5.0.0', 'plone.app.contenttypes', 'plone.app.robotframework[debug]', + 'plone.tiles' ], }, entry_points=""" diff --git a/src/collective/handlebars/browser/views.py b/src/collective/handlebars/browser/views.py index ffe4928..fc05c85 100644 --- a/src/collective/handlebars/browser/views.py +++ b/src/collective/handlebars/browser/views.py @@ -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 @@ -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() diff --git a/src/collective/handlebars/tests/test_views.py b/src/collective/handlebars/tests/test_views.py index b92ef60..569d637 100644 --- a/src/collective/handlebars/tests/test_views.py +++ b/src/collective/handlebars/tests/test_views.py @@ -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 @@ -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'} @@ -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'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'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')