Author: bree
Date: Thu Feb 2 00:26:20 2006
New Revision: 2263
Modified:
azax/branches/snowsprint/tests/test_azaxview.py
Log:
Fix tests (template is also tested)
Modified: azax/branches/snowsprint/tests/test_azaxview.py
==============================================================================
--- azax/branches/snowsprint/tests/test_azaxview.py (original)
+++ azax/branches/snowsprint/tests/test_azaxview.py Thu Feb 2 00:26:20 2006
@@ -22,38 +22,53 @@
from zope.testing import doctest
from Testing.ZopeTestCase import ZopeTestCase
from Products.azax import AzaxBaseView
-#from Products.azax.azaxresponse import HTML_DTD
from Products.azax import config
from ZPublisher.HTTPRequest import HTTPRequest
from cStringIO import StringIO
+from Globals import InitializeClass
+from OFS.SimpleItem import SimpleItem
+from zope.publisher.browser import TestRequest
+import Products.Five
+from Products.Five.zcml import load_string, load_config
+from textwrap import dedent
-# fake request
+# Fake content
-def dummy(kdict, name='dummy'):
- return type(name, (object,), kdict)()
-
-def setHeader(self, a, b):
- self.__dict__.update(locals())
-
-fakerequest = HTTPRequest(StringIO(),
- dict(SERVER_NAME='dummy', SERVER_PORT='8080'),
- dummy(dict(setHeader=setHeader, name='Response')))
-
-class FakeContent(object):
+class FakeContent(SimpleItem, object):
pass
-#s = getGlobalService(Presentation)
-#s.provideView(for_, name, IBrowserRequest, class_, layer)
-#initializeClass(FakeContent)
+#InitializeClass(FakeContent)
class AzaxViewTestCase(ZopeTestCase):
def afterSetUp(self):
+ from zope.app.tests.placelesssetup import setUp
+ 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()
self.view = AzaxBaseView(fakecontent, fakerequest)
-
+ # Allow traversing
+ load_config('meta.zcml', package=Products.Five)
+ load_string(dedent('''\
+ <configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:five="http://namespaces.zope.org/five">
+ <include package="zope.app.traversing" />
+ <adapter
+ for="*"
+ factory="Products.Five.traversable.FiveTraversable"
+
provides="zope.app.traversing.interfaces.ITraversable"
+ />
+ <adapter
+ for="*"
+ factory="zope.app.traversing.adapters.Traverser"
+ provides="zope.app.traversing.interfaces.ITraverser"
+ />
+ </configure>'''))
+
class TestAzaxView(AzaxViewTestCase):
def test_empty(self):
@@ -102,32 +117,45 @@
def test_setHtmlAsChildTextTagPlusText(self):
self._checkSetHtmlResult('before<p>new_content</p>after')
-class FTestAzaxResponse(AzaxViewTestCase):
+class FTestAzaxView(AzaxViewTestCase):
'Functional tests'
- # XXX don't work at the moment
-
- def cleanupXMLForTesting(self, xml):
- return xml.replace(' />', '/>')
def _wrapped_commands(self, inline):
- return '%s\n<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:kukit="http://www.kukit.org/commands/1.0">' \
-# '<body>%s</body></html>' % (HTML_DTD, inline)
+ header = dedent('''\
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"file:///var/lib/zope2.8/instance/kukit/Products/azax/dtds/xhtml1-transitional.dtd">
+ <html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:kukit="http://www.kukit.org/commands/1.0"><body>
+ ''')
+ footer = dedent('''\
+ </body></html>
+ ''')
+ return header + inline + footer
def assertXMLEquals(self, a, b):
self.assertEqual(a, b)
def assertCommandsEqual(self, a, b):
- self.assertEqual(a, _wrapped_commands(b))
+ self.assertXMLEquals(a, self._wrapped_commands(b))
def test_empty(self):
view = self.view
- commands = view.getCommands()
- self.assertEqual(len(commands), 0)
+ result = view.render()
self.assertEquals(view.request.response.getHeader('Content-Type'),
'text/xml')
-
+ self.assertCommandsEqual(result, '')
+
+ def test_setHtmlAsChild(self):
+ view = self.view
+ view.setHtmlAsChild('div.class', 'new content')
+ result = view.render()
+ self.assertCommandsEqual(result, '''\
+<kukit:command selector="div.class" name="setHtmlAsChild">
+\t<kukit:param name="html">new content</kukit:param>
+</kukit:command>
+''')
+
def test_suite():
suites = []
suites.append(unittest.makeSuite(TestAzaxView))
- #suites.append(unittest.makeSuite(FTestAzaxView))
+ suites.append(unittest.makeSuite(FTestAzaxView))
suites.append(doctest.DocTestSuite('Products.azax.azaxview'))
return unittest.TestSuite(suites)
--
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins