[Checkins] SVN: zope.app.pagetemplate/tags/3.7.0/src/zope/app/pagetemplate/tests/test_simpleviewclass.py Coverage.

Tres Seaver tseaver at palladion.com
Mon May 25 20:06:46 EDT 2009


Log message for revision 100382:
  Coverage.

Changed:
  U   zope.app.pagetemplate/tags/3.7.0/src/zope/app/pagetemplate/tests/test_simpleviewclass.py

-=-
Modified: zope.app.pagetemplate/tags/3.7.0/src/zope/app/pagetemplate/tests/test_simpleviewclass.py
===================================================================
--- zope.app.pagetemplate/tags/3.7.0/src/zope/app/pagetemplate/tests/test_simpleviewclass.py	2009-05-25 20:49:45 UTC (rev 100381)
+++ zope.app.pagetemplate/tags/3.7.0/src/zope/app/pagetemplate/tests/test_simpleviewclass.py	2009-05-26 00:06:45 UTC (rev 100382)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2001-2009 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -17,18 +17,20 @@
 """
 import unittest
 
-from zope.app.pagetemplate.simpleviewclass import SimpleViewClass
-from zope.app.pagetemplate.tests.simpletestview import SimpleTestView
-from zope.publisher.browser import TestRequest
+class Test_SimpleTestView(unittest.TestCase):
 
-class data(object): pass
+    def _getTargetClass(self):
+        from zope.app.pagetemplate.tests.simpletestview import SimpleTestView
+        return SimpleTestView
 
-class SimpleViewTestCase(unittest.TestCase):
+    def _makeOne(self, context, request):
+        return self._getTargetClass()(context, request)
 
     def test_simple(self):
-        ob = data()
+        from zope.publisher.browser import TestRequest
+        context = DummyContext()
         request = TestRequest()
-        view = SimpleTestView(ob, request)
+        view = self._makeOne(context, request)
         macro = view['test']
         out = view()
         self.assertEqual(out,
@@ -37,27 +39,38 @@
                          '    <p>hello world</p>\n'
                          '  </body>\n</html>\n')
 
-    def test_name(self):
-        View = SimpleViewClass('testsimpleviewclass.pt', name='test.html')
-        view = View(None, None)
+class Test_SimpleViewClass(unittest.TestCase):
+
+    def _getTargetClass(self):
+        from zope.app.pagetemplate.simpleviewclass import SimpleViewClass
+        return SimpleViewClass
+
+    def _makeKlass(self, *args, **kw):
+        return self._getTargetClass()(*args, **kw)
+
+    def test___name__(self):
+        klass = self._makeKlass('testsimpleviewclass.pt', name='test.html')
+        view = klass(None, None)
         self.assertEqual(view.__name__, 'test.html')
 
-    def test_getitem(self):
-        View = SimpleViewClass('testsimpleviewclass.pt', name='test.html')
-        view = View(None, None)
+    def test___getitem___(self):
+        klass = self._makeKlass('testsimpleviewclass.pt', name='test.html')
+        view = klass(None, None)
         self.assert_(view['test'] is not None)
         self.assertRaises(KeyError, view.__getitem__, 'foo')
 
-    def test_WBases(self):
-        class C(object): pass
+    def test_w_base_classes(self):
+        from zope.publisher.browser import TestRequest
+        class BaseClass(object):
+            pass
 
-        SimpleTestView = SimpleViewClass('testsimpleviewclass.pt', bases=(C, ))
+        klass = self._makeKlass('testsimpleviewclass.pt', bases=(BaseClass, ))
 
-        self.failUnless(issubclass(SimpleTestView, C))
+        self.failUnless(issubclass(klass, BaseClass))
 
-        ob = data()
+        ob = DummyContext()
         request = TestRequest()
-        view = SimpleTestView(ob, request)
+        view = klass(ob, request)
         macro = view['test']
         out = view()
         self.assertEqual(out,
@@ -66,8 +79,95 @@
                          '    <p>hello world</p>\n'
                          '  </body>\n</html>\n')
 
+class Test_simple(unittest.TestCase):
+
+    def _getTargetClass(self):
+        from zope.app.pagetemplate.simpleviewclass import simple
+        return simple
+
+    def _makeOne(self, context=None, request=None):
+        if context is None:
+            context = DummyContext()
+        if request is None:
+            request = DummyRequest()
+        return self._getTargetClass()(context, request)
+
+    def test_class_conforms_to_IBrowserPublisher(self):
+        from zope.interface.verify import verifyClass
+        from zope.publisher.interfaces.browser import IBrowserPublisher
+        verifyClass(IBrowserPublisher, self._getTargetClass())
+
+    def test_browserDefault(self):
+        request = DummyRequest()
+        view = self._makeOne(request=request)
+        self.assertEqual(view.browserDefault(request), (view, ()))
+
+    def test_publishTraverse_not_index_raises_NotFound(self):
+        from zope.publisher.interfaces import NotFound
+        request = DummyRequest()
+        view = self._makeOne(request=request)
+        self.assertRaises(NotFound, view.publishTraverse, request, 'nonesuch')
+
+    def test_publishTraverse_w_index_returns_index(self):
+        request = DummyRequest()
+        view = self._makeOne(request=request)
+        index = view.index = DummyTemplate()
+        self.failUnless(view.publishTraverse(request, 'index.html') is index)
+
+    def test___getitem___uses_index_macros(self):
+        view = self._makeOne()
+        view.index = index = DummyTemplate()
+        index.macros = {}
+        index.macros['aaa'] = aaa = object()
+        self.failUnless(view['aaa'] is aaa)
+
+    def test___call___no_args_no_kw(self):
+        view = self._makeOne()
+        view.index = index = DummyTemplate()
+        result = view()
+        self.failUnless(result is index)
+        self.assertEqual(index._called_with, ((), {}))
+
+    def test___call___w_args_no_kw(self):
+        view = self._makeOne()
+        view.index = index = DummyTemplate()
+        result = view('abc')
+        self.failUnless(result is index)
+        self.assertEqual(index._called_with, (('abc',), {}))
+
+    def test___call___no_args_w_kw(self):
+        view = self._makeOne()
+        view.index = index = DummyTemplate()
+        result = view(foo='bar')
+        self.failUnless(result is index)
+        self.assertEqual(index._called_with, ((), {'foo': 'bar'}))
+
+    def test___call___no_args_no_kw(self):
+        view = self._makeOne()
+        view.index = index = DummyTemplate()
+        result = view('abc', foo='bar')
+        self.failUnless(result is index)
+        self.assertEqual(index._called_with, (('abc',), {'foo': 'bar'}))
+
+
+class DummyContext:
+    pass
+
+class DummyResponse:
+    pass
+
+class DummyRequest:
+    debug = False
+    response = DummyResponse()
+
+class DummyTemplate:
+    def __call__(self, *args, **kw):
+        self._called_with = (args, kw)
+        return self
+
 def test_suite():
-    return unittest.makeSuite(SimpleViewTestCase)
-
-if __name__=='__main__':
-    unittest.TextTestRunner().run(test_suite())
+    return unittest.TestSuite((
+        unittest.makeSuite(Test_SimpleTestView),
+        unittest.makeSuite(Test_SimpleViewClass),
+        unittest.makeSuite(Test_simple),
+    ))



More information about the Checkins mailing list