[CalendarServer-changes] [4766] CalendarServer/branches/release/CalendarServer-2.4-dev

source_changes at macosforge.org source_changes at macosforge.org
Wed Nov 18 11:20:05 PST 2009


Revision: 4766
          http://trac.macosforge.org/projects/calendarserver/changeset/4766
Author:   glyph at apple.com
Date:     2009-11-18 11:20:04 -0800 (Wed, 18 Nov 2009)
Log Message:
-----------
Pulled up r4711 r4712 r4716 from trunk.

Revision Links:
--------------
    http://trac.macosforge.org/projects/calendarserver/changeset/4711
    http://trac.macosforge.org/projects/calendarserver/changeset/4712
    http://trac.macosforge.org/projects/calendarserver/changeset/4716

Modified Paths:
--------------
    CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/extensions.py

Added Paths:
-----------
    CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/test/test_extensions.py

Property Changed:
----------------
    CalendarServer/branches/release/CalendarServer-2.4-dev/


Property changes on: CalendarServer/branches/release/CalendarServer-2.4-dev
___________________________________________________________________
Modified: svn:mergeinfo
   - /CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
/CalendarServer/trunk:4439-4440,4448,4450,4464,4473-4475,4717
   + /CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
/CalendarServer/trunk:4439-4440,4448,4450,4464,4473-4475,4711-4712,4716-4717

Modified: CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/extensions.py	2009-11-18 19:18:15 UTC (rev 4765)
+++ CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/extensions.py	2009-11-18 19:20:04 UTC (rev 4766)
@@ -1,3 +1,4 @@
+# -*- test-case-name: twistedcaldav.test.test_extensions -*-
 ##
 # Copyright (c) 2005-2009 Apple Inc. All rights reserved.
 #
@@ -969,15 +970,16 @@
                         value = cgi.escape(value)
 
                     output.append(
-                        """<tr class="%(even)s">"""
-                        """<td valign="top">%(name)s</td>"""
-                        """<td><pre>%(value)s</pre></td>"""
-                        """</tr>"""
-                        % {
-                            "even": even.state() and "even" or "odd",
-                            "name": name,
-                            "value": value,
-                        }
+                        str("""<tr class="%(even)s">"""
+                            """<td valign="top">%(name)s</td>"""
+                            """<td><pre>%(value)s</pre></td>"""
+                            """</tr>"""
+                            % {
+                                "even": even.state() and "even" or "odd",
+                                "name": name,
+                                "value": value,
+                            }
+                        )
                     )
 
                 output.append("</div>")

Copied: CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/test/test_extensions.py (from rev 4711, CalendarServer/trunk/twistedcaldav/test/test_extensions.py)
===================================================================
--- CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/test/test_extensions.py	                        (rev 0)
+++ CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/test/test_extensions.py	2009-11-18 19:20:04 UTC (rev 4766)
@@ -0,0 +1,184 @@
+# -*- coding: utf-8 -*-
+##
+# Copyright (c) 2009 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from xml.etree.cElementTree import XML# , tostring
+
+from twisted.trial.unittest import TestCase
+
+from twisted.internet.defer import inlineCallbacks
+from twisted.python.filepath import FilePath
+
+from twisted.web.microdom import parseString
+from twisted.web2.static import MetaDataMixin
+
+from twistedcaldav.extensions import DAVFile
+
+from twisted.web2.dav.element.base import WebDAVElement
+
+class UnicodeProperty(WebDAVElement):
+    """
+    An element with a unicode name.
+    """
+
+    name = u'unicode'
+
+    allowed_children = {}
+
+
+class StrProperty(WebDAVElement):
+    """
+    An element with a unicode name.
+    """
+
+    name = 'str'
+
+    allowed_children = {}
+
+
+
+class SimpleFakeRequest(object):
+    """
+    Emulate a very small portion of the web2 'Request' API, just enough to
+    render a L{DAVFile}.
+
+    @ivar path: the path portion of the URL being rendered.
+    """
+
+    def __init__(self, path):
+        self.path = path
+
+
+    def urlForResource(self, resource):
+        """
+        @return: this L{SimpleFakeRequest}'s 'path' attribute, since this
+            request can render only one thing.
+        """
+        return self.path
+
+
+
+def browserHTML2ETree(htmlString):
+    """
+    Loosely interpret an HTML string as XML and return an ElementTree object for it.
+    
+    We're not promising strict XML (in fact, we're specifically saying HTML) in
+    the content-type of certain responses, but it's much easier to work with
+    the ElementTree data structures present in Python 2.5+ for testing; so
+    we'll use Twisted's built-in facilities to sanitize the inputs before
+    making any structured assertions about them.
+
+    A more precise implementation would use
+    U{HTML5Lib<http://code.google.com/p/html5lib/wiki/UserDocumentation>}'s
+    etree bindings to do the parsing, as that is more directly 'what a browser
+    would do', but Twisted's built-in stuff is a good approximation and doesn't
+    drag in another dependency.
+
+    @param htmlString: a L{str}, encoded in UTF-8, representing a pile of
+        browser-friendly HTML tag soup.
+
+    @return: an object implementing the standard library ElementTree interface.
+    """
+    return XML(parseString(htmlString, beExtremelyLenient=True).toxml())
+
+
+
+nonASCIIFilename = u"アニメ.txt"
+
+
+class DirectoryListingTest(TestCase):
+    """
+    Test cases for HTML directory listing.
+    """
+
+    @inlineCallbacks
+    def doDirectoryTest(self, addedNames, modify=lambda x: None, expectedNames=None):
+        """
+        Do a test of a L{DAVFile} pointed at a directory, verifying that files
+        existing with the given names will be faithfully 'played back' via HTML
+        rendering.
+        """
+        if expectedNames is None:
+            expectedNames = addedNames
+        fp = FilePath(self.mktemp())
+        fp.createDirectory()
+        for sampleName in expectedNames:
+            fp.child(sampleName).touch()
+        df = DAVFile(fp)
+        modify(df)
+        responseXML = browserHTML2ETree(
+            (yield df.render(SimpleFakeRequest('/'))).stream.read()
+        )
+        names = set([element.text.encode("utf-8")
+                     for element in responseXML.findall(".//a")])
+        self.assertEquals(set(expectedNames), names)
+
+
+    def test_simpleList(self):
+        """
+        Rendering a L{DAVFile} that is backed by a directory will produce an
+        HTML document including links to its contents.
+        """
+        return self.doDirectoryTest([u'gamma.txt', u'beta.html', u'alpha.xml'])
+
+
+    def test_emptyList(self):
+        """
+        Listing a directory with no files in it will produce an index with no
+        links.
+        """
+        return self.doDirectoryTest([])
+
+
+    def test_nonASCIIList(self):
+        """
+        Listing a directory with a file in it that includes characters that
+        fall outside of the 'Basic Latin' and 'Latin-1 Supplement' unicode
+        blocks should result in those characters being rendered as links in the
+        index.
+        """
+        return self.doDirectoryTest([nonASCIIFilename.encode("utf-8")])
+
+
+    @inlineCallbacks
+    def test_nonASCIIListMixedChildren(self):
+        """
+        Listing a directory that contains unicode metadata and non-ASCII
+        characters in a filename should result in a listing that contains the
+        names of both entities.
+        """
+        unicodeChildName = "test"
+        def addUnicodeChild(davFile):
+            m = MetaDataMixin()
+            m.contentType = lambda: u'text/plain'
+            davFile.putChild(unicodeChildName, m)
+        yield self.doDirectoryTest([nonASCIIFilename], addUnicodeChild,
+                                   [nonASCIIFilename.encode("utf-8"), unicodeChildName])
+
+
+    @inlineCallbacks
+    def test_nonASCIIListMixedProperties(self):
+        """
+        Listing a directory that contains unicode metadata and non-ASCII
+        characters in a filename should result in a listing that contains the
+        names of both entities.
+        """
+        def addUnicodeChild(davFile):
+            davFile.writeProperty(UnicodeProperty(), None)
+            davFile.writeProperty(StrProperty(), None)
+        yield self.doDirectoryTest([nonASCIIFilename], addUnicodeChild,
+                                   [nonASCIIFilename.encode("utf-8")])
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20091118/d8ef801a/attachment-0001.html>


More information about the calendarserver-changes mailing list