[Checkins] SVN: zc.resourcelibrary/trunk/src/zc/resourcelibrary/ added tests for the content-type checks

Thomas Lotze tl at gocept.com
Tue Dec 4 17:33:01 EST 2007


Log message for revision 82131:
  added tests for the content-type checks

Changed:
  U   zc.resourcelibrary/trunk/src/zc/resourcelibrary/README.txt
  U   zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/tests.py

-=-
Modified: zc.resourcelibrary/trunk/src/zc/resourcelibrary/README.txt
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/README.txt	2007-12-04 22:05:22 UTC (rev 82130)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/README.txt	2007-12-04 22:33:01 UTC (rev 82131)
@@ -166,6 +166,47 @@
     >>> '/@@/my-lib/included.js' in zpt(page, view=View())
     True
 
+
+Content-type checking
+---------------------
+
+Resources should be referenced only from HTML and XML content, other content
+types should not be touched by the resource library:
+
+    >>> page = ('<html><head>'
+    ...         '<tal:block replace="resource_library:my-lib"/>'
+    ...         '</head><body></body></html>')
+
+    >>> '/@@/my-lib/included.js' in zpt(page, content_type='text/html')
+    True
+
+    >>> '/@@/my-lib/included.js' in zpt(page, content_type='text/xml')
+    True
+
+    >>> '/@@/my-lib/included.js' in zpt(page, content_type='text/none')
+    False
+
+This works also if the content type is spelled in a funny way and contains
+whitespace (leading whitespace and funny spelling of the major type will cause
+the publisher to complain so we don't try that here):
+
+    >>> '/@@/my-lib/included.js' in zpt(page, content_type='text/hTMl  ')
+    True
+
+    >>> '/@@/my-lib/included.js' in zpt(page, content_type='text/nOne ')
+    False
+
+Parameters to the content type can't fool the check either:
+
+    >>> '/@@/my-lib/included.js' in zpt(
+    ...     page, content_type='text/xml; charset=utf-8')
+    True
+
+    >>> '/@@/my-lib/included.js' in zpt(
+    ...     page, content_type='text/none; charset=utf-8')
+    False
+
+
 Dependencies
 ------------
 

Modified: zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/tests.py
===================================================================
--- zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/tests.py	2007-12-04 22:05:22 UTC (rev 82130)
+++ zc.resourcelibrary/trunk/src/zc/resourcelibrary/tests/tests.py	2007-12-04 22:33:01 UTC (rev 82131)
@@ -47,7 +47,7 @@
         return context
 
 
-def zpt(s, view=None):
+def zpt(s, view=None, content_type=None):
     request = publication.Request(body_instream=StringIO(''), environ={})
     zope.security.management.newInteraction(request)
     pt = TestPageTemplate(view)
@@ -62,6 +62,9 @@
     html = pt()
     zope.security.management.endInteraction()
 
+    if content_type:
+        request.response.setHeader("Content-Type", content_type)
+
     if html:
         request.response.setResult(html)
         return request.response.consumeBody()



More information about the Checkins mailing list