Back to index

plone3  3.1.7
test_exportimport.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ZCTextIndex export / import support unit tests.
00014 
00015 $Id: test_exportimport.py 71212 2006-11-20 19:27:48Z yuppie $
00016 """
00017 
00018 import unittest
00019 import Testing
00020 
00021 from Acquisition import Implicit
00022 
00023 from Products.GenericSetup.testing import NodeAdapterTestCase
00024 from Products.GenericSetup.testing import ExportImportZCMLLayer
00025 
00026 _PLEXICON_XML = """\
00027 <object name="foo_plexicon" meta_type="ZCTextIndex Lexicon">
00028  <element name="Whitespace splitter" group="Word Splitter"/>
00029  <element name="Case Normalizer" group="Case Normalizer"/>
00030  <element name="Remove listed stop words only" group="Stop Words"/>
00031 </object>
00032 """
00033 
00034 _ZCTEXT_XML = """\
00035 <index name="foo_zctext" meta_type="ZCTextIndex">
00036  <indexed_attr value="foo_zctext"/>
00037  <indexed_attr value="baz_zctext"/>
00038  <extra name="index_type" value="Okapi BM25 Rank"/>
00039  <extra name="lexicon_id" value="foo_plexicon"/>
00040 </index>
00041 """
00042 
00043 
00044 class _extra:
00045 
00046     pass
00047 
00048 
00049 class DummyCatalog(Implicit):
00050 
00051     pass
00052 
00053 
00054 class ZCLexiconNodeAdapterTests(NodeAdapterTestCase):
00055 
00056     layer = ExportImportZCMLLayer
00057 
00058     def _getTargetClass(self):
00059         from Products.GenericSetup.ZCTextIndex.exportimport \
00060                 import ZCLexiconNodeAdapter
00061 
00062         return ZCLexiconNodeAdapter
00063 
00064     def _populate(self, obj):
00065         from Products.ZCTextIndex.Lexicon import CaseNormalizer
00066         from Products.ZCTextIndex.Lexicon import Splitter
00067         from Products.ZCTextIndex.Lexicon import StopWordRemover
00068         obj._pipeline = (Splitter(), CaseNormalizer(), StopWordRemover())
00069 
00070     def setUp(self):
00071         from Products.ZCTextIndex.ZCTextIndex import PLexicon
00072 
00073         NodeAdapterTestCase.setUp(self)
00074         self._obj = PLexicon('foo_plexicon')
00075         self._XML = _PLEXICON_XML
00076 
00077 
00078 class ZCTextIndexNodeAdapterTests(NodeAdapterTestCase):
00079 
00080     layer = ExportImportZCMLLayer
00081 
00082     def _getTargetClass(self):
00083         from Products.GenericSetup.ZCTextIndex.exportimport \
00084                 import ZCTextIndexNodeAdapter
00085 
00086         return ZCTextIndexNodeAdapter
00087 
00088     def _populate(self, obj):
00089         obj._indexed_attrs = ['foo_zctext', 'baz_zctext']
00090 
00091     def setUp(self):
00092         from Products.ZCTextIndex.ZCTextIndex import PLexicon
00093         from Products.ZCTextIndex.ZCTextIndex import ZCTextIndex
00094 
00095         NodeAdapterTestCase.setUp(self)
00096         catalog = DummyCatalog()
00097         catalog.foo_plexicon = PLexicon('foo_plexicon')
00098         extra = _extra()
00099         extra.lexicon_id = 'foo_plexicon'
00100         extra.index_type='Okapi BM25 Rank'
00101         self._obj = ZCTextIndex('foo_zctext', extra=extra,
00102                                 caller=catalog).__of__(catalog)
00103         self._XML = _ZCTEXT_XML
00104 
00105 
00106 def test_suite():
00107     return unittest.TestSuite((
00108         unittest.makeSuite(ZCLexiconNodeAdapterTests),
00109         unittest.makeSuite(ZCTextIndexNodeAdapterTests),
00110         ))
00111 
00112 if __name__ == '__main__':
00113     from Products.GenericSetup.testing import run
00114     run(test_suite())