Back to index

plone3  3.1.7
test_urls.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2003-2005 Kupu Contributors. All rights reserved.
00004 #
00005 # This software is distributed under the terms of the Kupu
00006 # License. See LICENSE.txt for license text. For a list of Kupu
00007 # Contributors see CREDITS.txt.
00008 #
00009 ##############################################################################
00010 """Tests for the library tool
00011 
00012 $Id: test_resourcetypemapper.py 21075 2005-12-12 12:59:59Z duncan $
00013 """
00014 
00015 import os, sys
00016 if __name__ == '__main__':
00017     execfile(os.path.join(sys.path[0], 'framework.py'))
00018 
00019 
00020 import unittest
00021 from urlparse import urlsplit, urljoin, urlunsplit
00022 from Products.kupu.plone.html2captioned import makeUrlRelative
00023 
00024 class test_urls(unittest.TestCase):
00025     def test1(self):
00026         data = 'http://host/site/a'
00027         base = 'http://host/site/'
00028         expected = 'a', ''
00029         self.assertEquals(expected, makeUrlRelative(data, base))
00030 
00031     def testRelativeLinks1(self):
00032         data =  'http://localhost/cms/folder/jim#_ftnref1'
00033         expected = "jim", "#_ftnref1"
00034         base = 'http://localhost/cms/folder/fred'
00035 
00036         self.assertEquals(expected, makeUrlRelative(data, base))
00037 
00038     def testRelativeLinks2(self):
00039         data =  "http://localhost/cms/folder/otherdoc#key"
00040         expected = "otherdoc", "#key"
00041         base = 'http://localhost/cms/folder/'
00042 
00043         self.assertEquals(expected, makeUrlRelative(data, base))
00044 
00045     def testRelativeLinks3(self):
00046         data =  "http://localhost/cms/otherfolder/otherdoc"
00047         expected = "../otherfolder/otherdoc", ""
00048         base = 'http://localhost/cms/folder/'
00049 
00050         self.assertEquals(expected, makeUrlRelative(data, base))
00051 
00052     def testRelativeLinks4(self):
00053         data =  "http://localhost:9080/plone/Members/admin/art1"
00054         expected = "", ""
00055         base = 'http://localhost:9080/plone/Members/admin/art1'
00056 
00057         self.assertEquals(expected, makeUrlRelative(data, base))
00058 
00059     def testRelativeLinks5(self):
00060         data =  'http://localhost:9080/plone/Members/admin/art1/subitem'
00061         expected = "art1/subitem", ""
00062         base = 'http://localhost:9080/plone/Members/admin/art1'
00063 
00064         actual = makeUrlRelative(data, base)
00065         self.assertEquals(actual, expected)
00066 
00067     def testRelativeLinks6(self):
00068         data =  "http://localhost:9080/plone/Members/admin"
00069         expected = ".", ""
00070         base = 'http://localhost:9080/plone/Members/admin/art1'
00071 
00072         actual = makeUrlRelative(data, base)
00073         self.assertEquals(actual, expected)
00074 
00075     def testRelativeQuery(self):
00076         data =  "http://localhost:9080/plone/Members/admin/jim?x=5"
00077         expected = "jim", "?x=5"
00078         base = 'http://localhost:9080/plone/Members/admin/art1'
00079 
00080         actual = makeUrlRelative(data, base)
00081         self.assertEquals(actual, expected)
00082 
00083 if __name__ == '__main__':
00084     framework()
00085 else:
00086     # While framework.py provides its own test_suite()
00087     # method the testrunner utility does not.
00088     from unittest import TestSuite, makeSuite
00089     def test_suite():
00090         suite = TestSuite()
00091         suite.addTest(makeSuite(test_urls))
00092         return suite
00093