Permalink
Browse files

100% test coverage

  • Loading branch information...
1 parent 0e71951 commit de60087af380e3d6f24e7c8e0aaf0d5434dd3223 @chrisrossi chrisrossi committed Aug 13, 2012
Showing with 102 additions and 2 deletions.
  1. +102 −2 pyramid_layout/tests/test_layout.py
@@ -6,17 +6,117 @@
# python >= 2.7
import unittest
+import mock
from pyramid import testing
-from pyramid_layout.layout import LayoutManager
class LayoutManagerTests(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
self.config.include('pyramid_layout')
- def test_structure(self):
+ def make_one(self, context, request):
+ from pyramid_layout.layout import LayoutManager as test_class
+ return test_class(context, request)
+
+ @mock.patch('pyramid_layout.layout.find_layout')
+ def test_use_layout(self, find_layout):
+ lm = self.make_one('context', 'request')
+ find_layout.return_value = 'Test Layout'
+ lm.use_layout('test')
+ self.assertEqual(lm.layout, 'Test Layout')
+ find_layout.assert_called_once_with('context', 'request', 'test')
+
+ @mock.patch('pyramid_layout.layout.find_layout')
+ def test_layout(self, find_layout):
+ lm = self.make_one('context', 'request')
+ find_layout.return_value = 'Test Layout'
+ self.assertEqual(lm.layout, 'Test Layout')
+ self.assertEqual(lm.layout, 'Test Layout')
+ find_layout.assert_called_once_with('context', 'request')
+
+ def test_render_panel(self):
+ from zope.interface import providedBy
+ from pyramid_layout.interfaces import IPanel
+ request = mock.Mock()
+ lookup = request.registry.adapters.lookup
+ panel = lookup.return_value
+ panel.return_value = 'Test Panel'
+ lm = self.make_one('context', request)
+ self.assertEqual(lm.render_panel('test'), 'Test Panel')
+ lookup.assert_called_once_with(
+ (providedBy('context'),), IPanel, name='test')
+ panel.assert_called_once_with('context', request)
+
+ def test_render_panel_with_args(self):
+ from zope.interface import providedBy
+ from pyramid_layout.interfaces import IPanel
+ request = mock.Mock()
+ lookup = request.registry.adapters.lookup
+ panel = lookup.return_value
+ panel.return_value = 'Test Panel'
+ lm = self.make_one('context', request)
+ self.assertEqual(lm.render_panel('test', 1, two=3), 'Test Panel')
+ lookup.assert_called_once_with(
+ (providedBy('context'),), IPanel, name='test')
+ panel.assert_called_once_with('context', request, 1, two=3)
+
+ def test_render_panel_no_panel(self):
+ from zope.interface import providedBy
+ from pyramid_layout.interfaces import IPanel
+ request = mock.Mock()
+ lookup = request.registry.adapters.lookup
+ lookup.return_value = None
+ lm = self.make_one('context', request)
+ self.assertEqual(lm.render_panel('test'), None)
+ lookup.assert_called_once_with(
+ (providedBy('context'),), IPanel, name='test')
+
+
+class Test_find_layout(unittest.TestCase):
+
+ def test_it(self):
+ from zope.interface import providedBy
+ from pyramid_layout.interfaces import ILayout
+ from pyramid_layout.layout import find_layout
+ request = mock.Mock()
+ lookup = request.registry.adapters.lookup
+ Layout = lookup.return_value
+ find_layout('context', request, 'test')
+ Layout.assert_called_once_with('context', request)
+ lookup.assert_called_once_with(
+ (providedBy('context'),), ILayout, name='test')
+
+
+class TestStructure(unittest.TestCase):
+
+ def test_it(self):
from pyramid_layout.layout import Structure
html = u'<h1>Hello</h1>'
s = Structure(html)
self.assertTrue(s.__html__(), html)
+
+
+class Test_layout_config(unittest.TestCase):
+
+ @mock.patch('pyramid_layout.layout.venusian')
+ def test_it(self, venusian):
+ from pyramid_layout.layout import layout_config
+ decorator = layout_config('name', 'context', 'template', 'containment')
+ self.assertEqual(decorator('wrapped'), 'wrapped')
+ info = venusian.attach.return_value
+ args, kwargs = venusian.attach.call_args
+ self.assertEqual(kwargs, {'category': 'pyramid_layout'})
+ wrapped, callback = args
+ self.assertEqual(wrapped, 'wrapped')
+ context = mock.Mock()
+ context.config.with_package.return_value = context
+ callback(context, 'name', 'layout')
+ context.config.with_package.assert_called_once_with(info.module)
+ context.add_layout.assert_called_once_with(
+ layout='layout',
+ name='name',
+ context='context',
+ template='template',
+ containment='containment',
+ _info=info.codeinfo)

0 comments on commit de60087

Please sign in to comment.