Back to index

plone3  3.1.7
test_links.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 link checking and migration code"""
00011 
00012 import os, sys
00013 if __name__ == '__main__':
00014     execfile(os.path.join(sys.path[0], 'framework.py'))
00015 
00016 from kuputestcase import *
00017 from Products.kupu.plone.html2captioned import Migration
00018 
00019 class TestLinkCode(KupuTestCase):
00020     """Test the link checking code"""
00021 
00022     def test_relative(self):
00023         self.setup_content()
00024         migrator = Migration(self.kupu)
00025         portal = self.portal
00026         base = portal.folder.sub2.delta.absolute_url()
00027         path = '../alpha'
00028         expected = ('internal', portal.folder.alpha.UID(), path, '')
00029         self.assertEquals(expected, migrator.classifyLink(path, base))
00030 
00031     def test_external(self):
00032         self.setup_content()
00033         migrator = Migration(self.kupu)
00034         portal = self.portal
00035         base = portal.folder.sub2.delta.absolute_url()
00036         path = 'mailto:me@nowhere'
00037         expected = ('external', None, path, '')
00038         self.assertEquals(expected, migrator.classifyLink(path, base))
00039 
00040     def test_localexternal(self):
00041         self.setup_content()
00042         migrator = Migration(self.kupu)
00043         portal = self.portal
00044         base = portal.folder.sub2.delta.absolute_url()
00045         path = 'http://nohost/plone/folder/alpha'
00046         expected = ('internal', portal.folder.alpha.UID(), '../alpha', '')
00047         self.assertEquals(expected, migrator.classifyLink(path, base))
00048 
00049     def test_abspath(self):
00050         self.setup_content()
00051         migrator = Migration(self.kupu)
00052         portal = self.portal
00053         base = portal.folder.alpha.absolute_url()
00054         path = '/plone/folder/beta'
00055         expected = ('internal', portal.folder.beta.UID(), 'beta', '')
00056         self.assertEquals(expected, migrator.classifyLink(path, base))
00057 
00058     def test_anchor(self):
00059         self.setup_content()
00060         migrator = Migration(self.kupu)
00061         portal = self.portal
00062         base = portal.folder.alpha.absolute_url()
00063         path = '#fred'
00064         expected = ('internal', None, '', path)
00065         self.assertEquals(expected, migrator.classifyLink(path, base))
00066 
00067     def test_redundant(self):
00068         self.setup_content()
00069         migrator = Migration(self.kupu)
00070         portal = self.portal
00071         base = portal.folder.alpha.absolute_url()
00072         path = 'alpha#fred'
00073         expected = ('internal', None, '', '#fred')
00074         self.assertEquals(expected, migrator.classifyLink(path, base))
00075 
00076     def test_bad_portal_factory(self):
00077         # Some version of kupu wrongly inserted jumplinks to
00078         # portal_factory. Check these get cleaned.
00079         self.setup_content()
00080         migrator = Migration(self.kupu)
00081         portal = self.portal
00082         base = portal.folder.alpha.absolute_url()
00083         path = 'portal_factory#fred'
00084         expected = ('internal', None, '', '#fred')
00085         self.assertEquals(expected, migrator.classifyLink(path, base))
00086 
00087     def test_dot(self):
00088         self.setup_content()
00089         migrator = Migration(self.kupu)
00090         portal = self.portal
00091         base = portal.folder.alpha.absolute_url()
00092         path = '.'
00093         expected = ('internal', portal.folder.UID(), path, '')
00094         self.assertEquals(expected, migrator.classifyLink(path, base))
00095 
00096     def test_resolveuid(self):
00097         self.setup_content()
00098         migrator = Migration(self.kupu)
00099         portal = self.portal
00100         base = portal.folder.alpha.absolute_url()
00101         path = 'resolveuid/' + portal.folder.beta.UID()
00102         expected = ('internal', portal.folder.beta.UID(), 'beta', '')
00103         self.assertEquals(expected, migrator.classifyLink(path, base))
00104 
00105     def test_resolveuidEmbedded(self):
00106         self.setup_content()
00107         migrator = Migration(self.kupu)
00108         portal = self.portal
00109         base = portal.folder.alpha.absolute_url()
00110         path = 'wibble/resolveuid/' + portal.folder.beta.UID() + '#fragment'
00111         expected = ('internal', portal.folder.beta.UID(), 'beta', '#fragment')
00112         self.assertEquals(expected, migrator.classifyLink(path, base))
00113 
00114     def test_badlink(self):
00115         self.setup_content()
00116         migrator = Migration(self.kupu)
00117         portal = self.portal
00118         base = portal.folder.alpha.absolute_url()
00119         path = 'wibble'
00120         expected = ('bad', None, path, '')
00121         self.assertEquals(expected, migrator.classifyLink(path, base))
00122 
00123     def test_image(self):
00124         self.setup_content()
00125         migrator = Migration(self.kupu)
00126         migrator.initImageSizes()
00127         portal = self.portal
00128         base = portal.folder.alpha.absolute_url()
00129         path = 'gamma/image_thumb'
00130         expected = ('internal', portal.folder.gamma.UID(), 'gamma', '/image_thumb')
00131         self.assertEquals(expected, migrator.classifyLink(path, base))
00132 
00133     def test_image2(self):
00134         self.setup_content()
00135         migrator = Migration(self.kupu)
00136         portal = self.portal
00137         base = portal.folder.alpha.absolute_url()
00138         path = 'resolveuid/'+portal.folder.gamma.UID()+'/image_icon'
00139         expected = ('internal', portal.folder.gamma.UID(), 'gamma', '/image_icon')
00140         self.assertEquals(expected, migrator.classifyLink(path, base))
00141 
00142         
00143 if __name__ == '__main__':
00144     framework()
00145 else:
00146     # While framework.py provides its own test_suite()
00147     # method the testrunner utility does not.
00148     from unittest import TestSuite, makeSuite
00149     def test_suite():
00150         suite = TestSuite()
00151         suite.addTest(makeSuite(TestLinkCode))
00152         return suite