[Checkins] SVN: zc.resourcelibrary/trunk/ - buildoutify zc.resourcelibrary

Benji York benji at zope.com
Mon Mar 19 14:37:01 EDT 2007


Log message for revision 73347:
   - buildoutify zc.resourcelibrary
   - make tests actually run
   - fix a bug that would cause incorrect mangling of decoy "<head>" sections
  

Changed:
  _U  zc.resourcelibrary/trunk/
  A   zc.resourcelibrary/trunk/buildout.cfg
  U   zc.resourcelibrary/trunk/src/zc/resourcelibrary/README.txt
  D   zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/configure.zcml
  A   zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/ftesting.zcml
  D   zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/test_doc.py
  A   zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/test_template_5.pt
  A   zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/tests.py
  U   zc.resourcelibrary/trunk/src/zc/resourcelibrary/publication.py
  U   zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests.py
  U   zc.resourcelibrary/trunk/src/zc/resourcelibrary/zc.resourcelibrary-ftesting.zcml

-=-

Property changes on: zc.resourcelibrary/trunk
___________________________________________________________________
Name: svn:ignore
   - build
dist

   + build
dist
bin
build
dist
lib
setup.cfg
develop-eggs
eggs
parts
.installed.cfg


Added: zc.resourcelibrary/trunk/buildout.cfg
===================================================================
--- zc.resourcelibrary/trunk/buildout.cfg	2007-03-19 16:18:53 UTC (rev 73346)
+++ zc.resourcelibrary/trunk/buildout.cfg	2007-03-19 18:37:00 UTC (rev 73347)
@@ -0,0 +1,14 @@
+[buildout]
+develop = .
+parts = zope3 test
+
+find-links = http://download.zope.org/distribution/
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = zc.resourcelibrary
+extra-paths = parts/zope3/src
+
+[zope3]
+recipe = zc.recipe.zope3checkout
+url = svn://svn.zope.org/repos/main/Zope3/trunk

Modified: zc.resourcelibrary/trunk/src/zc/resourcelibrary/README.txt
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/README.txt	2007-03-19 16:18:53 UTC (rev 73346)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/README.txt	2007-03-19 18:37:00 UTC (rev 73347)
@@ -243,6 +243,22 @@
     ZopeXMLConfigurationError: ...
         ConfigurationError: Directory u'...does-not-exist' does not exist
 
+Multiple Heads
+--------------
+
+On occasion the body of an HTML document may contain the text "<head>".  In
+those cases, only the actual head tag should be manipulated.  The first
+occurrence of "<head>" has the script tag inserted...
+
+    >>> browser.open('http://localhost/zc.resourcelibrary.test_template_5')
+    >>> print browser.contents
+    <html>...<head> <script src="http://localhost/@@/my-lib/included.js"...
+
+...but that is the only time it is inserted.
+
+    >>> browser.contents.count('src="http://localhost/@@/my-lib/included.js"')
+    1
+
 Future Work
 -----------
 

Deleted: zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/configure.zcml
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/configure.zcml	2007-03-19 16:18:53 UTC (rev 73346)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/configure.zcml	2007-03-19 18:37:00 UTC (rev 73347)
@@ -1,37 +0,0 @@
-<configure
-    xmlns="http://namespaces.zope.org/zope"
-    xmlns:browser="http://namespaces.zope.org/browser"
-    xmlns:zc="http://namespaces.zope.com/zc"
-    i18n_domain="zope"
-    package="zc.resourcelibrary.ftests"
-    >
-
-  <browser:page
-      for="zope.app.folder.interfaces.IFolder"
-      name="zc.resourcelibrary.test_template_1"
-      permission="zope.View"
-      template="test_template_1.pt"
-      />
-
-  <browser:page
-      for="zope.app.folder.interfaces.IFolder"
-      name="zc.resourcelibrary.test_template_2"
-      permission="zope.View"
-      template="test_template_2.pt"
-      />
-
-  <browser:page
-      for="zope.app.folder.interfaces.IFolder"
-      name="zc.resourcelibrary.test_template_3"
-      permission="zope.View"
-      template="test_template_3.pt"
-      />
-
-  <browser:page
-      for="zope.app.folder.interfaces.IFolder"
-      name="zc.resourcelibrary.test_template_4"
-      permission="zope.View"
-      template="test_template_4.pt"
-      />
-
-</configure>

Copied: zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/ftesting.zcml (from rev 73328, zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/configure.zcml)
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/configure.zcml	2007-03-18 19:37:55 UTC (rev 73328)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/ftesting.zcml	2007-03-19 18:37:00 UTC (rev 73347)
@@ -0,0 +1,73 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:browser="http://namespaces.zope.org/browser"
+    xmlns:zc="http://namespaces.zope.com/zc"
+    i18n_domain="zope"
+    package="zc.resourcelibrary.ftests"
+    >
+  <!-- set up enough of Zope to run the tests -->
+
+  <include package="zope.app.zcmlfiles" />
+  <include package="zope.app.authentication" />
+
+  <!-- principals -->
+
+  <unauthenticatedPrincipal
+      id="zope.anybody"
+      title="Unauthenticated User" />
+
+
+  <include package="zope.app.securitypolicy" file="meta.zcml"/>
+
+  <securityPolicy
+    component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
+
+  <role id="zope.Anonymous" title="Everybody"
+                 description="All users have this role implicitly" />
+
+  <grant permission="zope.View"
+                  role="zope.Anonymous" />
+
+  <!-- also need the resource library config -->
+
+  <include package="zc.resourcelibrary" file="meta.zcml"/>
+  <include package="zc.resourcelibrary"/>
+
+  <!-- make some pages to use in the tests -->
+
+  <browser:page
+      for="zope.app.folder.interfaces.IFolder"
+      name="zc.resourcelibrary.test_template_1"
+      permission="zope.View"
+      template="test_template_1.pt"
+      />
+
+  <browser:page
+      for="zope.app.folder.interfaces.IFolder"
+      name="zc.resourcelibrary.test_template_2"
+      permission="zope.View"
+      template="test_template_2.pt"
+      />
+
+  <browser:page
+      for="zope.app.folder.interfaces.IFolder"
+      name="zc.resourcelibrary.test_template_3"
+      permission="zope.View"
+      template="test_template_3.pt"
+      />
+
+  <browser:page
+      for="zope.app.folder.interfaces.IFolder"
+      name="zc.resourcelibrary.test_template_4"
+      permission="zope.View"
+      template="test_template_4.pt"
+      />
+
+  <browser:page
+      for="zope.app.folder.interfaces.IFolder"
+      name="zc.resourcelibrary.test_template_5"
+      permission="zope.View"
+      template="test_template_5.pt"
+      />
+
+</configure>

Deleted: zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/test_doc.py
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/test_doc.py	2007-03-19 16:18:53 UTC (rev 73346)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/test_doc.py	2007-03-19 18:37:00 UTC (rev 73347)
@@ -1,79 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""
-$Id: ntests.py 3330 2005-09-09 23:05:34Z jim $
-"""
-from StringIO import StringIO
-from zc.resourcelibrary import publication
-from zc.resourcelibrary import tal
-from zope.app.testing import functional
-from zope.configuration import xmlconfig
-from zope.pagetemplate import pagetemplate
-import doctest
-import unittest
-import zope.security.management
-
-#### testing framework ####
-
-def zcml(s, execute=True):
-    from zope.app.appsetup.appsetup import __config_context as context
-    try:
-        xmlconfig.string(s, context, execute=execute)
-    except:
-        context.end()
-        raise
-
-
-class TestPageTemplate(pagetemplate.PageTemplate):
-    def __init__(self, view):
-        self.view = view
-        super(TestPageTemplate, self).__init__()
-
-    def pt_getContext(self, *args, **kws):
-        context = super(TestPageTemplate, self).pt_getContext(*args, **kws)
-        context['view'] = self.view
-        return context
-
-
-def zpt(s, view=None):
-    request = publication.Request(body_instream=StringIO(''), environ={})
-    zope.security.management.newInteraction(request)
-    pt = TestPageTemplate(view)
-
-    # if the resource library expression hasn't been registered, do so
-    engine = pt.pt_getEngine()
-    type_name = 'resource_library'
-    if type_name not in engine.types:
-        engine.registerType(type_name, tal.ResourceLibraryExpression)
-
-    pt.write(s)
-    html = pt()
-    zope.security.management.endInteraction()
-
-    if html:
-        request.response.setResult(html)
-        return request.response.consumeBody()
-
-#### test setup ####
-
-def test_suite():
-    suite = functional.FunctionalDocFileSuite(
-        '../README.txt',
-        globs={'zcml': zcml, 'zpt': zpt},
-        optionflags=doctest.NORMALIZE_WHITESPACE+doctest.ELLIPSIS,
-        )
-    return suite
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')

Added: zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/test_template_5.pt
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/test_template_5.pt	2007-03-19 16:18:53 UTC (rev 73346)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/test_template_5.pt	2007-03-19 18:37:00 UTC (rev 73347)
@@ -0,0 +1,7 @@
+<html>
+  <head></head>
+  <body>
+    <tal:block replace="structure resource_library:my-lib"/>
+    <textarea><head>Not the real head.</head></textarea>
+  </body>
+</html>


Property changes on: zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/test_template_5.pt
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Copied: zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/tests.py (from rev 73328, zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/test_doc.py)
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/test_doc.py	2007-03-18 19:37:55 UTC (rev 73328)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/ftests/tests.py	2007-03-19 18:37:00 UTC (rev 73347)
@@ -0,0 +1,85 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id: ntests.py 3330 2005-09-09 23:05:34Z jim $
+"""
+from StringIO import StringIO
+from zc.resourcelibrary import publication
+from zc.resourcelibrary import tal
+from zope.app.testing import functional
+from zope.configuration import xmlconfig
+from zope.pagetemplate import pagetemplate
+import doctest
+import os
+import unittest
+import zope.security.management
+
+#### testing framework ####
+
+def zcml(s, execute=True):
+    from zope.app.appsetup.appsetup import __config_context as context
+    try:
+        xmlconfig.string(s, context, execute=execute)
+    except:
+        context.end()
+        raise
+
+
+class TestPageTemplate(pagetemplate.PageTemplate):
+    def __init__(self, view):
+        self.view = view
+        super(TestPageTemplate, self).__init__()
+
+    def pt_getContext(self, *args, **kws):
+        context = super(TestPageTemplate, self).pt_getContext(*args, **kws)
+        context['view'] = self.view
+        return context
+
+
+def zpt(s, view=None):
+    request = publication.Request(body_instream=StringIO(''), environ={})
+    zope.security.management.newInteraction(request)
+    pt = TestPageTemplate(view)
+
+    # if the resource library expression hasn't been registered, do so
+    engine = pt.pt_getEngine()
+    type_name = 'resource_library'
+    if type_name not in engine.types:
+        engine.registerType(type_name, tal.ResourceLibraryExpression)
+
+    pt.write(s)
+    html = pt()
+    zope.security.management.endInteraction()
+
+    if html:
+        request.response.setResult(html)
+        return request.response.consumeBody()
+
+#### test setup ####
+
+ResourceLibraryFunctionalLayer = functional.ZCMLLayer(
+    os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
+    __name__, 'ResourceLibraryFunctionalLayer')
+
+def test_suite():
+    suite = functional.FunctionalDocFileSuite(
+        '../README.txt',
+        globs={'zcml': zcml, 'zpt': zpt},
+        optionflags=doctest.NORMALIZE_WHITESPACE+doctest.ELLIPSIS,
+        )
+    suite.layer = ResourceLibraryFunctionalLayer
+    return suite
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')

Modified: zc.resourcelibrary/trunk/src/zc/resourcelibrary/publication.py
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/publication.py	2007-03-19 16:18:53 UTC (rev 73346)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/publication.py	2007-03-19 18:37:00 UTC (rev 73347)
@@ -45,7 +45,7 @@
         >>> response
         <zc.resourcelibrary.publication.Response object at ...>
         >>> response1 = response.retry()
-        
+
         The returned object is not the same.
         >>> response1 is response
         False
@@ -100,10 +100,12 @@
                         # shouldn't get here; zcml.py is supposed to check includes
                         raise RuntimeError('Resource library doesn\'t know how to '
                                            'include this file: "%s"' % file_name)
-    
+
             if html:
+                # This is a pretty low-rent way of adding things to the head.
+                # We should probably use a real HTML parser instead.
                 body = body.replace('<head>', '<head>\n    %s\n' %
-                                    '\n    '.join(html))
+                                    '\n    '.join(html), 1)
 
 
         return super(Response, self)._implicitResult(body)

Modified: zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests.py
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests.py	2007-03-19 16:18:53 UTC (rev 73346)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests.py	2007-03-19 18:37:00 UTC (rev 73347)
@@ -73,4 +73,3 @@
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')
-    

Modified: zc.resourcelibrary/trunk/src/zc/resourcelibrary/zc.resourcelibrary-ftesting.zcml
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/zc.resourcelibrary-ftesting.zcml	2007-03-19 16:18:53 UTC (rev 73346)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/zc.resourcelibrary-ftesting.zcml	2007-03-19 18:37:00 UTC (rev 73347)
@@ -1 +1 @@
-<include package="zc.resourcelibrary.ftests"/>
\ No newline at end of file
+<include package="zc.resourcelibrary.ftests" file="ftesting.zcml"/>



More information about the Checkins mailing list