[KSS-checkins] r35639 - in kukit/kss.core/trunk: . tests

reebalazs at codespeak.net reebalazs at codespeak.net
Tue Dec 12 19:31:32 CET 2006


Author: reebalazs
Date: Tue Dec 12 19:31:28 2006
New Revision: 35639

Modified:
   kukit/kss.core/trunk/azaxview.py
   kukit/kss.core/trunk/azaxview.txt
   kukit/kss.core/trunk/siteview.txt
   kukit/kss.core/trunk/tests/base.py
   kukit/kss.core/trunk/tests/configure-unittest.zcml
   kukit/kss.core/trunk/tests/test_azaxview.py
Log:
Fix tests apart from azaxview.txt and siteview.txt

Modified: kukit/kss.core/trunk/azaxview.py
==============================================================================
--- kukit/kss.core/trunk/azaxview.py	(original)
+++ kukit/kss.core/trunk/azaxview.py	Tue Dec 12 19:31:28 2006
@@ -73,9 +73,17 @@
 
         self._sitemanager.__bases__ = (next_sitemanager, )
 
+        # On Five, we should wrap it in the acquisition context
+        # see, if self has aq_parent, it is done obligatoraly
+        try:
+            self.context.aq_parent
+        except AttributeError:
+            # Zope3 - No problem.
+            wrapped_view = self
+        else:
+            wrapped_view = self.__of__(self.context)
+
         # register object event handler
-        # we should wrap it in the acquisition context
-        wrapped_view = self.__of__(self.context)
         self._sitemanager.registerHandler(wrapped_view._eventRedispatcher)
         ##setHooks()
         ##setSite(self)

Modified: kukit/kss.core/trunk/azaxview.txt
==============================================================================
--- kukit/kss.core/trunk/azaxview.txt	(original)
+++ kukit/kss.core/trunk/azaxview.txt	Tue Dec 12 19:31:28 2006
@@ -17,16 +17,23 @@
 
   >>> from kss.core.azaxview import AzaxBaseView
   >>> from kss.core.interfaces import IAzaxEvent
-  >>> from kss.core.tests.base import DebugTestRequest
+  >>> from kss.core.tests.base import IDebugRequest
   >>> from zope import component
   >>> from zope.lifecycleevent import ObjectModifiedEvent
   >>> from zope.lifecycleevent.interfaces import IObjectModifiedEvent
   >>> from zope.event import notify
   >>> from zope.app.component.interfaces import ISite
+  >>> from zope.interface import directlyProvides, directlyProvidedBy
+  >>> from zope.publisher.browser import TestRequest
 
   >>> from zope.app.folder import folder
   >>> myfolder = folder.rootFolder()
 
+This will make the commands rendered as test-friendly structures.
+
+  >>> request = TestRequest()
+  >>> directlyProvides(request, directlyProvidedBy(request) + IDebugRequest)
+
 Now we will write our custom.
 
   >>> class SampleView(AzaxBaseView):
@@ -35,7 +42,6 @@
   ...         self.handle(ObjectModifiedEvent(title))
   ...         return self.render()
 
-  >>> request = DebugTestRequest()
   >>> view = SampleView(myfolder, request)
   >>> view.add_page("some title")
   []

Modified: kukit/kss.core/trunk/siteview.txt
==============================================================================
--- kukit/kss.core/trunk/siteview.txt	(original)
+++ kukit/kss.core/trunk/siteview.txt	Tue Dec 12 19:31:28 2006
@@ -21,6 +21,7 @@
 
 When created this view will make it's manager the default site manager.
 
+Context must be 
   >>> from zope import component
   >>> old_sitemanager = component.getSiteManager()
   >>> view = SiteView(None, None)

Modified: kukit/kss.core/trunk/tests/base.py
==============================================================================
--- kukit/kss.core/trunk/tests/base.py	(original)
+++ kukit/kss.core/trunk/tests/base.py	Tue Dec 12 19:31:28 2006
@@ -22,15 +22,12 @@
 from Testing.ZopeTestCase import ZopeTestCase
 import kss.core
 from kss.core import AzaxBaseView
-#from kss.core import config 
-#from ZPublisher.HTTPRequest import HTTPRequest
-#from cStringIO import StringIO
-#from Globals import InitializeClass
 from OFS.SimpleItem import SimpleItem
 from textwrap import dedent
 from zope.publisher.browser import TestRequest
 from zope.publisher.interfaces.browser import IBrowserRequest
 from zope.interface import Interface, implements
+from zope import interface as iapi
 
 try:
     # Zope > 2.8
@@ -39,47 +36,24 @@
     # Zope == 2.8
     from zope.app.tests import placelesssetup
 
+# Test view
+#
+
+class TestView(AzaxBaseView):
+    def testMethod(self):
+        'Yes.'
+
 # Debug request
 # This has a modified render.
 
 class IDebugRequest(IBrowserRequest):
     'The debug request'
 
-class DebugTestRequest(TestRequest):
-    'Debug test request'
-    implements(IDebugRequest)
-    def __init__(self):
-        self.RESPONSE = DebugTestResponse()
-        self.form = {}
-
-class DebugTestResponse:
-    def __init__(self, status=200):
-        self.status = status
-    def getStatus(self):
-        return self.status
-    def setStatus(self, status):
-        self.status = status
-
-# Fake content
-
-class FakeContent(SimpleItem, object):
-    pass
-    
-#InitializeClass(FakeContent)
-
 class AzaxViewTestCase(ZopeTestCase):
 
     def afterSetUp(self):
         placelesssetup.setUp()
-        # fake content
-        fakecontent = FakeContent()
-        self.folder._setObject('ob', fakecontent)
-        fakecontent = fakecontent.__of__(self.folder)
-        # Set up a fake view (with no content)
-        fakerequest = TestRequest()
-        debugfakerequest = DebugTestRequest()
-        self.view = AzaxBaseView(fakecontent, fakerequest)
-        self.debug_view = AzaxBaseView(fakecontent, debugfakerequest)
+
         # Allow traversing
         try:
             import Products.Five
@@ -88,7 +62,7 @@
             pass
             # XXX TODO fix this?? --- never run yet on Z3
             from zope.configuration.xmlconfig import XMLConfig
-            XMLConfig('tests/configure-unittes.zcml', kss.core)()
+            XMLConfig('tests/configure-unittest.zcml', kss.core)()
         else:
             from Products.Five.zcml import load_string, load_config
             load_config('meta.zcml', package=Products.Five)
@@ -122,7 +96,17 @@
             load_config('meta.zcml', package=kss.core)
             load_config('configure.zcml', package=kss.core)
             load_config('configure-unittest.zcml', package=kss.core.tests)
-             
+    
+    def createView(self):
+        "Set up a fake view (with no content)"
+        self.view = self.folder.restrictedTraverse('testMethod')
+        return self.view
+
+    def setDebugRequest(self):
+        'commands will be rendered as test friendly data structures'
+        request = self.portal.REQUEST
+        iapi.directlyProvides(request, iapi.directlyProvidedBy(request) + IDebugRequest)
+
     def beforeTearDown(self):
         placelesssetup.tearDown()
         try:

Modified: kukit/kss.core/trunk/tests/configure-unittest.zcml
==============================================================================
--- kukit/kss.core/trunk/tests/configure-unittest.zcml	(original)
+++ kukit/kss.core/trunk/tests/configure-unittest.zcml	Tue Dec 12 19:31:28 2006
@@ -5,6 +5,7 @@
            >
  
     <!-- Registration of a command view, for use in the tests.
+         This will provide the test-friendly rendering of commands.
     -->
 
     <adapter
@@ -14,4 +15,15 @@
         factory=".commandinspector.CommandInspectorView"
     />
 
+    <!-- Register the kss view that makes it possible to
+         instantiate a view
+    -->
+    <browser:page
+      for="*"
+      class=".base.TestView"
+      attribute="testMethod"
+      name="testMethod"
+      permission="zope.Public"
+      />
+
 </configure>

Modified: kukit/kss.core/trunk/tests/test_azaxview.py
==============================================================================
--- kukit/kss.core/trunk/tests/test_azaxview.py	(original)
+++ kukit/kss.core/trunk/tests/test_azaxview.py	Tue Dec 12 19:31:28 2006
@@ -22,7 +22,7 @@
 import unittest, os
 from textwrap import dedent
 from zope.testing import doctest
-from base import AzaxViewTestCase, FakeContent, TestRequest, DebugTestRequest
+from base import AzaxViewTestCase
 from kss.core import AzaxUnicodeError
 from kss.core.plugins.core.interfaces import IKSSCoreCommands
 from zope.testing.cleanup import CleanUp as PlacelessSetup
@@ -68,12 +68,12 @@
 class TestAzaxView(AzaxViewTestCase):
     
     def test_empty(self):
-        view = self.view
+        view = self.createView()
         commands = view.getCommands()
         self.assertEqual(len(commands), 0)
 
     def test_addCommand(self):
-        view = self.view
+        view = self.createView()
         commands = view.getCommands()
         command = commands.addCommand('replaceInnerHTML', 'selector')
         self.assertEqual(len(commands), 1)
@@ -86,7 +86,7 @@
     # Nevertheless, we test all these cases
     
     def _checkSetHtmlResult(self, content, content2=None):
-        view = self.view
+        view = self.createView()
         view.getCommandSet('core').replaceInnerHTML('div.class', content)
         commands = view.getCommands()
         self.assertEqual(len(commands), 1)
@@ -155,13 +155,13 @@
         self.assertXMLEquals(a, self._wrapped_commands(b))
 
     def test_empty(self):
-        view = self.view
+        view = self.createView()
         result = view.render()
-        self.assertEquals(view.request.response.getHeader('Content-Type'), 'text/xml;charset=utf-8')
+        self.assertEquals(view.request.response.getHeader('content-type'), 'text/xml;charset=utf-8')
         self.assertCommandsEqual(result, '')
     
     def test_replaceInnerHTML(self):
-        view = self.view
+        view = self.createView()
         view.getCommandSet('core').replaceInnerHTML('div.class', 'new content')
         result = view.render()
         awaited = u'''\
@@ -173,7 +173,7 @@
         self.assertCommandsEqual(result, awaited)
         
     def test_setCommandSet(self):
-        view = self.view
+        view = self.createView()
         cs = view.getCommandSet('core')
         cs.replaceInnerHTML('div.class', 'new content')
         result = view.render()


More information about the Kukit-checkins mailing list