~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to twisted/web2/dav/test/test_util.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-17 14:52:35 UTC
  • mfrom: (1.1.5 upstream) (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20070117145235-btmig6qfmqfen0om
Tags: 2.5.0-0ubuntu1
New upstream version, compatible with python2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##
 
2
# Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
 
3
#
 
4
# Permission is hereby granted, free of charge, to any person obtaining a copy
 
5
# of this software and associated documentation files (the "Software"), to deal
 
6
# in the Software without restriction, including without limitation the rights
 
7
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
8
# copies of the Software, and to permit persons to whom the Software is
 
9
# furnished to do so, subject to the following conditions:
 
10
 
11
# The above copyright notice and this permission notice shall be included in all
 
12
# copies or substantial portions of the Software.
 
13
 
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
15
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
16
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
17
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
18
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
20
# SOFTWARE.
 
21
#
 
22
# DRI: Wilfredo Sanchez, wsanchez@apple.com
 
23
##
 
24
 
 
25
from twisted.trial import unittest
 
26
from twisted.web2.dav import util
 
27
 
 
28
class Utilities(unittest.TestCase):
 
29
    """
 
30
    Utilities.
 
31
    """
 
32
    def test_normalizeURL(self):
 
33
        """
 
34
        normalizeURL()
 
35
        """
 
36
        self.assertEquals(util.normalizeURL("http://server//foo"), "http://server/foo")
 
37
        self.assertEquals(util.normalizeURL("http://server/foo/.."), "http://server/")
 
38
        self.assertEquals(util.normalizeURL("/foo/bar/..//"), "/foo")
 
39
        self.assertEquals(util.normalizeURL("/foo/bar/.//"), "/foo/bar")
 
40
        self.assertEquals(util.normalizeURL("//foo///bar/../baz"), "/foo/baz")
 
41
        self.assertEquals(util.normalizeURL("//foo///bar/./baz"), "/foo/bar/baz")
 
42
        self.assertEquals(util.normalizeURL("///../"), "/")
 
43
        self.assertEquals(util.normalizeURL("/.."), "/")
 
44
 
 
45
    def test_joinURL(self):
 
46
        """
 
47
        joinURL()
 
48
        """
 
49
        self.assertEquals(util.joinURL("http://server/foo/"), "http://server/foo/")
 
50
        self.assertEquals(util.joinURL("http://server/foo", "/bar"), "http://server/foo/bar")
 
51
        self.assertEquals(util.joinURL("http://server/foo", "bar"), "http://server/foo/bar")
 
52
        self.assertEquals(util.joinURL("http://server/foo/", "/bar"), "http://server/foo/bar")
 
53
        self.assertEquals(util.joinURL("http://server/foo/", "/bar/.."), "http://server/foo")
 
54
        self.assertEquals(util.joinURL("http://server/foo/", "/bar/."), "http://server/foo/bar")
 
55
        self.assertEquals(util.joinURL("http://server/foo/", "/bar/../"), "http://server/foo/")
 
56
        self.assertEquals(util.joinURL("http://server/foo/", "/bar/./"), "http://server/foo/bar/")
 
57
        self.assertEquals(util.joinURL("http://server/foo/../", "/bar"), "http://server/bar")
 
58
        self.assertEquals(util.joinURL("/foo/"), "/foo/")
 
59
        self.assertEquals(util.joinURL("/foo", "/bar"), "/foo/bar")
 
60
        self.assertEquals(util.joinURL("/foo", "bar"), "/foo/bar")
 
61
        self.assertEquals(util.joinURL("/foo/", "/bar"), "/foo/bar")
 
62
        self.assertEquals(util.joinURL("/foo/", "/bar/.."), "/foo")
 
63
        self.assertEquals(util.joinURL("/foo/", "/bar/."), "/foo/bar")
 
64
        self.assertEquals(util.joinURL("/foo/", "/bar/../"), "/foo/")
 
65
        self.assertEquals(util.joinURL("/foo/", "/bar/./"), "/foo/bar/")
 
66
        self.assertEquals(util.joinURL("/foo/../", "/bar"), "/bar")
 
67
        self.assertEquals(util.joinURL("/foo", "/../"), "/")
 
68
        self.assertEquals(util.joinURL("/foo", "/./"), "/foo/")
 
69
 
 
70
    def test_parentForURL(self):
 
71
        """
 
72
        parentForURL()
 
73
        """
 
74
        self.assertEquals(util.parentForURL("http://server/"), None)
 
75
        self.assertEquals(util.parentForURL("http://server//"), None)
 
76
        self.assertEquals(util.parentForURL("http://server/foo/.."), None)
 
77
        self.assertEquals(util.parentForURL("http://server/foo/../"), None)
 
78
        self.assertEquals(util.parentForURL("http://server/foo/."), "http://server/")
 
79
        self.assertEquals(util.parentForURL("http://server/foo/./"), "http://server/")
 
80
        self.assertEquals(util.parentForURL("http://server/foo"), "http://server/")
 
81
        self.assertEquals(util.parentForURL("http://server//foo"), "http://server/")
 
82
        self.assertEquals(util.parentForURL("http://server/foo/bar/.."), "http://server/")
 
83
        self.assertEquals(util.parentForURL("http://server/foo/bar/."), "http://server/foo/")
 
84
        self.assertEquals(util.parentForURL("http://server/foo/bar"), "http://server/foo/")
 
85
        self.assertEquals(util.parentForURL("http://server/foo/bar/"), "http://server/foo/")
 
86
        self.assertEquals(util.parentForURL("/"), None)
 
87
        self.assertEquals(util.parentForURL("/foo/.."), None)
 
88
        self.assertEquals(util.parentForURL("/foo/../"), None)
 
89
        self.assertEquals(util.parentForURL("/foo/."), "/")
 
90
        self.assertEquals(util.parentForURL("/foo/./"), "/")
 
91
        self.assertEquals(util.parentForURL("/foo"), "/")
 
92
        self.assertEquals(util.parentForURL("/foo"), "/")
 
93
        self.assertEquals(util.parentForURL("/foo/bar/.."), "/")
 
94
        self.assertEquals(util.parentForURL("/foo/bar/."), "/foo/")
 
95
        self.assertEquals(util.parentForURL("/foo/bar"), "/foo/")
 
96
        self.assertEquals(util.parentForURL("/foo/bar/"), "/foo/")