[Erp5-report] r12750 - in /spec/debian/erp5-cmfcore/CMFCore/tests: base/ fake_skins/fake_skin/

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Feb 15 17:50:03 CET 2007


Author: yusei
Date: Thu Feb 15 17:50:00 2007
New Revision: 12750

URL: http://svn.erp5.org?rev=12750&view=rev
Log:
commit debian(unstable) packages.

Added:
    spec/debian/erp5-cmfcore/CMFCore/tests/base/__init__.py
    spec/debian/erp5-cmfcore/CMFCore/tests/base/content.py
    spec/debian/erp5-cmfcore/CMFCore/tests/base/dummy.py
    spec/debian/erp5-cmfcore/CMFCore/tests/base/security.py
    spec/debian/erp5-cmfcore/CMFCore/tests/base/testcase.py
    spec/debian/erp5-cmfcore/CMFCore/tests/base/tidata.py
    spec/debian/erp5-cmfcore/CMFCore/tests/base/utils.py
    spec/debian/erp5-cmfcore/CMFCore/tests/fake_skins/fake_skin/

Added: spec/debian/erp5-cmfcore/CMFCore/tests/base/__init__.py
URL: http://svn.erp5.org/spec/debian/erp5-cmfcore/CMFCore/tests/base/__init__.py?rev=12750&view=auto
==============================================================================
--- spec/debian/erp5-cmfcore/CMFCore/tests/base/__init__.py (added)
+++ spec/debian/erp5-cmfcore/CMFCore/tests/base/__init__.py Thu Feb 15 17:50:00 2007
@@ -1,0 +1,3 @@
+"""
+Generic stuff for unit testing the CMF.
+"""

Added: spec/debian/erp5-cmfcore/CMFCore/tests/base/content.py
URL: http://svn.erp5.org/spec/debian/erp5-cmfcore/CMFCore/tests/base/content.py?rev=12750&view=auto
==============================================================================
--- spec/debian/erp5-cmfcore/CMFCore/tests/base/content.py (added)
+++ spec/debian/erp5-cmfcore/CMFCore/tests/base/content.py Thu Feb 15 17:50:00 2007
@@ -1,0 +1,174 @@
+DOCTYPE = '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'''
+
+HTML_TEMPLATE = '''\
+<html><head>
+ <title>%(title)s</title>
+</head>
+<body bgcolor="#efe843">%(body)s</body>
+</html>
+'''
+
+SIMPLE_HTML = '''\
+<html>
+ <head>
+  <title>Title in tag</title>
+  <meta name="description" content="Describe me">
+  <meta name="contributors" content="foo at bar.com; baz at bam.net;
+    Benotz, Larry J (larry at benotz.stuff)">
+  <meta name="title" content="Title in meta">
+  <meta name="subject" content="content management">
+ </head>
+ <body bgcolor="#ffffff">
+  <h1>Not a lot here</h1>
+ </body>
+</html>
+'''
+
+BASIC_HTML = '''\
+<html>
+ <head>
+  <title>Title in tag</title>
+  <meta name="description" content="Describe me">
+  <meta name="contributors" content="foo at bar.com; baz at bam.net;
+    Benotz, Larry J (larry at benotz.stuff)">
+  <meta name="title" content="Title in meta">
+  <meta name="subject" content="content management">
+  <meta name="keywords" content="unit tests, framework; ,zope ">
+ </head>
+ <body bgcolor="#ffffff">
+  <h1>Not a lot here</h1>
+ </body>
+</html>
+'''
+
+SIMPLE_XHTML = """\
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html
+    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+  <title>Title in tag</title>
+  <meta name="description" content="Describe me" />
+  <meta name="contributors" content="foo at bar.com; baz at bam.net;
+    Benotz, Larry J (larry at benotz.stuff)" />
+  <meta name="title" content="Title in meta" />
+  <meta name="subject" content="content management" />
+ </head>
+ <body bgcolor="#ffffff">
+  <h1>Not a lot here</h1>
+ </body>
+</html>
+"""
+
+# A document with an html-qualifying *portion*.
+FAUX_HTML_LEADING_TEXT = '''\
+The following would look like HTML but for this leading text:
+
+<html>
+ <head>
+  <title>Title in tag</title>
+  <meta name="description" content="Describe me">
+  <meta name="contributors" content="foo at bar.com; baz at bam.net;
+    Benotz, Larry J (larry at benotz.stuff)">
+  <meta name="title" content="Title in meta">
+  <meta name="subject" content="content management">
+  <meta name="keywords" content="unit tests, framework; ,zope ">
+ </head>
+ <body bgcolor="#ffffff">
+  <h1>Not a lot here</h1>
+ </body>
+</html>
+'''
+
+ENTITY_IN_TITLE = '''\
+<html>
+ <head>
+  <title>&Auuml;rger</title>
+ </head>
+ <bOdY>
+  <h2>Not a lot here either</h2>
+ </bodY>
+</html>
+'''
+
+SIMPLE_STRUCTUREDTEXT = '''\
+Title: My Document
+Description: A document by me
+Contributors: foo at bar.com; baz at bam.net; no at yes.maybe
+Subject: content management, zope
+
+This is the header
+
+  Body body body body body
+  body body body.
+
+   o A list item
+
+   o And another thing...
+'''
+
+BASIC_STRUCTUREDTEXT = '''\
+Title: My Document
+Description: A document by me
+Contributors: foo at bar.com; baz at bam.net; no at yes.maybe
+Subject: content management, zope
+Keywords: unit tests; , framework
+
+This is the header
+
+  Body body body body body
+  body body body.
+
+   o A list item
+
+   o And another thing...
+'''
+
+STX_WITH_HTML = """\
+Sometimes people do interesting things
+
+  Sometimes people do interesting things like have examples
+  of HTML inside their structured text document.  We should
+  be detecting that this is indeed a structured text document
+  and **NOT** an HTML document::
+
+    <html>
+    <head><title>Hello World</title></head>
+    <body><p>Hello world, I am Bruce.</p></body>
+    </html>
+
+  All in favor say pi!
+"""
+
+
+STX_NO_HEADERS = """\
+Title Phrase
+
+    This is a "plain" STX file, with no headers.  Saving with
+    it shouldn't overwrite any metadata.
+"""
+
+STX_NO_HEADERS_BUT_COLON = """\
+Plain STX:  No magic!
+
+    This is a "plain" STX file, with no headers.  Saving with
+    it shouldn't overwrite any metadata.
+"""
+
+BASIC_RFC822 = """\
+Title: Zope Community
+Description: Link to the Zope Community website.
+Subject: open source; Zope; community
+
+http://www.zope.org
+"""
+
+RFC822_W_CONTINUATION = """\
+Title: Zope Community
+Description: Link to the Zope Community website,
+  including hundreds of contributed Zope products.
+Subject: open source; Zope; community
+
+http://www.zope.org
+"""

Added: spec/debian/erp5-cmfcore/CMFCore/tests/base/dummy.py
URL: http://svn.erp5.org/spec/debian/erp5-cmfcore/CMFCore/tests/base/dummy.py?rev=12750&view=auto
==============================================================================
--- spec/debian/erp5-cmfcore/CMFCore/tests/base/dummy.py (added)
+++ spec/debian/erp5-cmfcore/CMFCore/tests/base/dummy.py Thu Feb 15 17:50:00 2007
@@ -1,0 +1,333 @@
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" Unit test dummies.
+
+$Id: dummy.py 37771 2005-08-07 15:59:22Z yuppie $
+"""
+
+from Acquisition import Implicit, aq_base, aq_inner, aq_parent
+from OFS.SimpleItem import Item
+
+from Products.CMFCore.ActionProviderBase import ActionProviderBase
+from Products.CMFCore.PortalContent import PortalContent
+from security import OmnipotentUser
+
+
+class DummyObject(Implicit):
+    """
+    A dummy callable object.
+    Comes with getIcon and restrictedTraverse
+    methods.
+    """
+    def __init__(self, id='dummy',**kw):
+        self._id = id
+        self.__dict__.update( kw )
+
+    def __str__(self):
+        return self._id
+
+    def __call__(self):
+        return self._id
+
+    def restrictedTraverse( self, path ):
+        return path and getattr( self, path ) or self
+
+    def getIcon( self, relative=0 ):
+        return 'Site: %s' % relative
+
+    def getId(self):
+        return self._id
+
+
+class DummyContent( PortalContent, Item ):
+    """
+    A Dummy piece of PortalContent
+    """
+    meta_type = 'Dummy'
+    portal_type = 'Dummy Content'
+    url = 'foo_url'
+    after_add_called = before_delete_called = 0
+
+    def __init__( self, id='dummy', *args, **kw ):
+        self.id = id
+        self._args = args
+        self._kw = {}
+        self._kw.update( kw )
+
+        self.reset()
+        self.catalog = kw.get('catalog',0)
+        self.url = kw.get('url',None)
+
+    def manage_afterAdd( self, item, container ):
+        self.after_add_called = 1
+        if self.catalog:
+            PortalContent.manage_afterAdd( self, item, container )
+
+    def manage_beforeDelete( self, item, container ):
+        self.before_delete_called = 1
+        if self.catalog:
+            PortalContent.manage_beforeDelete( self, item, container )
+
+    def absolute_url(self):
+       return self.url
+
+    def reset( self ):
+        self.after_add_called = self.before_delete_called = 0
+
+    # Make sure normal Database export/import stuff doesn't trip us up.
+    def _getCopy(self, container):
+        return DummyContent( self.id, catalog=self.catalog )
+
+    def _safe_get(self,attr):
+        if self.catalog:
+            return getattr(self,attr,'')
+        else:
+            return getattr(self,attr)
+
+    def Title( self ):
+        return self.title
+
+    def listCreators(self):
+        return self._safe_get('creators')
+
+    def Subject( self ):
+        return self._safe_get('subject')
+
+    def Description( self ):
+        return self._safe_get('description')
+
+    def created( self ):
+        return self._safe_get('created_date')
+
+    def modified( self ):
+        return self._safe_get('modified_date')
+
+    def Type( self ):
+        return 'Dummy Content Title'
+
+
+class DummyFactory:
+    """
+    Dummy Product Factory
+    """
+    def __init__( self, folder ):
+        self._folder = folder
+
+    def getId(self):
+        return 'DummyFactory'
+
+    def addFoo( self, id, *args, **kw ):
+        if getattr(self._folder, '_prefix', None):
+            id = '%s_%s' % ( self._folder._prefix, id )
+        foo = DummyContent(id, *args, **kw)
+        self._folder._setObject(id, foo)
+        if getattr(self._folder, '_prefix', None):
+            return id
+
+    __roles__ = ( 'FooAdder', )
+    __allow_access_to_unprotected_subobjects__ = { 'addFoo' : 1 }
+
+
+class DummyFolder(DummyObject):
+    """
+        Dummy Container for testing
+    """
+    def __init__( self, id='dummy', fake_product=0, prefix='' ):
+        self._prefix = prefix
+        self._id = id
+
+        if fake_product:
+            self.manage_addProduct = { 'FooProduct' : DummyFactory( self ) }
+
+    def _setOb(self, id, object):
+        setattr(self, id, object)
+
+    def _delOb(self, id):
+        delattr(self, id)
+
+    def _getOb( self, id ):
+        return getattr(self, id)
+
+    def _setObject(self, id, object):
+        self._setOb(id, object)
+        object = self._getOb(id)
+        if hasattr(aq_base(object), 'manage_afterAdd'):
+            object.manage_afterAdd(object, self)
+        return object
+
+    def _delObject(self, id):
+        object = self._getOb(id)
+        if hasattr(aq_base(object), 'manage_beforeDelete'):
+            object.manage_beforeDelete(object, self)
+        self._delOb(id)
+
+    def getPhysicalPath(self):
+        p = aq_parent(aq_inner(self))
+        path = (self._id, )
+        if p is not None:
+            path = p.getPhysicalPath() + path
+        return path
+
+    def getId(self):
+        return self._id
+
+    def reindexObjectSecurity(self):
+        pass
+
+    def contentIds(self):
+        return ('user_bar',)
+
+
+class DummySite(DummyFolder):
+    """ A dummy portal folder.
+    """
+
+    _domain = 'http://www.foobar.com'
+    _path = 'bar'
+    _isPortalRoot = 1
+
+    def absolute_url(self, relative=0):
+        return '/'.join( (self._domain, self._path, self._id) )
+
+    def getPhysicalPath(self):
+        return ('', self._path, self._id)
+
+    def getPhysicalRoot(self):
+        return self
+
+    def unrestrictedTraverse(self, path, default=None, restricted=0):
+        if path == ['acl_users']:
+            return self.acl_users
+        else:
+            obj = self
+            for id in path[3:]:
+                obj = getattr(obj, id)
+            return obj
+
+    def userdefined_roles(self):
+        return ('Member', 'Reviewer')
+
+
+class DummyUser(Implicit):
+    """ A dummy User.
+    """
+
+    def __init__(self, id='dummy'):
+        self.id = id
+
+    def getId(self):
+        return self.id
+
+    getUserName = getId
+
+    def allowed(self, object, object_roles=None):
+        if object_roles is None or 'Anonymous' in object_roles:
+            return 1
+        for role in object_roles:
+            if role in self.getRolesInContext(object):
+                return 1
+        return 0
+
+    def getRolesInContext(self, object):
+        return ('Authenticated', 'Dummy', 'Member')
+
+    def _check_context(self, object):
+        return 1
+
+
+class DummyUserFolder(Implicit):
+    """ A dummy User Folder with 2 dummy Users.
+    """
+
+    id = 'acl_users'
+
+    def __init__(self):
+        setattr( self, 'user_foo', DummyUser(id='user_foo') )
+        setattr( self, 'user_bar', DummyUser(id='user_bar') )
+        setattr( self, 'all_powerful_Oz', OmnipotentUser() )
+
+    def getUsers(self):
+        pass
+
+    def getUser(self, name):
+        return getattr(self, name, None)
+
+    def getUserById(self, id, default=None):
+        return self.getUser(id)
+
+    def userFolderDelUsers(self, names):
+        for user_id in names:
+            delattr(self, user_id)
+
+
+class DummyTool(Implicit,ActionProviderBase):
+    """
+    This is a Dummy Tool that behaves as a
+    a MemberShipTool, a URLTool and an
+    Action Provider
+    """
+
+    _actions = ( DummyObject()
+               , DummyObject()
+               )
+
+    root = 'DummyTool'
+
+    def __init__(self, anon=1):
+        self.anon = anon
+
+    def __call__( self ):
+        return self.root
+
+    getPortalPath = __call__
+
+    def getPortalObject( self ):
+        return aq_parent( aq_inner( self ) )
+
+    def getIcon( self, relative=0 ):
+        return 'Tool: %s' % relative
+
+    # MembershipTool
+    def getAuthenticatedMember(self):
+        return DummyUser()
+
+    def isAnonymousUser(self):
+        return self.anon
+
+    def checkPermission(self, permissionName, object, subobjectName=None):
+        return True
+
+    # TypesTool
+    def listTypeInfo(self, container=None):
+        return ( DummyObject('Dummy Content'), )
+
+    def getTypeInfo(self, contentType):
+        return ( DummyObject('Dummy Content'), )
+
+    # WorkflowTool
+    test_notified = None
+
+    def notifyCreated(self, ob):
+        self.test_notified = ob
+
+
+class DummyCachingManager:
+
+    def getHTTPCachingHeaders( self, content, view_name, keywords, time=None ):
+         return (
+             ('foo', 'Foo'), ('bar', 'Bar'),
+             ('test_path', '/'.join(content.getPhysicalPath())),
+             )
+
+    def getPhysicalPath(self):
+        return ('baz',)

Added: spec/debian/erp5-cmfcore/CMFCore/tests/base/security.py
URL: http://svn.erp5.org/spec/debian/erp5-cmfcore/CMFCore/tests/base/security.py?rev=12750&view=auto
==============================================================================
--- spec/debian/erp5-cmfcore/CMFCore/tests/base/security.py (added)
+++ spec/debian/erp5-cmfcore/CMFCore/tests/base/security.py Thu Feb 15 17:50:00 2007
@@ -1,0 +1,118 @@
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" Unit test security.
+
+$Id: security.py 36662 2004-11-16 22:03:03Z efge $
+"""
+
+from AccessControl.PermissionRole import rolesForPermissionOn
+from Acquisition import Implicit
+
+
+class PermissiveSecurityPolicy:
+    """
+        Very permissive security policy for unit testing purposes.
+    """
+    #
+    #   Standard SecurityPolicy interface
+    #
+    def validate( self
+                , accessed=None
+                , container=None
+                , name=None
+                , value=None
+                , context=None
+                , roles=None
+                , *args
+                , **kw):
+        if name and name.startswith('hidden'):
+            return False
+        else:
+            return True
+
+    def checkPermission(self, permission, object, context):
+        if permission == 'forbidden permission':
+            return 0
+        roles = rolesForPermissionOn(permission, object)
+        if isinstance(roles, basestring):
+            roles=[roles]
+        return context.user.allowed(object, roles)
+
+
+class OmnipotentUser( Implicit ):
+    """
+      Omnipotent User for unit testing purposes.
+    """
+    def getId( self ):
+        return 'all_powerful_Oz'
+
+    getUserName = getId
+
+    def getRoles(self):
+        return ('Manager',)
+
+    def allowed( self, object, object_roles=None ):
+        return 1
+
+    def getRolesInContext(self, object):
+        return ('Manager',)
+
+
+class UserWithRoles( Implicit ):
+    """
+      User with roles specified in constructor
+      for unit testing purposes.
+    """
+    def __init__( self, *roles ):
+        self._roles = roles
+
+    def getId( self ):
+        return 'high_roller'
+
+    getUserName = getId
+
+    def getRoles(self):
+        return self._roles
+
+    def allowed( self, object, object_roles=None ):
+        if object_roles is None:
+            object_roles=()
+        for orole in object_roles:
+            if orole in self._roles:
+                return 1
+        return 0
+
+class AnonymousUser( Implicit ):
+    """
+      Anonymous USer for unit testing purposes.
+    """
+    def getId( self ):
+        return 'Anonymous User'
+
+    getUserName = getId
+
+    def has_permission(self, permission, obj):
+        # For types tool tests dealing with filtered_meta_types
+        return 1
+
+    def allowed( self, object, object_roles=None ):
+        # for testing permissions on actions
+        if object.getId() == 'actions_dummy':
+            if 'Anonymous' in object_roles:
+                return 1
+            else:
+                return 0
+        return 1
+
+    def getRoles(self):
+        return ('Anonymous',)

Added: spec/debian/erp5-cmfcore/CMFCore/tests/base/testcase.py
URL: http://svn.erp5.org/spec/debian/erp5-cmfcore/CMFCore/tests/base/testcase.py?rev=12750&view=auto
==============================================================================
--- spec/debian/erp5-cmfcore/CMFCore/tests/base/testcase.py (added)
+++ spec/debian/erp5-cmfcore/CMFCore/tests/base/testcase.py Thu Feb 15 17:50:00 2007
@@ -1,0 +1,237 @@
+from unittest import TestCase
+try:
+    import Zope2
+except ImportError:
+    # BBB: for Zope 2.7
+    import Zope as Zope2
+Zope2.startup()
+
+import sys
+import time
+from os import chmod, curdir, mkdir, remove, stat, walk
+from os.path import join, abspath, dirname
+from shutil import copytree, rmtree
+from stat import S_IREAD, S_IWRITE
+from tempfile import mktemp
+
+from AccessControl.SecurityManagement import newSecurityManager
+from AccessControl.SecurityManagement import noSecurityManager
+from AccessControl.SecurityManager import setSecurityPolicy
+from Testing.makerequest import makerequest
+import zLOG
+try:
+    import transaction
+except ImportError:
+    # BBB: for Zope 2.7
+    from Products.CMFCore.utils import transaction
+
+from dummy import DummyFolder
+from security import AnonymousUser
+from security import PermissiveSecurityPolicy
+
+class LogInterceptor:
+
+    _old_log_write = None
+    logged = None
+
+    def _catch_log_errors( self, ignored_level=zLOG.PROBLEM ):
+
+        if self._old_log_write is not None:
+            return
+
+        def log_write(subsystem, severity, summary, detail, error):
+            if severity > ignored_level:
+                assert 0, "%s(%s): %s" % (subsystem, severity, summary)
+            if self.logged is None:
+                self.logged = []
+            self.logged.append( ( subsystem, severity, summary, detail ) )
+
+        self._old_log_write = zLOG.log_write
+        zLOG.log_write = log_write
+
+    def _ignore_log_errors( self ):
+
+        if self._old_log_write is None:
+            return
+
+        zLOG.log_write = self._old_log_write
+        del self._old_log_write
+
+class WarningInterceptor:
+
+    _old_stderr = None
+    _our_stderr_stream = None
+
+    def _trap_warning_output( self ):
+
+        if self._old_stderr is not None:
+            return
+
+        import sys
+        from StringIO import StringIO
+
+        self._old_stderr = sys.stderr
+        self._our_stderr_stream = sys.stderr = StringIO()
+
+    def _free_warning_output( self ):
+
+        if self._old_stderr is None:
+            return
+
+        import sys
+        sys.stderr = self._old_stderr
+
+
+class TransactionalTest( TestCase ):
+
+    def setUp( self ):
+        transaction.begin()
+        self.connection = Zope2.DB.open()
+        self.root =  self.connection.root()[ 'Application' ]
+
+    def tearDown( self ):
+        transaction.abort()
+        self.connection.close()
+
+
+class RequestTest( TransactionalTest ):
+
+    def setUp(self):
+        TransactionalTest.setUp(self)
+        root = self.root = makerequest(self.root)
+        self.REQUEST  = root.REQUEST
+        self.RESPONSE = root.REQUEST.RESPONSE
+
+
+class SecurityTest( TestCase ):
+
+    def setUp(self):
+        transaction.begin()
+        self._policy = PermissiveSecurityPolicy()
+        self._oldPolicy = setSecurityPolicy(self._policy)
+        self.connection = Zope2.DB.open()
+        self.root =  self.connection.root()[ 'Application' ]
+        newSecurityManager( None, AnonymousUser().__of__( self.root ) )
+
+    def tearDown( self ):
+        transaction.abort()
+        self.connection.close()
+        noSecurityManager()
+        setSecurityPolicy(self._oldPolicy)
+
+
+class SecurityRequestTest( SecurityTest ):
+
+    def setUp(self):
+        SecurityTest.setUp(self)
+        self.root = makerequest(self.root)
+
+try:
+    __file__
+except NameError:
+    # Test was called directly, so no __file__ global exists.
+    _prefix = abspath(curdir)
+else:
+    # Test was called by another test.
+    _prefix = abspath(dirname(__file__))
+
+_prefix = abspath(join(_prefix,'..'))
+
+
+class FSDVTest( TestCase, WarningInterceptor ):
+    # Base class for FSDV test, creates a fake skin
+    # copy that can be edited.
+
+    _sourceprefix = _prefix
+    _skinname = 'fake_skins'
+    _layername = 'fake_skin'
+
+    def _registerDirectory(self, object=None, ignore=None):
+        self._trap_warning_output()
+        from Products.CMFCore.DirectoryView import registerDirectory
+        from Products.CMFCore.DirectoryView import addDirectoryViews
+        if ignore is None:
+            from Products.CMFCore.DirectoryView import ignore
+        registerDirectory(self._skinname, self.tempname, ignore=ignore)
+        if object is not None:
+            ob = self.ob = DummyFolder()
+            addDirectoryViews(ob, self._skinname, self.tempname)
+
+    def _writeFile(self, filename, stuff):
+        # write some stuff to a file on disk
+        # make sure the file's modification time has changed
+        # also make sure the skin folder mod time has changed
+        try:
+            dir_mtime = stat(self.skin_path_name)[8]
+        except:  # XXX Why bare except?
+            dir_mtime = 0
+        thePath = join(self.skin_path_name,filename)
+        try:
+            mtime1 = stat(thePath)[8]
+        except:  # XXX Why bare except?
+            mtime1 = 0
+        mtime2 = mtime1
+        while mtime2==mtime1:
+            f = open(thePath,'w')
+            f.write(stuff)
+            f.close()
+            mtime2 = stat(thePath)[8]
+        self._addedOrRemoved(dir_mtime)
+
+
+    def _deleteFile(self,filename):
+        try:
+            dir_mtime = stat(self.skin_path_name)[8]
+        except:  # XXX Why bare except?
+            dir_mtime = 0
+        remove(join(self.skin_path_name, filename))
+        self._addedOrRemoved(dir_mtime)
+
+
+    def _addedOrRemoved(self, old_mtime):
+        # Called after adding/removing a file from self.skin_path_name.
+        
+        if sys.platform == 'win32':
+            # Windows doesn't reliably update directory mod times, so
+            # DirectoryView has an expensive workaround.  The
+            # workaround does not rely on directory mod times.
+            return
+        limit = time.time() + 60  # If it takes 60 seconds, give up.
+        new_mtime = old_mtime
+        while new_mtime == old_mtime:
+            # Many systems have a granularity of 1 second.
+            # Add/remove a file until it actually changes the
+            # directory mod time.
+            if time.time() > limit:
+                raise RuntimeError(
+                    "This platform (%s) does not update directory mod times "
+                    "reliably." % sys.platform)
+            time.sleep(0.1)
+            fn = join(self.skin_path_name, '.touch')
+            f = open(fn, 'w')
+            f.write('Temporary file')
+            f.close()
+            remove(fn)
+            new_mtime = stat(self.skin_path_name)[8]
+
+    def setUp(self):
+        # store the place where the skin copy will be created
+        self.tempname = mktemp()
+        # create the temporary folder
+        mkdir(self.tempname)
+        # copy the source fake skin to the new location
+        copytree(join(self._sourceprefix,
+                      self._skinname),
+                 join(self.tempname,
+                      self._skinname))
+        # make sure we have a writable copy
+        for root, dirs, files in walk(self.tempname):
+            for name in files:
+                chmod(join(root, name), S_IREAD+S_IWRITE)
+        # store the skin path name
+        self.skin_path_name = join(self.tempname,self._skinname,self._layername)
+
+    def tearDown(self):
+        # kill the copy
+        self._free_warning_output()
+        rmtree(self.tempname)

Added: spec/debian/erp5-cmfcore/CMFCore/tests/base/tidata.py
URL: http://svn.erp5.org/spec/debian/erp5-cmfcore/CMFCore/tests/base/tidata.py?rev=12750&view=auto
==============================================================================
--- spec/debian/erp5-cmfcore/CMFCore/tests/base/tidata.py (added)
+++ spec/debian/erp5-cmfcore/CMFCore/tests/base/tidata.py Thu Feb 15 17:50:00 2007
@@ -1,0 +1,296 @@
+ManageProperties = 'Manage properties'
+ModifyPortalContent = 'Modify portal content'
+View = 'View'
+
+FTIDATA_ACTIONS = (
+      { 'id' : 'Action Tests'
+      , 'meta_type' : 'Dummy'
+      , 'actions' : (
+            { 'id':'view',
+              'title': 'View',
+              'action':'string:',
+              'permissions':('View',),
+              'category':'object',
+              'visible':1 }
+          , { 'name':'Edit',                    # Note: No ID passed
+              'action':'string:${object_url}/foo_edit',
+              'permissions':('Modify',),
+              'category':'object',
+              'visible':1 }
+          , { 'name':'Object Properties',       # Note: No ID passed
+              'action':'string:foo_properties',
+              'permissions':('Modify',),
+              'category':'object',
+              'visible':1 }
+          , { 'id':'slot',
+              'action':'string:foo_slot',
+              'category':'object',
+              'visible':0 }
+          )
+      }
+    ,
+    )
+
+FTIDATA_DUMMY = (
+      { 'id' : 'Dummy Content'
+      , 'title' : 'Dummy Content Title'
+      , 'meta_type' : 'Dummy'
+      , 'product' : 'FooProduct'
+      , 'factory' : 'addFoo'
+      , 'actions' : (
+            { 'id': 'view',
+              'title': 'View',
+              'action':'string:view',
+              'permissions':('View',) }
+          , { 'id': 'view2',
+              'title': 'View2',
+              'action':'string:view2',
+              'permissions':('View',) }
+          , { 'id': 'edit',
+              'title': 'Edit',
+              'action':'string:edit',
+              'permissions':('forbidden permission',) }
+          )
+      }
+    ,
+    )
+
+FTIDATA_CMF13 = (
+      { 'id' : 'Dummy Content 13'
+      , 'meta_type' : 'Dummy'
+      , 'description' : (
+           'Dummy Content.')
+      , 'icon' : 'dummy_icon.gif'
+      , 'product' : 'FooProduct'
+      , 'factory' : 'addFoo'
+      , 'immediate_view' : 'metadata_edit_form'
+      , 'actions' : (
+            { 'id':'view',
+              'name':'View',
+              'action':'dummy_view',
+              'permissions':(View,) }
+          , { 'id':'edit',
+              'name':'Edit',
+              'action':'dummy_edit_form',
+              'permissions':(ModifyPortalContent,) }
+          , { 'id':'metadata',
+              'name':'Metadata',
+              'action':'metadata_edit_form',
+              'permissions':(ModifyPortalContent,) }
+          )
+      }
+    ,
+    )
+
+FTIDATA_CMF13_FOLDER = (
+      { 'id' : 'Dummy Folder 13'
+      , 'meta_type' : 'Dummy Folder'
+      , 'description' : (
+           'Dummy Folder.')
+      , 'icon' : 'dummy_icon.gif'
+      , 'product' : 'FooProduct'
+      , 'factory' : 'addFoo'
+      , 'filter_content_types' : 0
+      , 'immediate_view' : 'dummy_edit_form'
+      , 'actions' : (
+            { 'id':'view',
+              'name':'View',
+              'action':'',
+              'permissions':(View,),
+              'category':'folder' }
+          , { 'id':'edit',
+              'name':'Edit',
+              'action':'dummy_edit_form',
+              'permissions':(ManageProperties,),
+              'category':'folder' }
+          , { 'id':'localroles',
+              'name':'Local Roles',
+              'action':'folder_localrole_form',
+              'permissions':(ManageProperties,),
+              'category':'folder' }
+          )
+      }
+    ,
+    )
+
+FTIDATA_CMF14 = (
+      { 'id' : 'Dummy Content 14'
+      , 'meta_type' : 'Dummy'
+      , 'description' : (
+           'Dummy Content.')
+      , 'icon' : 'dummy_icon.gif'
+      , 'product' : 'FooProduct'
+      , 'factory' : 'addFoo'
+      , 'immediate_view' : 'metadata_edit_form'
+      , 'actions' : (
+            { 'id':'view',
+              'name':'View',
+              'action':'string:${object_url}/dummy_view',
+              'permissions':(View,) }
+          , { 'id':'edit',
+              'name':'Edit',
+              'action':'string:${object_url}/dummy_edit_form',
+              'permissions':(ModifyPortalContent,) }
+          , { 'id':'metadata',
+              'name':'Metadata',
+              'action':'string:${object_url}/metadata_edit_form',
+              'permissions':(ModifyPortalContent,) }
+          )
+      }
+    ,
+    )
+
+FTIDATA_CMF14_FOLDER = (
+      { 'id' : 'Dummy Folder 14'
+      , 'meta_type' : 'Dummy Folder'
+      , 'description' : (
+           'Dummy Folder.')
+      , 'icon' : 'dummy_icon.gif'
+      , 'product' : 'FooProduct'
+      , 'factory' : 'addFoo'
+      , 'filter_content_types' : 0
+      , 'immediate_view' : 'dummy_edit_form'
+      , 'actions' : (
+            { 'id':'view',
+              'name':'View',
+              'action':'string:${object_url}',
+              'permissions':(View,),
+              'category':'folder' }
+          , { 'id':'edit',
+              'name':'Edit',
+              'action':'string:${object_url}/dummy_edit_form',
+              'permissions':(ManageProperties,),
+              'category':'folder' }
+          , { 'id':'localroles',
+              'name':'Local Roles',
+              'action':'string:${object_url}/folder_localrole_form',
+              'permissions':(ManageProperties,),
+              'category':'folder' }
+          )
+      }
+    ,
+    )
+
+FTIDATA_CMF14_SPECIAL = (
+      { 'id' : 'Dummy Content 14'
+      , 'meta_type' : 'Dummy'
+      , 'description' : (
+           'Dummy Content.')
+      , 'icon' : 'dummy_icon.gif'
+      , 'product' : 'FooProduct'
+      , 'factory' : 'addFoo'
+      , 'immediate_view' : 'metadata_edit_form'
+      , 'actions' : (
+            { 'id':'download',
+              'name':'Download',
+              'action':'string:${object_url}/',   # Note: special default view
+              'permissions':(View,) }
+          , { 'id':'edit',
+              'name':'Edit',
+              'action':'string:${object_url}/dummy_edit_form',
+              'permissions':(ModifyPortalContent,) }
+          , { 'id':'view',                  # Note: not first with 'View' perm
+              'name':'View',
+              'action':'string:${object_url}/dummy_view',
+              'permissions':(View,) }
+          , { 'id':'metadata',
+              'name':'Metadata',
+              'action':'string:${object_url}/metadata_edit_form',
+              'permissions':(ModifyPortalContent,) }
+          , { 'id':'mkdir',
+              'name':'MKDIR handler',
+              'action':'string:dummy_mkdir',
+              'category':'folder',
+              'visible':0 }
+          )
+      }
+    ,
+    )
+
+FTIDATA_CMF14_SPECIAL2 = (
+      { 'id' : 'Dummy Content 14'
+      , 'meta_type' : 'Dummy'
+      , 'description' : (
+           'Dummy Content.')
+      , 'icon' : 'dummy_icon.gif'
+      , 'product' : 'FooProduct'
+      , 'factory' : 'addFoo'
+      , 'immediate_view' : 'metadata_edit_form'
+      , 'actions' : (
+            { 'id': 'top',
+              'name': 'View Mail Archive',
+              'category': 'object',
+              'action':'python:object.getArchive().absolute_url()',
+              'permissions':(View,) }
+          , { 'id':'view',
+              'name':'View',
+              'action':"python:object.someMethod() + '/some_template.html'",
+              'permissions':(View,) }
+          , { 'id':'edit',
+              'name':'Edit',
+              'action':'string:${object_url}/dummy_edit_form',
+              'permissions':(ModifyPortalContent,) }
+          , { 'id':'metadata',
+              'name':'Metadata',
+              'action':'string:${object_url}/metadata_edit_form',
+              'permissions':(ModifyPortalContent,) }
+          , { 'id':'mkdir',
+              'name':'MKDIR handler',
+              'action':'python:object.getMKDIR().absolute_url()',
+              'category':'folder',
+              'visible':0 }
+          )
+      }
+    ,
+    )
+
+FTIDATA_CMF15 = (
+      { 'id' : 'Dummy Content 15'
+      , 'meta_type' : 'Dummy'
+      , 'description' : (
+           'Dummy Content.')
+      , 'icon' : 'dummy_icon.gif'
+      , 'product' : 'FooProduct'
+      , 'factory' : 'addFoo'
+      , 'immediate_view' : 'metadata.html'
+      , 'aliases' : {
+           '(Default)':'dummy_view',
+           'view':'dummy_view',
+           'view.html':'dummy_view',
+           'edit.html':'dummy_edit_form',
+           'metadata.html':'metadata_edit_form',
+           'gethtml':'source_html'}
+      , 'actions' : (
+            { 'id':'view',
+              'title': 'View',
+              'action':'string:${object_url}/view.html',
+              'permissions':(View,) }
+          , { 'id':'edit',
+              'title': 'Edit',
+              'action':'string:${object_url}/edit.html',
+              'permissions':(ModifyPortalContent,) }
+          , { 'id':'metadata',
+              'title': 'Metadata',
+              'action':'string:${object_url}/metadata.html',
+              'permissions':(ModifyPortalContent,) }
+          )
+      }
+    ,
+    )
+
+
+STI_SCRIPT = """\
+## Script (Python) "addBaz"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=folder, id
+##title=
+##
+product = folder.manage_addProduct['FooProduct']
+product.addFoo(id)
+item = getattr(folder, id)
+return item
+"""

Added: spec/debian/erp5-cmfcore/CMFCore/tests/base/utils.py
URL: http://svn.erp5.org/spec/debian/erp5-cmfcore/CMFCore/tests/base/utils.py?rev=12750&view=auto
==============================================================================
--- spec/debian/erp5-cmfcore/CMFCore/tests/base/utils.py (added)
+++ spec/debian/erp5-cmfcore/CMFCore/tests/base/utils.py Thu Feb 15 17:50:00 2007
@@ -1,0 +1,55 @@
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" CMF test utils.
+
+$Id: utils.py 36457 2004-08-12 15:07:44Z jens $
+"""
+
+from unittest import TestSuite
+
+from sys import modules
+
+
+def build_test_suite(package_name, module_names, required=1,
+                     suite_name='test_suite'):
+    """
+    Utlitity for building a test suite from a package name
+    and a list of modules.
+
+    If required is false, then ImportErrors will simply result
+    in that module's tests not being added to the returned
+    suite.
+    """
+
+    suite = TestSuite()
+    try:
+        for name in module_names:
+            the_name = package_name+'.'+name
+            __import__(the_name,globals(),locals())
+            suite.addTest( getattr(modules[the_name], suite_name)() )
+    except ImportError:
+        if required:
+            raise
+    return suite
+
+def has_path( catalog, path ):
+    """
+        Verify that catalog has an object at path.
+    """
+    if type( path ) is type( () ):
+        path = '/'.join(path)
+    rids = map( lambda x: x.data_record_id_, catalog.searchResults() )
+    for rid in rids:
+        if catalog.getpath( rid ) == path:
+            return 1
+    return 0




More information about the Erp5-report mailing list