[kupu-checkins] r49164 - in kupu/trunk/kupu/plone: . tests tests/input tests/output

duncan at codespeak.net duncan at codespeak.net
Mon Nov 26 17:17:55 CET 2007


Author: duncan
Date: Mon Nov 26 17:17:52 2007
New Revision: 49164

Added:
   kupu/trunk/kupu/plone/tests/image.jpg   (contents, props changed)
   kupu/trunk/kupu/plone/tests/kuputestcase.py   (contents, props changed)
Modified:
   kupu/trunk/kupu/plone/html2captioned.py
   kupu/trunk/kupu/plone/tests/framework.py
   kupu/trunk/kupu/plone/tests/input/linked.in
   kupu/trunk/kupu/plone/tests/input/simple.in
   kupu/trunk/kupu/plone/tests/output/linked.out
   kupu/trunk/kupu/plone/tests/output/notcaptioned.out
   kupu/trunk/kupu/plone/tests/output/notquoted.out
   kupu/trunk/kupu/plone/tests/output/simple.out
   kupu/trunk/kupu/plone/tests/runme.cmd
   kupu/trunk/kupu/plone/tests/test_browserSupportsKupu.py
   kupu/trunk/kupu/plone/tests/test_html2captioned.py
   kupu/trunk/kupu/plone/tests/test_links.py
Log:
Fix transform so to preserve links around images.
Fix unit tests: use a real image instead of a dummy one & transform tests use a real portal instead of a dummy one.

Modified: kupu/trunk/kupu/plone/html2captioned.py
==============================================================================
--- kupu/trunk/kupu/plone/html2captioned.py	(original)
+++ kupu/trunk/kupu/plone/html2captioned.py	Mon Nov 26 17:17:52 2007
@@ -26,9 +26,9 @@
 # enclosed in a simple <p> or <div>. In the latter case we strip out
 # the enclosing tag since we are going to insert our own.
 PATIMG = '\\<img[^>]+class\s*=[^=>]*captioned[^>]+\\>'
-PATA = '(?:\\<a[^>]*\\>'+PATIMG+'\\</a\\>)' + '|' + PATIMG
-PAT0 = '('+PATA+')'
-PAT1 = '<(?:p|div)[^>]*>'+PAT0 + '</(?:p|div)>' + '|' + PAT0
+PATA = '(?:(?P<atag0>\\<a[^>]*\\>)'+PATIMG+'\\</a\\>)' + '|' + PATIMG
+PAT0 = '(?P<pat0>'+PATA+')'
+PAT1 = '<(?:p|div)[^>]*>'+PAT0 + '</(?:p|div)>' + '|' + PAT0.replace('0>','1>')
 IMAGE_PATTERN = re.compile(PAT1, re.IGNORECASE)
 
 # Regex to match stupid IE attributes. In IE generated HTML an
@@ -122,8 +122,9 @@
 
         if context and at_tool:        
             def replaceImage(match):
-                tag = match.group(1) or match.group(2)
+                tag = match.group('pat0') or match.group('pat1')
                 attrs = ATTR_PATTERN.match(tag)
+                atag = match.group('atag0') or match.group('atag1')
                 src = attrs.group('src')
                 subtarget = None
                 m = SRC_TAIL.match(tag, attrs.end('src'))
@@ -142,7 +143,7 @@
                         d['caption'] = newline_to_br(html_quote(target.Description()))
                         d['image'] = d['fullimage'] = target
                         d['tag'] = None
-                        d['isfullsize'] = False
+                        d['isfullsize'] = True
                         d['width'] = target.width
                         if srctail:
                             if isinstance(srctail, unicode):
@@ -166,6 +167,10 @@
                             d['isfullsize'] = subtarget.width == target.width and subtarget.height == target.height
                             d['width'] = subtarget.width
 
+                        if atag: # Must preserve original link, don't overwrite with a link to the image
+                            d['isfullsize'] = True
+                            d['tag'] = "%s%s</a>" % (atag, d['tag'])
+
                         return template(**d)
                 return match.group(0) # No change
 

Modified: kupu/trunk/kupu/plone/tests/framework.py
==============================================================================
--- kupu/trunk/kupu/plone/tests/framework.py	(original)
+++ kupu/trunk/kupu/plone/tests/framework.py	Mon Nov 26 17:17:52 2007
@@ -105,4 +105,12 @@
 print 'INSTANCE_HOME: %s' % os.environ.get('INSTANCE_HOME', 'Not set')
 sys.stdout.flush()
 from Testing import ZopeTestCase
-ZopeTestCase.installProduct('kupu')
+from Testing import ZopeTestCase
+DEPS = ('MimetypesRegistry', 'PortalTransforms', 'Archetypes', 'ATContentTypes', 'kupu')
+try:
+    import Products.TextIndexNG2
+    DEPS = DEPS + ('TextIndexNG2',)
+except ImportError:
+    pass
+for product in DEPS:
+    ZopeTestCase.installProduct(product, 1)

Added: kupu/trunk/kupu/plone/tests/image.jpg
==============================================================================
Binary file. No diff available.

Modified: kupu/trunk/kupu/plone/tests/input/linked.in
==============================================================================
--- kupu/trunk/kupu/plone/tests/input/linked.in	(original)
+++ kupu/trunk/kupu/plone/tests/input/linked.in	Mon Nov 26 17:17:52 2007
@@ -1,2 +1,2 @@
 <div>Simple text containing an embedded image</div>
-<p><a href="xyzzy" class="link"><img class="image-left captioned" height="144" alt="picture alt text" src="resolveuid/104ede98d4c7c8eaeaa3b984f7395979" width="120"/></a></p>
+<p><a href="xyzzy" class="link"><img class="image-left captioned" alt="picture alt text" src="resolveuid/104ede98d4c7c8eaeaa3b984f7395979"/></a></p>

Modified: kupu/trunk/kupu/plone/tests/input/simple.in
==============================================================================
--- kupu/trunk/kupu/plone/tests/input/simple.in	(original)
+++ kupu/trunk/kupu/plone/tests/input/simple.in	Mon Nov 26 17:17:52 2007
@@ -1,5 +1,4 @@
 <div>Simple text containing an embedded image</div>
+<p><img class="image-left captioned" alt="picture alt text" src="resolveuid/104ede98d4c7c8eaeaa3b984f7395979"/></p>
+<p><img class="image-left captioned" alt="picture alt text" src="resolveuid/104ede98d4c7c8eaeaa3b984f7395979/image_thumb"/></p>
 <p><img class="image-left captioned" height="144" alt="picture alt text" src="resolveuid/104ede98d4c7c8eaeaa3b984f7395979" width="120"/></p>
-<p><img class="image-left captioned" height="144" alt="picture alt text" src="resolveuid/104ede98d4c7c8eaeaa3b984f7395979/image_thumb"/></p>
-<p><img class="image-left captioned"
- height="144" alt="picture alt text" src="resolveuid/104ede98d4c7c8eaeaa3b984f7395979"/></p>

Added: kupu/trunk/kupu/plone/tests/kuputestcase.py
==============================================================================
--- (empty file)
+++ kupu/trunk/kupu/plone/tests/kuputestcase.py	Mon Nov 26 17:17:52 2007
@@ -0,0 +1,124 @@
+##############################################################################
+#
+# Copyright (c) 2003-2005 Kupu Contributors. All rights reserved.
+#
+# This software is distributed under the terms of the Kupu
+# License. See LICENSE.txt for license text. For a list of Kupu
+# Contributors see CREDITS.txt.
+#
+##############################################################################
+"""Base test class for kupu tests"""
+
+import os, sys
+if __name__ == '__main__':
+    execfile(os.path.join(sys.path[0], 'framework.py'))
+
+from Products.PloneTestCase import PloneTestCase
+from Products.PloneTestCase.ptc import portal_owner
+
+PloneTestCase.setupPloneSite(products=['ATContentTypes', 'kupu'])
+
+from AccessControl.SecurityManagement import newSecurityManager
+try:
+    from Products.ATContentTypes.lib import constraintypes
+except:
+    constraintypes = None
+
+from os.path import join, abspath, dirname
+PREFIX = abspath(dirname(__file__))
+
+RESOURCES = dict(
+    linkable = ('Document', 'Image', 'File', 'Folder'),
+    mediaobject = ('Image',),
+    collection = ('Folder',),
+    containsanchors = ('Document',),
+    )
+
+# Type names vary according to the version of Plone and/or
+# ATContentTypes. Map the new names to the old ones here, and
+# turn it into an identity mapping later if we can.
+TypeMapping = {
+    'Document': 'ATDocument',
+    'Image': 'ATImage',
+    'Link': 'ATLink',
+    'Folder': 'ATFolder',
+    'File': 'ATFile',
+    'News Item': 'ATNewsItem',
+    'Event': 'ATEvent',
+}
+def MapType(typename):
+    return TypeMapping[typename]
+
+class KupuTestCase(PloneTestCase.PloneTestCase):
+    """Base class for Kupu tests"""
+
+    def afterSetUp(self):
+        portal = self.portal
+        self.setRoles(['Manager',])
+        self.kupu = portal.kupu_library_tool
+        self.kupu.configure_kupu(captioning=True, linkbyuid=True)
+        typestool = self.portal.portal_types
+        if not hasattr(typestool, 'ATDocument'):
+            # Use the type names without the AT prefix
+            for k in TypeMapping:
+                TypeMapping[k] = k
+
+    def loginPortalOwner(self):
+        '''Use if you need to manipulate the portal itself.'''
+        uf = self.app.acl_users
+        user = uf.getUserById(portal_owner).__of__(uf)
+        newSecurityManager(None, user)
+
+    def create(self, id, metatype='ATDocument', folder=None, **kwds):
+        '''Create an object in the cms portal'''
+        if folder is None:
+            folder = self.portal
+
+        folder.invokeFactory(MapType(metatype), id)
+        obj = getattr(folder, id)
+
+        if metatype=='Folder' and constraintypes:
+            obj.setConstrainTypesMode(constraintypes.DISABLED)
+
+        if metatype=='Document':
+            obj.setTitle('Simple document')
+            obj.setText('Sample document text')
+            for k, v in kwds.items():
+                field = obj.getField(k)
+                mutator = field.getMutator(obj)(v)
+
+            obj.reindexObject()
+
+        assert obj is not None
+        return obj
+
+    def setup_content(self):
+        self.setRoles(['Manager',])
+        self.loginPortalOwner()
+        f = self.create('folder', 'Folder')
+
+        for id in ('alpha', 'beta'):
+            self.create(id, 'Document', f, subject=['aspidistra'])
+        self.create('gamma', 'Image', f)
+        gamma = f.gamma
+        gamma.setImage(open('image.jpg','rb').read())
+        gamma.setTitle('Kupu Test Image')
+        gamma.setDescription('Test image caption')
+        # The image needs a fixed uid for the transform tests.
+        f.gamma._setUID('104ede98d4c7c8eaeaa3b984f7395979')
+        f.reindexObject()
+
+        sub1 = self.create('sub1', 'Folder', f)
+        sub1.setSubject(['aspidistra'])
+        sub1.reindexObject()
+        sub2 = self.create('sub2', 'Folder', f)
+        self.create('delta', 'Folder', sub2)
+
+        portal = self.portal
+        tool = self.portal.kupu_library_tool
+        types = tool.zmi_get_resourcetypes()
+        #tool.deleteResource([ t.name for t in types])
+        for k,v in RESOURCES.items():
+            tool.addResourceType(k, [MapType(t) for t in v])
+
+__all__ = ['KupuTestCase', 'PloneTestCase', 'portal_owner']

Modified: kupu/trunk/kupu/plone/tests/output/linked.out
==============================================================================
--- kupu/trunk/kupu/plone/tests/output/linked.out	(original)
+++ kupu/trunk/kupu/plone/tests/output/linked.out	Mon Nov 26 17:17:52 2007
@@ -1,9 +1,12 @@
 <div>Simple text containing an embedded image</div>
 <dl class="image-left captioned">
  <dt>
-  <a href="xyzzy" class="link"><img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" width="120" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/></a>
+  <a href="xyzzy" class="link">
+    <img src="http://nohost/plone/folder/gamma/image" alt="Kupu Test Image" title="Kupu Test Image"
+    height="331" width="500" />
+  </a>
  </dt>
- <dd class="image-caption" style="width:120px">
+ <dd class="image-caption" style="width:500px">
   Test image caption
  </dd>
-</div>
+</dl>

Modified: kupu/trunk/kupu/plone/tests/output/notcaptioned.out
==============================================================================
--- kupu/trunk/kupu/plone/tests/output/notcaptioned.out	(original)
+++ kupu/trunk/kupu/plone/tests/output/notcaptioned.out	Mon Nov 26 17:17:52 2007
@@ -1,2 +1,2 @@
 <div>Simple text containing an embedded image</div>
-<p><img class=image-left height="144" alt="picture alt text" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" width="120"/></p>
+<p><img class=image-left height="144" alt="picture alt text" src="/plone/folder/gamma" width="120"/></p>

Modified: kupu/trunk/kupu/plone/tests/output/notquoted.out
==============================================================================
--- kupu/trunk/kupu/plone/tests/output/notquoted.out	(original)
+++ kupu/trunk/kupu/plone/tests/output/notquoted.out	Mon Nov 26 17:17:52 2007
@@ -1,13 +1,17 @@
 <div>IE doesn't always quote attributes</div>
 <dl class="image-left captioned">
   <dt>
-    <img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" width="120" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
+    <img src="http://nohost/plone/folder/gamma/image"
+        alt="Kupu Test Image" title="Kupu Test Image"
+        height="331" width="500" />
   </dt>
-  <dd class="image-caption" style="width:120px">Test image caption</dd>
+  <dd class="image-caption" style="width:500px">Test image caption</dd>
 </dl>
 <dl class="captioned">
   <dt>
-    <img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" width="120" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
+    <img src="http://nohost/plone/folder/gamma/image"
+        alt="Kupu Test Image" title="Kupu Test Image"
+        height="331" width="500" />
   </dt>
-  <dd class="image-caption" style="width:120px">Test image caption</dd>
+  <dd class="image-caption" style="width:500px">Test image caption</dd>
 </dl>

Modified: kupu/trunk/kupu/plone/tests/output/simple.out
==============================================================================
--- kupu/trunk/kupu/plone/tests/output/simple.out	(original)
+++ kupu/trunk/kupu/plone/tests/output/simple.out	Mon Nov 26 17:17:52 2007
@@ -1,16 +1,27 @@
 <div>Simple text containing an embedded image</div>
 <dl class="image-left captioned">
-  <dt><img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" width="120" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
+  <dt>
+     <img src="http://nohost/plone/folder/gamma/image"
+          alt="Kupu Test Image" title="Kupu Test Image"
+          height="331" width="500" />
   </dt>
-  <dd class="image-caption" style="width:120px">Test image caption</dd>
+  <dd class="image-caption" style="width:500px">Test image caption</dd>
 </dl>
 <dl class="image-left captioned">
-  <dt><img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]/image_thumb" width="20" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
+  <dt>
+    <a rel="lightbox" href="/plone/folder/gamma">
+      <img src="http://nohost/plone/folder/gamma/image/image_thumb"
+           alt="Kupu Test Image" title="Kupu Test Image" height="84"
+           width="128" />
+    </a>
   </dt>
-  <dd class="image-caption" style="width:20px">Test image caption</dd>
+  <dd class="image-caption" style="width:128px">Test image caption</dd>
 </dl>
 <dl class="image-left captioned">
-  <dt><img height="144" src="[url for 104ede98d4c7c8eaeaa3b984f7395979]" width="600" alt="image 104ede98d4c7c8eaeaa3b984f7395979"/>
+  <dt>
+     <img src="http://nohost/plone/folder/gamma/image"
+          alt="Kupu Test Image" title="Kupu Test Image" height="331"
+          width="500" />
   </dt>
-  <dd class="image-caption" style="width:600px">Test image caption</dd>
+  <dd class="image-caption" style="width:500px">Test image caption</dd>
 </dl>

Modified: kupu/trunk/kupu/plone/tests/runme.cmd
==============================================================================
--- kupu/trunk/kupu/plone/tests/runme.cmd	(original)
+++ kupu/trunk/kupu/plone/tests/runme.cmd	Mon Nov 26 17:17:52 2007
@@ -10,6 +10,7 @@
 @set PYTHON=C:\Plone20\Zope\bin\python.exe
 rem "%PYTHON%" %~D0%~P0test_browserSupportsKupu.py %2
 rem "%PYTHON%" %~D0%~P0test_librarymanager.py
+rem "%PYTHON%" %~D0%~P0test_links.py
 rem "%PYTHON%" %~D0%~P0test_html2captioned.py
 rem "%PYTHON%" %~D0%~P0test_resourcetypemapper.py
 rem "%PYTHON%" %~D0%~P0test_urls.py

Modified: kupu/trunk/kupu/plone/tests/test_browserSupportsKupu.py
==============================================================================
--- kupu/trunk/kupu/plone/tests/test_browserSupportsKupu.py	(original)
+++ kupu/trunk/kupu/plone/tests/test_browserSupportsKupu.py	Mon Nov 26 17:17:52 2007
@@ -17,16 +17,6 @@
 if __name__ == '__main__':
     execfile(os.path.join(sys.path[0], 'framework.py'))
 
-from Testing import ZopeTestCase
-DEPS = ('MimetypesRegistry', 'PortalTransforms', 'Archetypes', 'ATContentTypes')
-try:
-    import Products.TextIndexNG2
-    DEPS = DEPS + ('TextIndexNG2',)
-except ImportError:
-    pass
-
-for product in DEPS:
-    ZopeTestCase.installProduct(product, 1)
 from Products.PloneTestCase import PloneTestCase
 
 PloneTestCase.setupPloneSite(products=['ATContentTypes', 'kupu'])

Modified: kupu/trunk/kupu/plone/tests/test_html2captioned.py
==============================================================================
--- kupu/trunk/kupu/plone/tests/test_html2captioned.py	(original)
+++ kupu/trunk/kupu/plone/tests/test_html2captioned.py	Mon Nov 26 17:17:52 2007
@@ -2,8 +2,9 @@
 if __name__ == '__main__':
     execfile(os.path.join(sys.path[0], 'framework.py'))
 
+from kuputestcase import *
+
 from unittest  import TestCase, TestSuite, main, makeSuite
-from Products.CMFPlone.tests import PloneTestCase
 from os.path import join, abspath, dirname
 
 from Products.PortalTransforms.tests.test_transforms import *
@@ -27,92 +28,7 @@
 ('Products.kupu.plone.html2captioned', "linked.in", "linked.out", normalize_html, 0),
     )
 
-class MockImage:
-    def __init__(self, uid, description):
-        self.uid, self.description = uid, description
-        if not uid.startswith('SUB:'):
-            self.image_thumb = MockSubImage(self)
-
-    def Title(self):
-        return 'image '+self.uid
-    def Description(self):
-        return self.description
-    def absolute_url(self):
-        return '[url for %s]' % self.uid
-    def absolute_url_path(self):
-        return '[url for %s]' % self.uid
-    def getWidth(self):
-        return 600
-    def tag(self, height="", width="", **kw):
-        src = self.absolute_url_path()
-        alt = self.Title()
-        if not width:
-            width = self.getWidth()
-        return '<img height="%s" src="%s" width="%s" alt="%s"/>' % (height, src, width, alt)
-
-class MockSubImage(MockImage):
-    def __init__(self, parent):
-        self.uid = parent.uid
-        self.description = parent.description
-
-    def getWidth(self):
-        return 20
-    def absolute_url_path(self):
-        return '[url for %s]' % self.uid+'/image_thumb'
-
-class MockCatalogTool:
-    def lookupObject(self, uid):
-        dummydata = {
-            '104ede98d4c7c8eaeaa3b984f7395979': 'Test image caption'
-        }
-        if uid not in dummydata:
-            return None
-        image = MockImage(uid, dummydata[uid])
-        return image
-
-class MockArchetypeTool:
-    reference_catalog = MockCatalogTool()
-
-def mockPageTemplate(self, **kw):
-    """Acquisition isn't set up correctly for us to use a real PageTemplateFile,
-    so for the test we just use string formatting.
-    """
-    caption = kw.get('caption', '!caption!')
-    image = kw.get('image', None)
-    fullimage = kw.get('fullimage', None)
-    Class=kw['class']
-    width = kw['width']
-    owidth = fullimage.getWidth()
-    if width is None:
-        kw['width'] = width = image.getWidth()
-    href = fullimage.absolute_url_path()
-    tag = image.tag(**kw)
-
-    #if width==owidth:
-    TEMPLATE = '''<dl class="%(Class)s">
-    <dt>%(tag)s</dt>
-    <dd class="image-caption" style="width:%(width)spx">%(caption)s</dd>
-    </dl>'''
-    #else:
-    #    TEMPLATE = '''<dl class="%(Class)s">
-    #    <dt><a rel="lightbox" href="%(href)s">%(tag)s</a></dt>
-    #    <dd class="image-caption" style="width:%(width)spx">%(caption)s</dd>
-    #    </dl>'''
-        
-    return TEMPLATE % dict(
-        caption=caption, Class=Class, href=href, width=width, tag=tag)
-
-class MockPortal:
-    # Mock portal class: just enough to let me think I can lookup a
-    # Description for an image from its UID.
-    archetype_tool = MockArchetypeTool()
-
-    # Also now needs access to the captioning template
-    kupu_captioned_image = mockPageTemplate
-
-class TransformTest(TestCase):
-    portal = MockPortal()
-    
+class TransformTest(KupuTestCase):
     def do_convert(self, filename=None):
         if filename is None and exists(self.output + '.nofilename'):
             output = self.output + '.nofilename'
@@ -136,22 +52,25 @@
             output.close()
             self.assert_(0)
         expected = output.read()
+        raw_got, raw_expected = got, expected
         if self.normalize is not None:
             expected = self.normalize(expected)
             got = self.normalize(got)
         output.close()
 
         self.assertEquals(got, expected,
-                          '[%s]\n\n!=\n\n[%s]\n\nIN %s(%s)' % (
+                          'Got:\n[%s]\n\n!=\n\nExpected:\n[%s]\n\nIN %s(%s)' % (
             got, expected, self.transform.name(), self.input))
         self.assertEquals(self.subobjects, len(res_data.getSubObjects()),
-                          '%s\n\n!=\n\n%s\n\nIN %s(%s)' % (
+                          'Subobjects:\n%s\n\n!=\n\nLength: %s\n\nIN %s(%s)' % (
             self.subobjects, len(res_data.getSubObjects()), self.transform.name(), self.input))
 
     def testSame(self):
+        self.setup_content()
         self.do_convert(filename=self.input)
 
     def testSameNoFilename(self):
+        self.setup_content()
         self.do_convert()
 
     def __repr__(self):

Modified: kupu/trunk/kupu/plone/tests/test_links.py
==============================================================================
--- kupu/trunk/kupu/plone/tests/test_links.py	(original)
+++ kupu/trunk/kupu/plone/tests/test_links.py	Mon Nov 26 17:17:52 2007
@@ -13,103 +13,12 @@
 if __name__ == '__main__':
     execfile(os.path.join(sys.path[0], 'framework.py'))
 
-from Products.PloneTestCase import PloneTestCase
-from Products.PloneTestCase.ptc import portal_owner
-
-PloneTestCase.setupPloneSite(products=['kupu'])
-
-from AccessControl.SecurityManagement import newSecurityManager
-try:
-    from Products.ATContentTypes.lib import constraintypes
-except:
-    constraintypes = None
-
+from kuputestcase import *
 from Products.kupu.plone.html2captioned import Migration
 
-RESOURCES = dict(
-    linkable = ('Document', 'Image', 'File', 'Folder'),
-    mediaobject = ('Image',),
-    collection = ('Folder',),
-    containsanchors = ('Document',),
-    )
-
-# Type names vary according to the version of Plone and/or
-# ATContentTypes. Map the new names to the old ones here, and
-# turn it into an identity mapping later if we can.
-TypeMapping = {
-    'Document': 'ATDocument',
-    'Image': 'ATImage',
-    'Link': 'ATLink',
-    'Folder': 'ATFolder',
-    'File': 'ATFile',
-    'News Item': 'ATNewsItem',
-    'Event': 'ATEvent',
-}
-def MapType(typename):
-    return TypeMapping[typename]
-
-class TestLinkCode(PloneTestCase.PloneTestCase):
+class TestLinkCode(KupuTestCase):
     """Test the link checking code"""
 
-    def afterSetUp(self):
-        portal = self.portal
-        self.setRoles(['Manager',])
-        self.kupu = portal.kupu_library_tool
-        typestool = self.portal.portal_types
-        if not hasattr(typestool, 'ATDocument'):
-            # Use the type names without the AT prefix
-            for k in TypeMapping:
-                TypeMapping[k] = k
-
-    def loginPortalOwner(self):
-        '''Use if you need to manipulate the portal itself.'''
-        uf = self.app.acl_users
-        user = uf.getUserById(portal_owner).__of__(uf)
-        newSecurityManager(None, user)
-
-    def create(self, id, metatype='ATDocument', folder=None, **kwds):
-        '''Create an object in the cms portal'''
-        if folder is None:
-            folder = self.portal
-
-        folder.invokeFactory(MapType(metatype), id)
-        obj = getattr(folder, id)
-
-        if metatype=='Folder' and constraintypes:
-            obj.setConstrainTypesMode(constraintypes.DISABLED)
-
-        if metatype=='Document':
-            obj.setTitle('Simple document')
-            obj.setText('Sample document text')
-            for k, v in kwds.items():
-                field = obj.getField(k)
-                mutator = field.getMutator(obj)(v)
-
-            obj.reindexObject()
-        return obj
-
-    def setup_content(self):
-        self.setRoles(['Manager',])
-        self.loginPortalOwner()
-        f = self.create('folder', 'Folder')
-
-        for id in ('alpha', 'beta'):
-            self.create(id, 'Document', f, subject=['aspidistra'])
-        self.create('gamma', 'Image', f)
-
-        sub1 = self.create('sub1', 'Folder', f)
-        sub1.setSubject(['aspidistra'])
-        sub1.reindexObject()
-        sub2 = self.create('sub2', 'Folder', f)
-        self.create('delta', 'Folder', sub2)
-
-        portal = self.portal
-        tool = self.portal.kupu_library_tool
-        types = tool.zmi_get_resourcetypes()
-        #tool.deleteResource([ t.name for t in types])
-        for k,v in RESOURCES.items():
-            tool.addResourceType(k, [MapType(t) for t in v])
-
     def test_relative(self):
         self.setup_content()
         migrator = Migration(self.kupu)


More information about the kupu-checkins mailing list