def flushCacheSetUp(test):
    sectionsSetUp(test)
    
    class DataBase(object):
        def __init__(self, context):
            self.context = context
        
        def cacheMinimize(self):
            self.context.cacheMinimized += 1

        def _getDB(self):
            return self
    
    class DataBasePanel(object):
        def __init__(self, context):
            self.context = context
        
        def getDatabaseNames(self):
            return ('main',)
        
        def __getitem__(self, key):
            return DataBase(self.context)
    
    class ControlPanel(object):
        def __init__(self, context):
            self.Database = DataBasePanel(context)
    
    class MockPortal(object):
        def __init__(self):
            self.cacheMinimized = 0
            self.Control_Panel = ControlPanel(self)
        
    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']
def interfaceManagerSetUp(test):
    sectionsSetUp(test)

    from zope.interface import Interface
    from zope.annotation.interfaces import IAttributeAnnotatable
    from zope.interface import alsoProvides as orig_alsoProvides
    from Products.Archetypes.interfaces import IBaseObject

    class MockPortal(object):

        implements(
            IBaseObject,
        )

        _last_path = None

        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default  # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notatcontent'):
                return object()
            self._last_path = path
            return self

        # implement portal_catalog reindex method
        def reindexIndex(self, *args, **kwargs):
            pass

    updated = []
    test.globs['updated'] = updated

    def patch_alsoProvides(object, *interfaces):
        updated.extend([i.__identifier__ for i in interfaces])
        orig_alsoProvides(object, *interfaces)
    quintagroup.transmogrifier.interfacemanager.alsoProvides = patch_alsoProvides

    portal = MockPortal()
    orig_alsoProvides(portal, IAttributeAnnotatable, Interface)
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    class InterfaceManagerSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(InterfaceManagerSource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notatcontent'),
                dict(_path='spam/eggs/foo'),
            )

    provideUtility(InterfaceManagerSource,
        name=u'quintagroup.transmogrifier.tests.interfacemanagersource')
def xsltSetUp(test):
    sectionsSetUp(test)

    class XSLTSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(XSLTSource, self).__init__(*args, **kw)
            self.sample = (
                {},
                {'_type': 'Weblog'},
                {'_old_type': 'Blog'},
                {'_old_type': 'Blog',
                 '_type': 'Weblog',
                 '_files': {'manifest': {'data': 'xml', 'name': 'manifest.xml'}}},
                {'_old_type': 'Blog',
                 '_type': 'Weblog',
                 '_files': {'marshall': {'data': 'xml', 'name': 'marshall.xml'}}},
                 {'_old_type': 'Large Plone Folder',
                  '_type': 'Folder',
                  '_files': {'marshall': {'data': 'xml', 'name': 'marshall.xml'}}},
            )
            

    provideUtility(XSLTSource,
        name=u'quintagroup.transmogrifier.tests.xsltsource')

    from quintagroup.transmogrifier.xslt import XSLTSection, stylesheet_registry

    XSLTSection.applyTransformations = lambda self, xml, xslt: 'transformed xml'
    test.globs['stylesheet_registry'] = stylesheet_registry
Пример #4
0
def xsltSetUp(test):
    sectionsSetUp(test)

    class XSLTSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(XSLTSource, self).__init__(*args, **kw)
            self.sample = (
                {},
                {'_type': 'Weblog'},
                {'_old_type': 'Blog'},
                {'_old_type': 'Blog',
                 '_type': 'Weblog',
                 '_files': {'manifest': {'data': 'xml', 'name': 'manifest.xml'}}},
                {'_old_type': 'Blog',
                 '_type': 'Weblog',
                 '_files': {'marshall': {'data': 'xml', 'name': 'marshall.xml'}}},
            )

    provideUtility(XSLTSource,
        name=u'quintagroup.transmogrifier.tests.xsltsource')

    from quintagroup.transmogrifier.xslt import XSLTSection, stylesheet_registry

    XSLTSection.applyTransformations = lambda self, xml, xslt: 'transformed xml'
    test.globs['stylesheet_registry'] = stylesheet_registry
Пример #5
0
def flushCacheSetUp(test):
    sectionsSetUp(test)
    
    class DataBase(object):
        def __init__(self, context):
            self.context = context
        
        def cacheMinimize(self):
            self.context.cacheMinimized += 1

        def _getDB(self):
            return self
    
    class DataBasePanel(object):
        def __init__(self, context):
            self.context = context
        
        def getDatabaseNames(self):
            return ('main',)
        
        def __getitem__(self, key):
            return DataBase(self.context)
    
    class ControlPanel(object):
        def __init__(self, context):
            self.Database = DataBasePanel(context)
    
    class MockPortal(object):
        def __init__(self):
            self.cacheMinimized = 0
            self.Control_Panel = ControlPanel(self)
        
    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']
def interfaceManagerSetUp(test):
    sectionsSetUp(test)

    from zope.interface import Interface
    from zope.annotation.interfaces import IAttributeAnnotatable
    from zope.interface import alsoProvides as orig_alsoProvides
    from Products.Archetypes.interfaces import IBaseObject

    class MockPortal(object):

        implements(
            IBaseObject,
        )

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notatcontent'):
                return object()
            self._last_path = path
            return self

        # implement portal_catalog reindex method
        def reindexIndex(self, *args, **kwargs):
            pass


    updated = []
    test.globs['updated'] = updated
    def patch_alsoProvides(object, *interfaces):
        updated.extend([i.__identifier__ for i in interfaces])
        orig_alsoProvides(object, *interfaces)
    quintagroup.transmogrifier.interfacemanager.alsoProvides = patch_alsoProvides

    portal = MockPortal()
    orig_alsoProvides(portal, IAttributeAnnotatable, Interface)
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    class InterfaceManagerSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(InterfaceManagerSource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notatcontent'),
                dict(_path='spam/eggs/foo'),
            )

    provideUtility(InterfaceManagerSource,
        name=u'quintagroup.transmogrifier.tests.interfacemanagersource')
def readerSetUp(test):
    sectionsSetUp(test)

    class MockImportContext(object):

        _dirs = [
            'structure',
            'structure/news', 'structure/news/recent',
            'structure/pages', 'structure/pages/front-page',
        ]
        _files = [
            'structure/.properties.xml',
            'structure/other.file',
            'structure/news/.objects.xml',
            'structure/pages/.objects.xml',
            'structure/pages/front-page/.marshall.xml',
            'structure/pages/front-page/.comments.xml',
        ]

        def __init__( self, *args, **kwargs):
            self.args = args
            for k, v in kwargs.items():
                setattr(self, k, v)

        def __repr__(self):
            s = " ".join(["%s=%s" % (k,v) for k,v in self.__dict__.items()])
            return "<%s %s>" % (self.__class__.__name__, s)

        def readDataFile(self, filename, subdir=None):
            return 'some data'

        def isDirectory(self, path):
            return path == '' or path in self._dirs

        def listDirectory(self, path):
            all_names = self._dirs + self._files
            if path:
                pfx_len = len(path)+1
            else:
                pfx_len = 0
            names = []
            for name in all_names:
                if name == path:
                    continue
                if not name.startswith(path):
                    continue
                name = name[pfx_len:]
                if '/' in name:
                    continue
                names.append(name)
            return names

    from Products.GenericSetup import context

    context.DirectoryImportContext = type('Directory', (MockImportContext,),
        {'listDirectory': lambda self, path: []})
    context.TarballImportContext = type('Tarball', (MockImportContext,), {})
    context.SnapshotImportContext = type('Snapshot', (MockImportContext,),
        {'listDirectory': lambda self, path: []})
Пример #8
0
def readerSetUp(test):
    sectionsSetUp(test)

    class MockImportContext(object):

        _dirs = [
            'structure',
            'structure/news', 'structure/news/recent',
            'structure/pages', 'structure/pages/front-page',
        ]
        _files = [
            'structure/.properties.xml',
            'structure/other.file',
            'structure/news/.objects.xml',
            'structure/pages/.objects.xml',
            'structure/pages/front-page/.marshall.xml',
            'structure/pages/front-page/.comments.xml',
        ]

        def __init__( self, *args, **kwargs):
            self.args = args
            for k, v in kwargs.items():
                setattr(self, k, v)

        def __repr__(self):
            s = " ".join(["%s=%s" % (k,v) for k,v in self.__dict__.items()])
            return "<%s %s>" % (self.__class__.__name__, s)

        def readDataFile(self, filename, subdir=None):
            return 'some data'

        def isDirectory(self, path):
            return path == '' or path in self._dirs

        def listDirectory(self, path):
            all_names = self._dirs + self._files
            if path:
                pfx_len = len(path)+1
            else:
                pfx_len = 0
            names = []
            for name in all_names:
                if name == path:
                    continue
                if not name.startswith(path):
                    continue
                name = name[pfx_len:]
                if '/' in name:
                    continue
                names.append(name)
            return names

    from Products.GenericSetup import context

    context.DirectoryImportContext = type('Directory', (MockImportContext,),
        {'listDirectory': lambda self, path: []})
    context.TarballImportContext = type('Tarball', (MockImportContext,), {})
    context.SnapshotImportContext = type('Snapshot', (MockImportContext,),
        {'listDirectory': lambda self, path: []})
Пример #9
0
def uidSetUp(test):
    sectionsSetUp(test)

    from Products.Archetypes.interfaces import IReferenceable

    class MockReferenceableObject(object):
        implements(IReferenceable)

        def __init__(self, path, portal):
            self.path = path
            self.portal = portal

        _at_uid = 'xyz'
        def UID(self):
            return self._at_uid

        def _setUID(self, uid):
            self.portal.uids_set.append((self.path, uid))
            self._at_uid = uid

    class MockPortal(object):
        implements(IReferenceable)

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notatcontent'):
                return object()
            return MockReferenceableObject(path, self)

        uids_set = []

    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']

    class UIDSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(UIDSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='/spam/eggs/foo',     _uid='abc',), # will be set
                dict(_path='/spam/eggs/bar',     _uid='xyz',), # same as default
                dict(_path='not/existing/bar',   _uid='def',), # not found
                dict(                            _uid='geh',), # no path
                dict(_path='/spam/eggs/baz',                ), # no uid
                dict(_path='/spam/notatcontent', _uid='ijk',), # not referenceable
            )
    provideUtility(UIDSource,
        name=u'plone.app.transmogrifier.tests.uidsource')
Пример #10
0
def siteWalkerSetUp(test):
    sectionsSetUp(test)

    from Products.CMFCore.interfaces import IFolderish
    from Products.Archetypes.interfaces import IBaseFolder

    class MockContent(object):
        path = ()

        def getPhysicalPath(self):
            return self.path

        def getPortalTypeName(self):
            return self.__class__.__name__

        @property
        def meta_type(self):
            return self.__class__.__name__
        

    class Document(MockContent):
        pass

    class Folder(MockContent, dict):
        implements(IBaseFolder)

        contentItems = dict.items
        contentValues = dict.values
        objectItems = dict.items
        objectValues = dict.values

    class MockPortal(MockContent, dict):
        implements(IFolderish)

        contentItems = dict.items
        contentValues = dict.values
        objectItems = dict.items
        objectValues = dict.values

    portal = MockPortal()

    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    portal.path = ('', 'plone')
    portal['document1'] = Document()
    portal['document1'].path = ('', 'plone', 'document1')
    portal['folder1'] = Folder()
    portal['folder1'].path = ('', 'plone', 'folder1')
    portal['folder1']['document2'] = Document()
    portal['folder1']['document2'].path = ('', 'plone', 'folder1', 'document2')
    portal['folder1']['folder2'] = Folder()
    portal['folder1']['folder2'].path = ('', 'plone', 'folder1', 'folder2')
    portal['document3'] = Document()
    portal['document3'].path = ('', 'plone', 'document3')
Пример #11
0
def siteWalkerSetUp(test):
    sectionsSetUp(test)

    from collective.transmogrifier.interfaces import IFolderish
    from quintagroup.transmogrifier.interfaces import IBaseFolder

    class MockContent(object):
        path = ()

        def getPhysicalPath(self):
            return self.path

        def getPortalTypeName(self):
            return self.__class__.__name__

    class Document(MockContent):
        pass

    class File(MockContent):
        pass

    class Folder(MockContent, dict):
        implements(IBaseFolder)

        contentItems = dict.items
        contentValues = dict.values

    class MockPortal(MockContent, dict):
        implements(IFolderish)

        contentItems = dict.items
        contentValues = dict.values

    portal = MockPortal()

    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    portal.path = ('', 'plone')
    portal['document1'] = Document()
    portal['document1'].path = ('', 'plone', 'document1')
    portal['folder1'] = Folder()
    portal['folder1'].path = ('', 'plone', 'folder1')
    portal['folder1']['document2'] = Document()
    portal['folder1']['document2'].path = ('', 'plone', 'folder1', 'document2')
    portal['folder1']['folder2'] = Folder()
    portal['folder1']['folder2'].path = ('', 'plone', 'folder1', 'folder2')
    portal['folder1']['folder2']['file'] = File()
    portal['folder1']['folder2']['file'].path  = ('', 'plone', 'folder1', 'folder2', 'file')
    portal['document3'] = Document()
    portal['document3'].path = ('', 'plone', 'document3')
    portal['file'] = File()
    portal['file'].path = ('', 'plone', 'file')
Пример #12
0
def reindexObjectSetup(test):
    sectionsSetUp(test)

    from Products.CMFCore.CMFCatalogAware import CatalogAware
    from Products.Archetypes.interfaces import IBaseObject

    class MockCatalogAwareObject(CatalogAware): pass

    class MockPortal(object):
        implements(IBaseObject)

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path == 'not/a/catalog/aware/content':
                return default
            self._last_path = path
            return MockCatalogAwareObject(self)

        @property
        def portal_catalog(self):
            return self

        reindexed = ()
        def reindexObject(self, ob):
            self.reindexed += ((self._last_path, 'reindexed'),)

    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']

    class ReindexObjectSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(ReindexObjectSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='/spam/eggs/foo'), # will be set
                dict(_path='/spam/eggs/bar'), # will be set
                dict(_path='/spam/eggs/baz'), # will be set
                dict(_path='not/a/catalog/aware/content',
                     title='Should not be reindexed, not a CMFCatalogAware content'),
                dict(_path='not/existing/bar',
                     title='Should not be reindexed, not an existing path'),
            )
    provideUtility(ReindexObjectSource,
        name=u'plone.app.transmogrifier.tests.reindexobjectsource')
Пример #13
0
def portalTransformsSetUp(test):
    sectionsSetUp(test)

    class MockPortalTransforms(object):
        def __call__(self, transform, data):
            return 'Transformed %r using the %s transform' % (data, transform)
        def convertToData(self, target, data, mimetype=None):
            if mimetype is not None:
                return 'Transformed %r from %s to %s' % (
                    data, mimetype, target)
            else:
                return 'Transformed %r to %s' % (data, target)
    test.globs['plone'].portal_transforms = MockPortalTransforms()
Пример #14
0
def browserDefaultSetUp(test):
    sectionsSetUp(test)

    from Products.CMFDynamicViewFTI.interface import ISelectableBrowserDefault

    class MockPortal(MockObjectManager):
        implements(ISelectableBrowserDefault)

        def hasObject(self, id_):
            path = posixpath.join(self._path, id_)
            if path[0] == '/':
                return False  # path is absolute
            if isinstance(path, unicode):
                return False
            if path == 'not/existing/bar':
                return False
            return True

        updated = []

        def setLayout(self, layout):
            self.updated.append((self._last_path[0], 'layout', layout))

        def setDefaultPage(self, defaultpage):
            self.updated.append(
                (self._last_path[0], 'defaultpage', defaultpage))

    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']

    class BrowserDefaultSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(BrowserDefaultSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='/spam/eggs/foo', _layout='spam'),
                dict(_path='/spam/eggs/bar', _defaultpage='eggs'),
                dict(_path='/spam/eggs/baz', _layout='spam', _defaultpage='eggs'),
                dict(_path='not/existing/bar', _layout='spam',
                     title='Should not be updated, not an existing path'),
                dict(_path='spam/eggs/incomplete',
                     title='Should not be updated, no layout or defaultpage'),
                dict(_path='spam/eggs/emptylayout', _layout='',
                     title='Should not be updated, no layout or defaultpage'),
                dict(_path='spam/eggs/emptydefaultpage', _defaultpage='',
                     title='Should not be updated, no layout or defaultpage'),
            )
    provideUtility(BrowserDefaultSource,
        name=u'plone.app.transmogrifier.tests.browserdefaultsource')
Пример #15
0
def workflowUpdaterSetUp(test):
    sectionsSetUp(test)

    from Products.CMFCore.WorkflowCore import WorkflowException

    class MockPortal(MockObjectManager):

        def hasObject(self, id_):
            path = posixpath.join(self._path, id_)
            if path[0] == '/':
                return False  # path is absolute
            if isinstance(path, unicode):
                return False
            if path == 'not/existing/bar':
                return False
            return True

        @property
        def portal_workflow(self):
            return self

        updated = []

        def doActionFor(self, ob, action):
            assert isinstance(ob, self.__class__)
            if action == 'nonsuch':
                raise WorkflowException('Test exception')
            self.updated.append((self._last_path[0], action))

    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']

    class WorkflowSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(WorkflowSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='/spam/eggs/foo', _transitions='spam'),
                dict(_path='/spam/eggs/baz', _transitions=('spam', 'eggs')),
                dict(_path='not/existing/bar', _transitions=('spam', 'eggs'),
                     title='Should not be updated, not an existing path'),
                dict(_path='spam/eggs/incomplete',
                     title='Should not be updated, no transitions'),
                dict(_path='/spam/eggs/nosuchtransition',
                     _transitions=('nonsuch',),
                     title='Should not be updated, no such transition'),
            )
    provideUtility(WorkflowSource,
        name=u'plone.app.transmogrifier.tests.workflowsource')
Пример #16
0
def workflowUpdaterSetUp(test):
    sectionsSetUp(test)

    from Products.CMFCore.WorkflowCore import WorkflowException

    class MockPortal(object):
        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            self._last_path = path
            return self

        @property
        def portal_workflow(self):
            return self

        updated = ()
        def doActionFor(self, ob, action):
            assert ob == self
            if action == 'nonsuch':
                raise WorkflowException('Test exception')
            self.updated += ((self._last_path, action),)

    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']

    class WorkflowSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(WorkflowSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='/spam/eggs/foo', _transitions='spam'),
                dict(_path='/spam/eggs/baz', _transitions=('spam', 'eggs')),
                dict(_path='not/existing/bar', _transitions=('spam', 'eggs'),
                     title='Should not be updated, not an existing path'),
                dict(_path='spam/eggs/incomplete',
                     title='Should not be updated, no transitions'),
                dict(_path='/spam/eggs/nosuchtransition',
                     _transitions=('nonsuch',),
                     title='Should not be updated, no such transition'),
            )
    provideUtility(WorkflowSource,
        name=u'plone.app.transmogrifier.tests.workflowsource')
Пример #17
0
def reindexObjectSetup(test):
    sectionsSetUp(test)

    from Products.CMFCore.CMFCatalogAware import CatalogAware
    from Products.Archetypes.interfaces import IBaseObject

    class MockPortal(MockObjectManager, CatalogAware):
        implements(IBaseObject)

        def hasObject(self, id_):
            path = posixpath.join(self._path, id_)
            if path[0] == '/':
                return False  # path is absolute
            if isinstance(path, unicode):
                return False
            if path == 'not/existing/bar':
                return False
            if path == 'not/a/catalog/aware/content':
                return False
            return True

        @property
        def portal_catalog(self):
            return self

        reindexed = []

        def reindexObject(self, ob):
            self.reindexed.append((self._last_path[0], 'reindexed'))

    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']

    class ReindexObjectSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(ReindexObjectSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='/spam/eggs/foo'), # will be set
                dict(_path='/spam/eggs/bar'), # will be set
                dict(_path='/spam/eggs/baz'), # will be set
                dict(_path='not/a/catalog/aware/content',
                     title='Should not be reindexed, not a CMFCatalogAware content'),
                dict(_path='not/existing/bar',
                     title='Should not be reindexed, not an existing path'),
            )
    provideUtility(ReindexObjectSource,
        name=u'plone.app.transmogrifier.tests.reindexobjectsource')
Пример #18
0
def browserDefaultSetUp(test):
    sectionsSetUp(test)

    from Products.CMFDynamicViewFTI.interface import ISelectableBrowserDefault
    class MockPortal(object):
        implements(ISelectableBrowserDefault)

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            self._last_path = path
            return self

        updated = ()
        def setLayout(self, layout):
            self.updated += ((self._last_path, 'layout', layout),)

        def setDefaultPage(self, defaultpage):
            self.updated += ((self._last_path, 'defaultpage', defaultpage),)

    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']

    class BrowserDefaultSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(BrowserDefaultSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='/spam/eggs/foo', _layout='spam'),
                dict(_path='/spam/eggs/bar', _defaultpage='eggs'),
                dict(_path='/spam/eggs/baz', _layout='spam', _defaultpage='eggs'),
                dict(_path='not/existing/bar', _layout='spam',
                     title='Should not be updated, not an existing path'),
                dict(_path='spam/eggs/incomplete',
                     title='Should not be updated, no layout or defaultpage'),
                dict(_path='spam/eggs/emptylayout', _layout='',
                     title='Should not be updated, no layout or defaultpage'),
                dict(_path='spam/eggs/emptydefaultpage', _defaultpage='',
                     title='Should not be updated, no layout or defaultpage'),
            )
    provideUtility(BrowserDefaultSource,
        name=u'plone.app.transmogrifier.tests.browserdefaultsource')
Пример #19
0
def uidSetUp(test):
    sectionsSetUp(test)

    from Products.Archetypes.interfaces import IReferenceable

    class MockPortal(MockObjectManager):
        implements(IReferenceable)

        def hasObject(self, id_):
            path = posixpath.join(self._path, id_)
            if path[0] == '/':
                return False  # path is absolute
            if isinstance(path, unicode):
                return False
            if path == 'not/existing/bar':
                return False
            if path.endswith('/notatcontent'):
                return object()
            return True

        uids_set = []
        _at_uid = 'xyz'

        def UID(self):
            return self._at_uid

        def _setUID(self, uid):
            self.uids_set.append((self._path, uid))
            self._at_uid = uid

    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']

    class UIDSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(UIDSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='/spam/eggs/foo',     _uid='abc',), # will be set
                dict(_path='/spam/eggs/bar',     _uid='xyz',), # same as default
                dict(_path='not/existing/bar',   _uid='def',), # not found
                dict(                            _uid='geh',), # no path
                dict(_path='/spam/eggs/baz',                ), # no uid
                dict(_path='/spam/notatcontent', _uid='ijk',), # not referenceable
            )
    provideUtility(UIDSource,
        name=u'plone.app.transmogrifier.tests.uidsource')
def manifestSetUp(test):
    sectionsSetUp(test)

    root = dict(
        _path='',
        _entries=(
            ('news', 'Folder'),
            ('events', 'Folder'),
            ('front-page', 'Document'),
            ('only-in-manifest', 'Document')
        )
    )

    news = dict(
        _path='news',
        _entries=(
            ('aggregator', 'Topic'),
            ('once-more', 'File')
        )
    )

    aggregator = dict(
        _path='news/aggregator',
    )

    events = dict(
        _path='events'
    )

    front_page = dict(
        _path='front-page',
    )

    members = dict(
        _path='Members'
    )

    class ManifestSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(ManifestSource, self).__init__(*args, **kw)
            self.sample = (root, dict(), news, aggregator, events, front_page, members)

    provideUtility(ManifestSource,
        name=u'quintagroup.transmogrifier.tests.manifestsource')
Пример #21
0
def manifestSetUp(test):
    sectionsSetUp(test)

    root = dict(
        _path='',
        _entries=(
            ('news', 'Folder'),
            ('events', 'Folder'),
            ('front-page', 'Document'),
            ('only-in-manifest', 'Document')
        )
    )

    news = dict(
        _path='news',
        _entries=(
            ('aggregator', 'Topic'),
            ('once-more', 'File')
        )
    )

    aggregator = dict(
        _path='news/aggregator',
    )

    events = dict(
        _path='events'
    )

    front_page = dict(
        _path='front-page',
    )

    members = dict(
        _path='Members'
    )

    class ManifestSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(ManifestSource, self).__init__(*args, **kw)
            self.sample = (root, dict(), news, aggregator, events, front_page, members)

    provideUtility(ManifestSource,
        name=u'quintagroup.transmogrifier.tests.manifestsource')
def siteWalkerSetUp(test):
    sectionsSetUp(test)

    from Products.CMFCore.interfaces import IFolderish
    from Products.Archetypes.interfaces import IBaseFolder

    class MockContent(object):
        path = ()

        def getPhysicalPath(self):
            return self.path

        def getPortalTypeName(self):
            return self.__class__.__name__

    class Document(MockContent):
        pass

    class Folder(MockContent, dict):
        implements(IBaseFolder)

        contentItems = dict.items
        contentValues = dict.values

    class MockPortal(MockContent, dict):
        implements(IFolderish)

        contentItems = dict.items
        contentValues = dict.values

    portal = MockPortal()

    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    portal.path = ('', 'plone')
    portal['document1'] = Document()
    portal['document1'].path = ('', 'plone', 'document1')
    portal['folder1'] = Folder()
    portal['folder1'].path = ('', 'plone', 'folder1')
    portal['folder1']['document2'] = Document()
    portal['folder1']['document2'].path = ('', 'plone', 'folder1', 'document2')
    portal['folder1']['folder2'] = Folder()
    portal['folder1']['folder2'].path = ('', 'plone', 'folder1', 'folder2')
    portal['document3'] = Document()
    portal['document3'].path = ('', 'plone', 'document3')
Пример #23
0
def browserDefaultSetUp(test):
    sectionsSetUp(test)

    from plone.app.transmogrifier.interfaces import ISelectableBrowserDefault
    class MockPortal(object):
        implements(ISelectableBrowserDefault)

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            self._last_path = path
            return self

        updated = ()
        def setLayout(self, layout):
            self.updated += ((self._last_path, 'layout', layout),)

        def setDefaultPage(self, defaultpage):
            self.updated += ((self._last_path, 'defaultpage', defaultpage),)

    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']

    class BrowserDefaultSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(BrowserDefaultSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='/spam/eggs/foo', _layout='spam'),
                dict(_path='/spam/eggs/bar', _defaultpage='eggs'),
                dict(_path='/spam/eggs/baz', _layout='spam', _defaultpage='eggs'),
                dict(_path='not/existing/bar', _layout='spam',
                     title='Should not be updated, not an existing path'),
                dict(_path='spam/eggs/incomplete',
                     title='Should not be updated, no layout or defaultpage'),
            )
    provideUtility(BrowserDefaultSource,
        name=u'plone.app.transmogrifier.tests.browserdefaultsource')
def substitutionSetUp(test):
    sectionsSetUp(test)

    class SubstitutionSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(SubstitutionSource, self).__init__(*args, **kw)
            self.sample = (
                {},
                {'_type': 'Blog'},
                {'_type': 'PloneFormMailer'},
                {'_type': 'Document'},
            )

    provideUtility(SubstitutionSource,
        name=u'quintagroup.transmogrifier.tests.substitutionsource')
Пример #25
0
def substitutionSetUp(test):
    sectionsSetUp(test)

    class SubstitutionSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(SubstitutionSource, self).__init__(*args, **kw)
            self.sample = (
                {},
                {'_type': 'Blog'},
                {'_type': 'PloneFormMailer'},
                {'_type': 'Document'},
            )

    provideUtility(SubstitutionSource,
        name=u'quintagroup.transmogrifier.tests.substitutionsource')
Пример #26
0
def criteriaSetUp(test):
    sectionsSetUp(test)

    from Products.ATContentTypes.interface import IATTopic

    class MockPortal(MockObjectManager):
        implements(IATTopic)

        def hasObject(self, id_):
            path = posixpath.join(self._path, id_)
            if path[0] == '/':
                return False  # path is absolute
            if isinstance(path, unicode):
                return False
            if path == 'not/existing/bar':
                return False
            return True

        criteria = []

        def addCriterion(self, field, criterion):
            self.criteria.append((self._last_path[0], field, criterion))

    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']

    class CriteriaSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(CriteriaSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='/spam/eggs/foo', _criterion='bar', _field='baz'),
                dict(_path='not/existing/bar', _criterion='bar', _field='baz',
                     title='Should not be updated, not an existing path'),
                dict(_path='spam/eggs/incomplete',
                     title='Should not be updated, no criterion or field'),
            )
    provideUtility(CriteriaSource,
        name=u'plone.app.transmogrifier.tests.criteriasource')
Пример #27
0
def urlNormalizerSetUp(test):
    sectionsSetUp(test)

    from Products.CMFDynamicViewFTI.interface import ISelectableBrowserDefault
    class MockPortal(object):
        implements(ISelectableBrowserDefault)

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            self._last_path = path
            return self

        updated = ()

    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']

    class URLNormalizerSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(URLNormalizerSource, self).__init__(*args, **kw)
            self.sample = (
                dict(title='mytitle'),
                dict(title='Is this a title of any sort?'),
                dict(title='Put some <br /> $1llY V4LUES -- here&there'),
                dict(title='What about \r\n line breaks (system)'),
                dict(title='Try one of these --------- oh'),
                dict(language='My language is de'),
                dict(language='my language is en')
            )
    provideUtility(URLNormalizerSource,
        name=u'plone.app.transmogrifier.tests.urlnormalizersource')
Пример #28
0
def criteriaSetUp(test):
    sectionsSetUp(test)

    from Products.ATContentTypes.interface import IATTopic
    class MockPortal(object):
        implements(IATTopic)

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            self._last_path = path
            return self

        criteria = ()
        def addCriterion(self, field, criterion):
            self.criteria += ((self._last_path, field, criterion),)

    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']

    class CriteriaSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(CriteriaSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='/spam/eggs/foo', _criterion='bar', _field='baz'),
                dict(_path='not/existing/bar', _criterion='bar', _field='baz',
                     title='Should not be updated, not an existing path'),
                dict(_path='spam/eggs/incomplete',
                     title='Should not be updated, no criterion or field'),
            )
    provideUtility(CriteriaSource,
        name=u'plone.app.transmogrifier.tests.criteriasource')
Пример #29
0
def mimeencapsulatorSetUp(test):
    sectionsSetUp(test)

    class EncapsulatorSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(EncapsulatorSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_data='foobarbaz', _mimetype='application/x-test-data'),
                dict(_mimetype='skip/nodata'),
                dict(portrait='skip, no mimetypeset'),
                dict(portrait='someportraitdata',
                     _portrait_mimetype='image/jpeg'),
            )
    provideUtility(EncapsulatorSource,
        name=u'plone.app.transmogrifier.tests.encapsulatorsource')

    from OFS.Image import File
    class OFSFilePrinter(object):
        """Prints out data on any OFS.Image.File object in the item"""
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, transmogrifier, name, options, previous):
            self.previous = previous

        def __iter__(self):
            for item in self.previous:
                for key, value in item.iteritems():
                    if isinstance(value, File):
                        print '%s: (%s) %s' % (
                            key, value.content_type, str(value))
                yield item
    provideUtility(OFSFilePrinter,
        name=u'plone.app.transmogrifier.tests.ofsfileprinter')
Пример #30
0
def commentsSetUp(test):
    sectionsSetUp(test)

    class MockDiscussionItem(object):
        creator = 'creator'
        modified = 'date'

        def __init__(self, reply, text=""):
            self.in_reply_to = reply
            self.text = text

        def __of__(self, container):
            return self

        def getMetadataHeaders(self):
            return []

        def setMetadata(self, headers):
            pass

        def Creator(self):
            return self.creator

        def addCreator(self, creator):
            self.creator = creator

        def ModificationDate(self):
            return self.modified

        def setModificationDate(self, date):
            self.modified = date

        def setFormat(self, format):
            pass

        def _edit(self, text=None):
            self.text = text

        def indexObject(self):
            pass

        def __repr__(self):
            return "<DicussionItem %s %s %s %s>" % (
                self.Creator(),
                self.ModificationDate(),
                self.in_reply_to,
                self.text
                )

    from Products.CMFDefault import DiscussionItem
    DiscussionItem.DiscussionItem = MockDiscussionItem

    class MockPortal(object):
        _discussion = {
            '1': MockDiscussionItem(None, 'comment to content'),
            '2': MockDiscussionItem('1', 'reply to first comment'),
            '3': MockDiscussionItem(None, 'other comment to content')
        }
        _container = {}

        @property
        def talkback(self):
            return self

        def objectItems(self):
            l = self._discussion.items()
            l.sort(key=lambda x: int(x[0]))
            return l

        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notdiscussable'):
                return object()
            return self

        def getDiscussionFor(self, obj):
            return self

    portal = MockPortal()
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    class CommentsSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(CommentsSource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notdiscussable'),
                dict(_path='spam/eggs/foo'),
            )

    provideUtility(CommentsSource,
        name=u'quintagroup.transmogrifier.tests.commentssource')
Пример #31
0
def dataCorrectorSetUp(test):
    sectionsSetUp(test)

    class MockPortal(object):
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notadaptable'):
                return object()
            return self

    portal = MockPortal()
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    from collective.transmogrifier.interfaces import ITransmogrifier
    from quintagroup.transmogrifier.interfaces import IExportDataCorrector, \
        IImportDataCorrector

    class MockExportAdapter(object):
        implements(IExportDataCorrector)
        adapts(MockPortal, ITransmogrifier)
        def __init__(self, context, transmogrifier):
            self.context = context
            self.transmogrifier = transmogrifier

        def __call__(self, data):
            return "modified export data"

    provideAdapter(MockExportAdapter, name="marshall")

    class MockImportAdapter(object):
        implements(IImportDataCorrector)
        adapts(MockPortal, ITransmogrifier)
        def __init__(self, context, transmogrifier):
            self.context = context
            self.transmogrifier = transmogrifier

        def __call__(self, data):
            return "modified import data"

    provideAdapter(MockImportAdapter, name="manifest")

    class DataCorrectorSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(DataCorrectorSource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_files=dict(marshall="item hasn't path")),
                dict(_path='spam/eggs/foo'),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notadaptable', _files=dict(marshall="object isn't adaptable")),
                dict(_path='spam/eggs/foo',
                     _files=dict(marshall='marshall data', unchanged='this must be unchanged')),
                dict(_path='spam/eggs/foo',
                     _files=dict(manifest='manifest data', unchanged='this must be unchanged')),
            )

    provideUtility(DataCorrectorSource,
        name=u'quintagroup.transmogrifier.tests.datacorrectorsource')
Пример #32
0
def marshallSetUp(test):
    sectionsSetUp(test)

    from Products.Archetypes.interfaces import IBaseObject

    class Field(object):
        def __init__(self, name):
            self.name = name
            self.obj = None

        def getAccessor(self, obj):
            self.obj = obj
            return self

        def getMutator(self, obj):
            self.obj = obj
            return self

        def __call__(self, value=None):
            if value is None:
                return self.obj.fields[self.name]
            else:
                self.obj.fields[self.name] = value

    class MockBase(object):
        def __init__(self, effective=None):
            self.fields = {
                'effectiveDate': effective,
                'modification_date': 'changed',
            }

        def checkCreationFlag(self):
            return True

        def unmarkCreationFlag(self):
            pass

        def at_post_create_script(self):
            pass

        def at_post_edit_script(self):
            pass

        indexed = ()
        def indexObject(self):
            self.indexed += (self._last_path,)

        def getField(self, fname):
            return Field(fname)

    class MockCriterion(MockBase):
        implements(IBaseObject)
        _last_path = None
        indexed = ()
        def indexObject(self):
            self.indexed += (self._last_path,)

    class MockPortal(MockBase):
        implements(IBaseObject)

        criterion = MockCriterion('not changed')

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path == 'topic/criterion':
                self._last_path = path
                self.criterion._last_path = path
                return self.criterion
            if path.endswith('/notatcontent'):
                return object()
            self._last_path = path
            return self

        def getId(self):
            return "plone"

        indexed = ()
        def indexObject(self):
            self.indexed += (self._last_path,)

        updatedRoles = False
        def updateRoleMappings(self):
            self.updatedRoles = True

        reindexed = False
        def reindexIndex(self, name, extra=None):
            self.reindexed = True

        marshalled = ()
        def marshall(self, instance, **kwargs):
            self.marshalled += ((self._last_path, kwargs.get('atns_exclude')),)
            # Marshall often fails to export topic criteria
            if isinstance(instance, MockCriterion):
                return None, None, None
            else:
                return None, None, "marshalled"

        demarshalled = ()
        def demarshall(self, instance, data):
            # we don't need to test Marshall product, only check if we call it's components
            self.demarshalled += (self._last_path,)

    portal = MockPortal()
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    from Products.Marshall import registry
    def getComponent(name):
        return portal
    registry.getComponent = getComponent

    class MarshallSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(MarshallSource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='spam/eggs/foo', _excluded_fields=('file', 'image')),
                dict(_path='topic/criterion'),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notatcontent', 
                     _files=dict(marshall=dict(data='xml', name='.marshall.xml'))),
            )
    provideUtility(MarshallSource,
        name=u'quintagroup.transmogrifier.tests.marshallsource')
Пример #33
0
def propertyManagerSetUp(test):
    sectionsSetUp(test)

    from OFS.interfaces import IPropertyManager

    class MockPortal(object):
        implements(IPropertyManager)

        _properties = (
            {'id':'title', 'type': 'string', 'mode': 'w'},
            {'id':'description', 'type': 'string', 'mode': 'w'},
            {'id':'encoding', 'type': 'string', 'mode': 'w'},
            {'id':'author', 'type': 'string', 'mode': 'w'}
        )

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notatcontent'):
                return object()
            self._last_path = path
            return self

        def _propertyMap(self):
            return self._properties

        def getProperty(self, id, d=None):
            return 'value'

        def propdict(self):
            d={}
            for p in self._properties:
                d[p['id']]=p
            return d

        updated = ()
        def _updateProperty(self, id, value):
            self.updated += ((self._last_path, id, value))

    portal = MockPortal()
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    class PropertyManagerSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(PropertyManagerSource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notatcontent'),
                dict(_path='spam/eggs/foo', _excluded_properties=('encoding',)),
            )

    provideUtility(PropertyManagerSource,
        name=u'quintagroup.transmogrifier.tests.propertymanagersource')
def binarySetUp(test):
    sectionsSetUp(test)

    from Products.Archetypes.interfaces import IBaseObject

    class MockPortal(object):
        implements(IBaseObject)

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notatcontent'):
                return object()
            self._last_path = path
            return self

        fields = ['id', 'title', 'file', 'image']

        def Schema(self):
            return dict.fromkeys(self.fields)

        def isBinary(self, field):
            return field in ('file', 'image')

        _current_field = None
        def getField(self, field):
            self._current_field = field
            return self

        def getBaseUnit(self, obj):
            return self

        def getFilename(self):
            if self._current_field == 'file':
                return 'archive.tar.gz'
            else:
                return ''

        def getContentType(self):
            if self._current_field == 'file':
                return 'application/x-tar'
            else:
                return 'image/png'

        def getRaw(self):
            if self._current_field == 'file':
                return 'binary data'
            else:
                return 'image'

        def getMutator(self, obj):
            return self

        updated = ()
        def __call__(self, data, filename=None, mimetype=None):
            self.updated += (filename, mimetype, data)

    portal = MockPortal()
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    class BinarySource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(BinarySource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notatcontent'),
                dict(_path='spam/eggs/foo'),
            )

    provideUtility(BinarySource,
        name=u'quintagroup.transmogrifier.tests.binarysource')
Пример #35
0
def portletsSetUp(test):
    sectionsSetUp(test)

    from zope.interface import Interface
    from zope.annotation.interfaces import IAttributeAnnotatable
    from plone.portlets.interfaces import ILocalPortletAssignable

    # this bases class adds __of__ method
    from Acquisition import Implicit

    class MockPortal(Implicit):
        implements(IAttributeAnnotatable, ILocalPortletAssignable)

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notassignable'):
                return object()
            self._last_path = path
            return self

        def getPhysicalPath(self):
            return [''] + self._last_path.split('/')

    portal = MockPortal()
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    class PortletsSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(PortletsSource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notassignable'),
                dict(_path='assignable'),
                dict(_path='other-assignable', 
                    files=dict(portlets=dict(
                        name='.portlets.xml',
                        data="""<?xml version="1.0" encoding="utf-8"?>
<portlets>
  <assignment category="context" key="/other-assignable" manager="plone.leftcolumn" name="habra-rss" type="portlets.rss">
    <property name="count">
      20
    </property>
    <property name="url">
      http://habrahabr.ru/rss/
    </property>
    <property name="portlet_title">
      Habrahabr RSS feed
    </property>
    <property name="timeout">
      120
    </property>
  </assignment>
  <blacklist category="user" manager="plone.leftcolumn" status="block"/>
  <blacklist category="group" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="content_type" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="context" manager="plone.leftcolumn" status="acquire"/>
</portlets>
""")
                    )
                )
            )

    provideUtility(PortletsSource,
        name=u'quintagroup.transmogrifier.tests.portletssource')

    class PortletsSource2(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(PortletsSource2, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='other-assignable',
                    files=dict(portlets=dict(
                        name='.portlets.xml',
                        data="""<?xml version="1.0" encoding="utf-8"?>
<portlets>
  <assignment category="context" key="/other-assignable" manager="plone.leftcolumn" name="sumno-rss-2" type="portlets.rss">
    <property name="count">
      30
    </property>
    <property name="url">
      http://sumno.com/rss
    </property>
    <property name="portlet_title">
      Sumno RSS feed
    </property>
    <property name="timeout">
      360
    </property>
  </assignment>
  <blacklist category="user" manager="plone.leftcolumn" status="block"/>
  <blacklist category="group" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="content_type" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="context" manager="plone.leftcolumn" status="acquire"/>
</portlets>
""")
                    )
                )
            )
    provideUtility(PortletsSource2,
       name=u'quintagroup.transmogrifier.tests.portletssource2')

    # prepare the one portlet for testing
    from zope.interface import alsoProvides
    from zope.component import getUtility, getMultiAdapter
    from zope.component.interfaces import IFactory
    from zope.component.factory import Factory

    from plone.portlets.manager import PortletManager
    from plone.portlets.interfaces import IPortletManager, IPortletType, \
        IPortletAssignmentMapping
    from plone.portlets.registration import PortletType

    from plone.app.portlets.assignable import localPortletAssignmentMappingAdapter
    from plone.portlets.assignable import LocalPortletAssignmentManager
    from plone.app.portlets.interfaces import IPortletTypeInterface
    from plone.portlets.interfaces import  ILocalPortletAssignmentManager
    from plone.portlets.constants import USER_CATEGORY
    # from plone.app.portlets.browser.interfaces import IPortletAdding
    from plone.app.portlets.portlets.rss import IRSSPortlet, Assignment #, Renderer, AddForm, EditForm

    # register portlet manager and assignment mapping adapter
    manager = PortletManager()
    provideUtility(manager, IPortletManager, name='plone.leftcolumn')
    provideAdapter(localPortletAssignmentMappingAdapter)
    provideAdapter(LocalPortletAssignmentManager)
    mapping = getMultiAdapter((portal, manager), IPortletAssignmentMapping)
    assignable = getMultiAdapter((portal, manager), ILocalPortletAssignmentManager)
    test.globs['mapping'] = mapping
    test.globs['assignable'] = assignable

    # register portlet (this is what plone:portlet zcml directive does)
    PORTLET_NAME = 'portlets.rss'
    alsoProvides(IRSSPortlet, IPortletTypeInterface)
    provideUtility(provides=IPortletTypeInterface, name=PORTLET_NAME, component=IRSSPortlet)
    provideUtility(provides=IFactory, name=PORTLET_NAME, component=Factory(Assignment))

    # register a portlet type (this is what <portlet /> element in portlets.xml
    # does)
    portlet = PortletType()
    portlet.title = 'RSS Feed'
    portlet.description = 'A portlet which can receive and render an RSS feed.'
    portlet.addview = PORTLET_NAME
    portlet.for_ = [Interface]
    provideUtility(component=portlet, provides=IPortletType, 
        name=PORTLET_NAME)

    # add a portlet and configure it (this is done on @@manage-portlets view)
    assignment = getUtility(IFactory, name=PORTLET_NAME)()
    mapping['rss'] = assignment
    portlet_interface = getUtility(IPortletTypeInterface, name=PORTLET_NAME)
    data = {
        'portlet_title': u'RSS feed',
        'count': 10,
        'url': u'http://sumno.com/feeds/main-page/',
        'timeout': 60
    }
    for k, v in data.items():
        field = portlet_interface.get(k)
        field = field.bind(assignment)
        field.validate(v)
        field.set(assignment, v)
    # set blacklists for user category to 'block'
    assignable.setBlacklistStatus(USER_CATEGORY, True)
Пример #36
0
def writerSetUp(test):
    sectionsSetUp(test)

    class MockExportContext(object):
        def __init__( self, *args, **kwargs):
            self.args = args
            for k, v in kwargs.items():
                setattr(self, k, v)
            self._wrote = []

        def __getitem__(self, name):
            return getattr(self, name, None)

        def __contains__(self, name):
            return hasattr(self, name)

        def writeDataFile(self, filename, text, content_type, subdir=None):
            filename = '%s/%s' % (subdir, filename)
            self._wrote.append((filename, text, content_type))

        def __repr__(self):
            s = " ".join(["%s=%s" % (k,v) for k,v in self.__dict__.items()])
            return "<%s %s>" % (self.__class__.__name__, s)


    from Products.GenericSetup import context

    context.DirectoryExportContext = type('Directory', (MockExportContext,), {})
    context.TarballExportContext = type('Tarball', (MockExportContext,), {})
    context.SnapshotExportContext = type('Snapshot', (MockExportContext,), {})

    class WriterSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(WriterSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='spam/eggs/foo'),
                dict(_files=dict(mock=dict(name='.first.xml', data='some data'))),
                dict(_path='spam/eggs/foo',
                     _files=dict(mock=dict(name='.first.xml', data='some data'),
                                 other=dict(name='.second.xml', data='other data'))),
                dict(_path='other/path',
                     _files=dict(mock=dict(name='.third.xml', data='some data')))
            )

    provideUtility(WriterSource,
        name=u'quintagroup.transmogrifier.tests.writersource')

    class SingleItemSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(SingleItemSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='', _files={}),
            )

    provideUtility(SingleItemSource,
        name=u"quintagroup.transmogrifier.tests.singleitemsource")
Пример #37
0
def catalogSourceSetUp(test):
    sectionsSetUp(test)

    class MockContent(dict):
        def __init__(self, **kw):
            self.update(kw)
            self['id'] = self.getId

        def getPath(self):
            return self['path']

        @property
        def getId(self):
            path = self.getPath()
            return path.rsplit('/', 1)[-1]

        @property
        def portal_type(self):
            return self['portal_type']

        @property
        def is_folderish(self):
            return self['portal_type'] == 'Folder' and True or False

    class MockPortal(dict):

        content = ()
        def __call__(self, **kw):
            res = []
            for obj in self.content:
                matched = True
                for index, query in kw.items():
                    if index not in obj:
                        matched = False
                        break
                    if matched and index == 'modified':
                        if isinstance(query, dict):
                            value = query['query']
                            range_ = query['range']
                            if range_ == 'min' and DateTime(obj[index]) >= DateTime(value):
                                matched = True
                            elif range_ == 'max' and DateTime(obj[index]) <= DateTime(value):
                                matched = True
                            else:
                                matched = False
                        else:
                            if DateTime(obj[index]) == DateTime(query):
                                matched = True
                            else:
                                matched = False
                    elif matched and index == 'path':
                        if obj[index].startswith(query):
                            matched = True
                        else:
                            matched = False
                    elif matched:
                        if obj[index] == query:
                            matched = True
                        else:
                            matched = False
                if matched:
                    res.append(obj)

            return res

    portal = MockPortal()
    doc1 = MockContent(path='/plone/document1', portal_type='Document',
        modified='2008-11-01T12:00:00Z')
    folder1 = MockContent(path='/plone/folder1', portal_type='Folder',
        modified='2008-11-01T12:00:00Z')
    doc2 = MockContent(path='/plone/folder1/document2', portal_type='Document',
        modified='2008-11-02T12:00:00Z')
    doc3 = MockContent(path='/plone/folder1/document3', portal_type='Document',
        modified='2008-11-02T12:00:00Z')
    folder2 = MockContent(path='/plone/folder2', portal_type='Folder',
        modified='2008-11-02T12:00:00Z')
    doc4 = MockContent(path='/plone/folder2/document4', portal_type='Document',
        modified='2008-11-01T12:00:00Z')
    comment = MockContent(path='/plone/folder2/document4/talkback/1234567890', portal_type='Discussion Item',
        modified='2008-11-02T12:00:00Z')
    # items are sorted on their modification date
    portal.content = (doc1, folder1, folder2, doc2, doc3, doc4, comment)

    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']
def marshallSetUp(test):
    sectionsSetUp(test)

    from Products.Archetypes.interfaces import IBaseObject

    class Field(object):
        def __init__(self, name):
            self.name = name
            self.obj = None

        def getAccessor(self, obj):
            self.obj = obj
            return self

        def getMutator(self, obj):
            self.obj = obj
            return self

        def __call__(self, value=None):
            if value is None:
                return self.obj.fields[self.name]
            else:
                self.obj.fields[self.name] = value

    class MockBase(object):
        def __init__(self, effective=None):
            self.fields = {
                'effectiveDate': effective,
                'modification_date': 'changed',
            }

        def checkCreationFlag(self):
            return True

        def unmarkCreationFlag(self):
            pass

        def at_post_create_script(self):
            pass

        def at_post_edit_script(self):
            pass

        indexed = ()
        def indexObject(self):
            self.indexed += (self._last_path,)

        def getField(self, fname):
            return Field(fname)

    class MockCriterion(MockBase):
        implements(IBaseObject)
        _last_path = None
        indexed = ()
        def indexObject(self):
            self.indexed += (self._last_path,)

    class MockPortal(MockBase):
        implements(IBaseObject)

        criterion = MockCriterion('not changed')

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path == 'topic/criterion':
                self._last_path = path
                self.criterion._last_path = path
                return self.criterion
            if path.endswith('/notatcontent'):
                return object()
            self._last_path = path
            return self

        def getId(self):
            return "plone"

        indexed = ()
        def indexObject(self):
            self.indexed += (self._last_path,)

        updatedRoles = False
        def updateRoleMappings(self):
            self.updatedRoles = True

        reindexed = False
        def reindexIndex(self, name, extra=None):
            self.reindexed = True

        marshalled = ()
        def marshall(self, instance, **kwargs):
            self.marshalled += ((self._last_path, kwargs.get('atns_exclude')),)
            # Marshall often fails to export topic criteria
            if isinstance(instance, MockCriterion):
                return None, None, None
            else:
                return None, None, "marshalled"

        demarshalled = ()
        def demarshall(self, instance, data):
            # we don't need to test Marshall product, only check if we call it's components
            self.demarshalled += (self._last_path,)

    portal = MockPortal()
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    from Products.Marshall import registry
    def getComponent(name):
        return portal
    registry.getComponent = getComponent

    class MarshallSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(MarshallSource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='spam/eggs/foo', _excluded_fields=('file', 'image')),
                dict(_path='topic/criterion'),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notatcontent', 
                     _files=dict(marshall=dict(data='xml', name='.marshall.xml'))),
            )
    provideUtility(MarshallSource,
        name=u'quintagroup.transmogrifier.tests.marshallsource')
def commentsSetUp(test):
    sectionsSetUp(test)

    class MockDiscussionItem(object):
        creator = 'creator'
        modified = 'date'

        def __init__(self, reply, text=""):
            self.in_reply_to = reply
            self.text = text

        def __of__(self, container):
            return self

        def getMetadataHeaders(self):
            return []

        def setMetadata(self, headers):
            pass

        def Creator(self):
            return self.creator

        def addCreator(self, creator):
            self.creator = creator

        def ModificationDate(self):
            return self.modified

        def setModificationDate(self, date):
            self.modified = date

        def setFormat(self, format):
            pass

        def _edit(self, text=None):
            self.text = text

        def indexObject(self):
            pass

        def __repr__(self):
            return "<DicussionItem %s %s %s %s>" % (
                self.Creator(),
                self.ModificationDate(),
                self.in_reply_to,
                self.text
                )

    from Products.CMFDefault import DiscussionItem
    DiscussionItem.DiscussionItem = MockDiscussionItem

    class MockPortal(object):
        _discussion = {
            '1': MockDiscussionItem(None, 'comment to content'),
            '2': MockDiscussionItem('1', 'reply to first comment'),
            '3': MockDiscussionItem(None, 'other comment to content')
        }
        _container = {}

        @property
        def talkback(self):
            return self

        def objectItems(self):
            l = self._discussion.items()
            l.sort(key=lambda x: int(x[0]))
            return l

        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notdiscussable'):
                return object()
            return self

        def getDiscussionFor(self, obj):
            return self

    portal = MockPortal()
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    class CommentsSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(CommentsSource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notdiscussable'),
                dict(_path='spam/eggs/foo'),
            )

    provideUtility(CommentsSource,
        name=u'quintagroup.transmogrifier.tests.commentssource')
Пример #40
0
def aTSchemaUpdaterSetUp(test):
    sectionsSetUp(test)

    from Products.Archetypes.interfaces import IBaseObject
    class MockPortal(object):
        implements(IBaseObject)

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notatcontent'):
                return object()
            self._last_path = path
            return self

        _last_field = None
        def getField(self, name):
            if name.startswith('field'):
                self._last_field = name
                return self

        def get(self, ob):
            if self._last_field.endswith('notchanged'):
                return 'nochange'
            if self._last_field.endswith('unicode'):
                return u'\xe5'.encode('utf8')

        @property
        def accessor(self):
            if self._last_field in ('fieldone',):
                return 'accessor_method'
            else:
                return None

        def accessor_method(self):
            return '%s-by-mutator' % self.get(self)

        updated = ()
        def set(self, ob, val):
            self.updated += ((self._last_path, self._last_field, val),)

        @property
        def mutator(self):
            if self._last_field in ('fieldone',):
                return 'mutator_method'
            else:
                return None

        def mutator_method(self, value):
            return self.set(self, '%s-by-mutator' % value)

        def checkCreationFlag(self):
            return len(self.updated) % 2

        def unmarkCreationFlag(self):
            pass

        def at_post_create_script(self):
            pass

        def at_post_edit_script(self):
            pass

    test.globs['plone'] = MockPortal()
    test.globs['transmogrifier'].context = test.globs['plone']

    class SchemaSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(SchemaSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='/spam/eggs/foo', fieldone='one value',
                     fieldtwo=2, nosuchfield='ignored',
                     fieldnotchanged='nochange', fieldunicode=u'\xe5',),
                dict(_path='not/existing/bar', fieldone='one value',
                     title='Should not be updated, not an existing path'),
                dict(fieldone='one value',
                     title='Should not be updated, no path'),
                dict(_path='/spam/eggs/notatcontent', fieldtwo=2,
                     title='Should not be updated, not an AT base object'),
            )
    provideUtility(SchemaSource,
        name=u'plone.app.transmogrifier.tests.schemasource')
def propertyManagerSetUp(test):
    sectionsSetUp(test)

    from OFS.interfaces import IPropertyManager

    class MockPortal(object):
        implements(IPropertyManager)

        _properties = (
            {'id':'title', 'type': 'string', 'mode': 'w'},
            {'id':'description', 'type': 'string', 'mode': 'w'},
            {'id':'encoding', 'type': 'string', 'mode': 'w'},
            {'id':'author', 'type': 'string', 'mode': 'w'}
        )

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notatcontent'):
                return object()
            self._last_path = path
            return self

        def _propertyMap(self):
            return self._properties

        def getProperty(self, id, d=None):
            return 'value'

        def propdict(self):
            d={}
            for p in self._properties:
                d[p['id']]=p
            return d

        updated = ()
        def _updateProperty(self, id, value):
            self.updated += ((self._last_path, id, value))

    portal = MockPortal()
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    class PropertyManagerSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(PropertyManagerSource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notatcontent'),
                dict(_path='spam/eggs/foo', _excluded_properties=('encoding',)),
            )

    provideUtility(PropertyManagerSource,
        name=u'quintagroup.transmogrifier.tests.propertymanagersource')
def writerSetUp(test):
    sectionsSetUp(test)

    class MockExportContext(object):
        def __init__( self, *args, **kwargs):
            self.args = args
            for k, v in kwargs.items():
                setattr(self, k, v)
            self._wrote = []

        def __getitem__(self, name):
            return getattr(self, name, None)

        def __contains__(self, name):
            return hasattr(self, name)

        def writeDataFile(self, filename, text, content_type, subdir=None):
            filename = '%s/%s' % (subdir, filename)
            self._wrote.append((filename, text, content_type))

        def __repr__(self):
            s = " ".join(["%s=%s" % (k,v) for k,v in self.__dict__.items()])
            return "<%s %s>" % (self.__class__.__name__, s)


    from Products.GenericSetup import context

    context.DirectoryExportContext = type('Directory', (MockExportContext,), {})
    context.TarballExportContext = type('Tarball', (MockExportContext,), {})
    context.SnapshotExportContext = type('Snapshot', (MockExportContext,), {})

    class WriterSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(WriterSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='spam/eggs/foo'),
                dict(_files=dict(mock=dict(name='.first.xml', data='some data'))),
                dict(_path='spam/eggs/foo',
                     _files=dict(mock=dict(name='.first.xml', data='some data'),
                                 other=dict(name='.second.xml', data='other data'))),
                dict(_path='other/path',
                     _files=dict(mock=dict(name='.third.xml', data='some data')))
            )

    provideUtility(WriterSource,
        name=u'quintagroup.transmogrifier.tests.writersource')

    class SingleItemSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(SingleItemSource, self).__init__(*args, **kw)
            self.sample = (
                dict(_path='', _files={}),
            )

    provideUtility(SingleItemSource,
        name=u"quintagroup.transmogrifier.tests.singleitemsource")
Пример #43
0
def binarySetUp(test):
    sectionsSetUp(test)

    from Products.Archetypes.interfaces import IBaseObject

    class MockPortal(object):
        implements(IBaseObject)

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notatcontent'):
                return object()
            self._last_path = path
            return self

        fields = ['id', 'title', 'file', 'image']

        def Schema(self):
            return dict.fromkeys(self.fields)

        def isBinary(self, field):
            return field in ('file', 'image')

        _current_field = None
        def getField(self, field):
            self._current_field = field
            return self

        def getBaseUnit(self, obj):
            return self

        def getFilename(self):
            if self._current_field == 'file':
                return 'archive.tar.gz'
            else:
                return ''

        def getContentType(self):
            if self._current_field == 'file':
                return 'application/x-tar'
            else:
                return 'image/png'

        def getRaw(self):
            if self._current_field == 'file':
                return 'binary data'
            else:
                return 'image'

        def getMutator(self, obj):
            return self

        updated = ()
        def __call__(self, data, filename=None, mimetype=None):
            self.updated += (filename, mimetype, data)

    portal = MockPortal()
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    class BinarySource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(BinarySource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notatcontent'),
                dict(_path='spam/eggs/foo'),
            )

    provideUtility(BinarySource,
        name=u'quintagroup.transmogrifier.tests.binarysource')
def dataCorrectorSetUp(test):
    sectionsSetUp(test)

    class MockPortal(object):
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notadaptable'):
                return object()
            return self

    portal = MockPortal()
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    from collective.transmogrifier.interfaces import ITransmogrifier
    from quintagroup.transmogrifier.interfaces import IExportDataCorrector, \
        IImportDataCorrector

    class MockExportAdapter(object):
        implements(IExportDataCorrector)
        adapts(MockPortal, ITransmogrifier)
        def __init__(self, context, transmogrifier):
            self.context = context
            self.transmogrifier = transmogrifier

        def __call__(self, data):
            return "modified export data"

    provideAdapter(MockExportAdapter, name="marshall")

    class MockImportAdapter(object):
        implements(IImportDataCorrector)
        adapts(MockPortal, ITransmogrifier)
        def __init__(self, context, transmogrifier):
            self.context = context
            self.transmogrifier = transmogrifier

        def __call__(self, data):
            return "modified import data"

    provideAdapter(MockImportAdapter, name="manifest")

    class DataCorrectorSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(DataCorrectorSource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_files=dict(marshall="item hasn't path")),
                dict(_path='spam/eggs/foo'),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notadaptable', _files=dict(marshall="object isn't adaptable")),
                dict(_path='spam/eggs/foo',
                     _files=dict(marshall='marshall data', unchanged='this must be unchanged')),
                dict(_path='spam/eggs/foo',
                     _files=dict(manifest='manifest data', unchanged='this must be unchanged')),
            )

    provideUtility(DataCorrectorSource,
        name=u'quintagroup.transmogrifier.tests.datacorrectorsource')
def portletsSetUp(test):
    sectionsSetUp(test)

    from zope.interface import Interface
    from zope.annotation.interfaces import IAttributeAnnotatable
    from plone.portlets.interfaces import ILocalPortletAssignable

    # this bases class adds __of__ method
    from Acquisition import Implicit

    class MockPortal(Implicit):
        implements(IAttributeAnnotatable, ILocalPortletAssignable)

        _last_path = None
        def unrestrictedTraverse(self, path, default):
            if path[0] == '/':
                return default # path is absolute
            if isinstance(path, unicode):
                return default
            if path == 'not/existing/bar':
                return default
            if path.endswith('/notassignable'):
                return object()
            self._last_path = path
            return self

        def getPhysicalPath(self):
            return [''] + self._last_path.split('/')

    portal = MockPortal()
    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']

    class PortletsSource(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(PortletsSource, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='not/existing/bar'),
                dict(_path='spam/eggs/notassignable'),
                dict(_path='assignable'),
                dict(_path='other-assignable', 
                    files=dict(portlets=dict(
                        name='.portlets.xml',
                        data="""<?xml version="1.0" encoding="utf-8"?>
<portlets>
  <assignment category="context" key="/other-assignable" manager="plone.leftcolumn" name="habra-rss" type="portlets.rss">
    <property name="count">
      20
    </property>
    <property name="url">
      http://habrahabr.ru/rss/
    </property>
    <property name="portlet_title">
      Habrahabr RSS feed
    </property>
    <property name="timeout">
      120
    </property>
  </assignment>
  <blacklist category="user" manager="plone.leftcolumn" status="block"/>
  <blacklist category="group" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="content_type" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="context" manager="plone.leftcolumn" status="acquire"/>
</portlets>
""")
                    )
                )
            )

    provideUtility(PortletsSource,
        name=u'quintagroup.transmogrifier.tests.portletssource')

    class PortletsSource2(SampleSource):
        classProvides(ISectionBlueprint)
        implements(ISection)

        def __init__(self, *args, **kw):
            super(PortletsSource2, self).__init__(*args, **kw)
            self.sample = (
                dict(),
                dict(_path='other-assignable',
                    files=dict(portlets=dict(
                        name='.portlets.xml',
                        data="""<?xml version="1.0" encoding="utf-8"?>
<portlets>
  <assignment category="context" key="/other-assignable" manager="plone.leftcolumn" name="sumno-rss-2" type="portlets.rss">
    <property name="count">
      30
    </property>
    <property name="url">
      http://sumno.com/rss
    </property>
    <property name="portlet_title">
      Sumno RSS feed
    </property>
    <property name="timeout">
      360
    </property>
  </assignment>
  <blacklist category="user" manager="plone.leftcolumn" status="block"/>
  <blacklist category="group" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="content_type" manager="plone.leftcolumn" status="acquire"/>
  <blacklist category="context" manager="plone.leftcolumn" status="acquire"/>
</portlets>
""")
                    )
                )
            )
    provideUtility(PortletsSource2,
       name=u'quintagroup.transmogrifier.tests.portletssource2')

    # prepare the one portlet for testing
    from zope.interface import alsoProvides
    from zope.component import getUtility, getMultiAdapter
    from zope.component.interfaces import IFactory
    from zope.component.factory import Factory

    from plone.portlets.manager import PortletManager
    from plone.portlets.interfaces import IPortletManager, IPortletType, \
        IPortletAssignmentMapping
    from plone.portlets.registration import PortletType

    from plone.app.portlets.assignable import localPortletAssignmentMappingAdapter
    from plone.portlets.assignable import LocalPortletAssignmentManager
    from plone.app.portlets.interfaces import IPortletTypeInterface
    from plone.portlets.interfaces import  ILocalPortletAssignmentManager
    from plone.portlets.constants import USER_CATEGORY
    # from plone.app.portlets.browser.interfaces import IPortletAdding
    from plone.app.portlets.portlets.rss import IRSSPortlet, Assignment #, Renderer, AddForm, EditForm

    # register portlet manager and assignment mapping adapter
    manager = PortletManager()
    provideUtility(manager, IPortletManager, name='plone.leftcolumn')
    provideAdapter(localPortletAssignmentMappingAdapter)
    provideAdapter(LocalPortletAssignmentManager)
    mapping = getMultiAdapter((portal, manager), IPortletAssignmentMapping)
    assignable = getMultiAdapter((portal, manager), ILocalPortletAssignmentManager)
    test.globs['mapping'] = mapping
    test.globs['assignable'] = assignable

    # register portlet (this is what plone:portlet zcml directive does)
    PORTLET_NAME = 'portlets.rss'
    alsoProvides(IRSSPortlet, IPortletTypeInterface)
    provideUtility(provides=IPortletTypeInterface, name=PORTLET_NAME, component=IRSSPortlet)
    provideUtility(provides=IFactory, name=PORTLET_NAME, component=Factory(Assignment))

    # register a portlet type (this is what <portlet /> element in portlets.xml
    # does)
    portlet = PortletType()
    portlet.title = 'RSS Feed'
    portlet.description = 'A portlet which can receive and render an RSS feed.'
    portlet.addview = PORTLET_NAME
    portlet.for_ = [Interface]
    provideUtility(component=portlet, provides=IPortletType, 
        name=PORTLET_NAME)

    # add a portlet and configure it (this is done on @@manage-portlets view)
    assignment = getUtility(IFactory, name=PORTLET_NAME)()
    mapping['rss'] = assignment
    portlet_interface = getUtility(IPortletTypeInterface, name=PORTLET_NAME)
    data = {
        'portlet_title': u'RSS feed',
        'count': 10,
        'url': u'http://sumno.com/feeds/main-page/',
        'timeout': 60
    }
    for k, v in data.items():
        field = portlet_interface.get(k)
        field = field.bind(assignment)
        field.validate(v)
        field.set(assignment, v)
    # set blacklists for user category to 'block'
    assignable.setBlacklistStatus(USER_CATEGORY, True)
def catalogSourceSetUp(test):
    sectionsSetUp(test)

    class MockContent(dict):
        def __init__(self, **kw):
            self.update(kw)
            self['id'] = self.getId

        def getPath(self):
            return self['path']

        @property
        def getId(self):
            path = self.getPath()
            return path.rsplit('/', 1)[-1]

        @property
        def portal_type(self):
            return self['portal_type']

        @property
        def is_folderish(self):
            return self['portal_type'] == 'Folder' and True or False

    class MockPortal(dict):

        content = ()
        def __call__(self, **kw):
            res = []
            for obj in self.content:
                matched = True
                for index, query in kw.items():
                    if index not in obj:
                        matched = False
                        break
                    if matched and index == 'modified':
                        if isinstance(query, dict):
                            value = query['query']
                            range_ = query['range']
                            if range_ == 'min' and DateTime(obj[index]) >= DateTime(value):
                                matched = True
                            elif range_ == 'max' and DateTime(obj[index]) <= DateTime(value):
                                matched = True
                            else:
                                matched = False
                        else:
                            if DateTime(obj[index]) == DateTime(query):
                                matched = True
                            else:
                                matched = False
                    elif matched and index == 'path':
                        if obj[index].startswith(query):
                            matched = True
                        else:
                            matched = False
                    elif matched:
                        if obj[index] == query:
                            matched = True
                        else:
                            matched = False
                if matched:
                    res.append(obj)

            return res

    portal = MockPortal()
    doc1 = MockContent(path='/plone/document1', portal_type='Document',
        modified='2008-11-01T12:00:00Z')
    folder1 = MockContent(path='/plone/folder1', portal_type='Folder',
        modified='2008-11-01T12:00:00Z')
    doc2 = MockContent(path='/plone/folder1/document2', portal_type='Document',
        modified='2008-11-02T12:00:00Z')
    doc3 = MockContent(path='/plone/folder1/document3', portal_type='Document',
        modified='2008-11-02T12:00:00Z')
    folder2 = MockContent(path='/plone/folder2', portal_type='Folder',
        modified='2008-11-02T12:00:00Z')
    doc4 = MockContent(path='/plone/folder2/document4', portal_type='Document',
        modified='2008-11-01T12:00:00Z')
    comment = MockContent(path='/plone/folder2/document4/talkback/1234567890', portal_type='Discussion Item',
        modified='2008-11-02T12:00:00Z')
    # items are sorted on their modification date
    portal.content = (doc1, folder1, folder2, doc2, doc3, doc4, comment)

    test.globs['plone'] = portal
    test.globs['transmogrifier'].context = test.globs['plone']