def test_body_set_update(self): self._populate_special(self._obj) context = DummySetupEnviron() context._should_purge = False adapted = getMultiAdapter((self._obj, context), IBody) adapted.body = _CATALOG_UPDATE_BODY self.assertEqual(adapted.body, _CATALOG_BODY % ('', _ZCTEXT_XML))
def test_body_set_update(self): # Assert that the catalog ends up the way we expect it to. self._populate_special(self._obj) context = DummySetupEnviron() context._should_purge = False adapted = getMultiAdapter((self._obj, context), IBody) adapted.body = _CATALOG_UPDATE_BODY self.assertEqual(adapted.body, _CATALOG_BODY % ("", _ZCTEXT_XML, ""))
def test_body_set_update(self): # Assert that the catalog ends up the way we expect it to. self._populate_special(self._obj) context = DummySetupEnviron() context._should_purge = False adapted = getMultiAdapter((self._obj, context), IBody) adapted.body = _CATALOG_UPDATE_BODY self.assertEqual(adapted.body, _CATALOG_BODY % ('', _ZCTEXT_XML, ''))
def test_body_set_update(self): # Assert that the catalog ends up the way we expect it to. self._populate_special(self._obj) context = DummySetupEnviron() context._should_purge = False adapted = getMultiAdapter((self._obj, context), IBody) adapted.body = _CATALOG_UPDATE_BODY self.assertEqual(adapted.body, _CATALOG_BODY % ('', _ZCTEXT_XML, '')) message = self.getLastMessage() self.assertEqual( message[-1], "foo_catalog:['eggs', 'spam']", "Not updated columns in catalog" )
def test_ZCTextIndex(self): from xml.dom.minidom import parseString from Products.ZCTextIndex.ZCTextIndex import PLexicon from Products.ZCTextIndex.ZCTextIndex import ZCTextIndex from Products.GenericSetup.testing import DummySetupEnviron from Products.GenericSetup.ZCTextIndex.exportimport \ import ZCTextIndexNodeAdapter _XML = """\ <index name="foo_zctext" meta_type="ZCTextIndex"> <indexed_attr value="bar"/> <extra name="index_type" value="Okapi BM25 Rank"/> <extra name="lexicon_id" value="foo_plexicon"/> </index> """ environ = DummySetupEnviron() def _no_clear(*a): raise AssertionError("Don't clear me!") catalog = DummyCatalog() catalog.foo_plexicon = PLexicon('foo_plexicon') extra = _extra() extra.lexicon_id = 'foo_plexicon' extra.index_type = 'Okapi BM25 Rank' index = ZCTextIndex('foo_field', extra=extra, field_name='bar', caller=catalog).__of__(catalog) index.clear = _no_clear adapted = ZCTextIndexNodeAdapter(index, environ) adapted.node = parseString(_XML).documentElement # no raise
def test_ZCLexicon(self): from xml.dom.minidom import parseString from Products.GenericSetup.testing import DummySetupEnviron from Products.ZCTextIndex.PipelineFactory import element_factory from Products.GenericSetup.ZCTextIndex.exportimport \ import ZCLexiconNodeAdapter _XML = """\ <object name="foo_plexicon" meta_type="ZCTextIndex Lexicon"> <element name="foo" group="gs"/> <element name="bar" group="gs"/> </object> """ environ = DummySetupEnviron() _before = object(), object(), object() class DummyLexicon(object): _wids, _words, length = _before lex = DummyLexicon() lex._pipeline = foo, bar = object(), object() adapted = ZCLexiconNodeAdapter(lex, environ) element_factory._groups['gs'] = { 'foo': lambda: foo, 'bar': lambda: bar, } try: adapted.node = parseString(_XML).documentElement # no raise finally: del element_factory._groups['gs'] self.assertTrue(lex._wids is _before[0]) self.assertTrue(lex._words is _before[1]) self.assertTrue(lex.length is _before[2])
def test_body_get_special(self): # Assert that the catalog starts out the way we expect it to. self._populate_special(self._obj) context = DummySetupEnviron() adapted = getMultiAdapter((self._obj, context), IBody) self.assertEqual(adapted.body, _CATALOG_BODY % (_LEXICON_XML, _TEXT_XML, _COLUMN_XML))
def _makeOne(self, context=None, environ=None): from Products.GenericSetup.utils import NodeAdapterBase from Products.GenericSetup.testing import DummySetupEnviron class Foo(self._getTargetClass(), NodeAdapterBase): _PROPERTIES = ( {'id': 'foo_boolean', 'type': 'boolean', 'mode': 'wd'}, {'id': 'foo_date', 'type': 'date', 'mode': 'wd'}, {'id': 'foo_float', 'type': 'float', 'mode': 'wd'}, {'id': 'foo_int', 'type': 'int', 'mode': 'wd'}, {'id': 'foo_lines', 'type': 'lines', 'mode': 'wd'}, {'id': 'foo_long', 'type': 'long', 'mode': 'wd'}, {'id': 'foo_string', 'type': 'string', 'mode': 'wd'}, {'id': 'foo_text', 'type': 'text', 'mode': 'wd'}, {'id': 'foo_tokens', 'type': 'tokens', 'mode': 'wd'}, {'id': 'foo_selection', 'type': 'selection', 'select_variable': 'foobarbaz', 'mode': 'wd'}, {'id': 'foo_mselection', 'type': 'multiple selection', 'select_variable': 'foobarbaz', 'mode': 'wd'}, {'id': 'foo_boolean0', 'type': 'boolean', 'mode': 'wd'}, {'id': 'foo_ro', 'type': 'string', 'mode': ''}, {'id': 'foo_int_nodel', 'type': 'int', 'mode': 'w'}, {'id': 'foo_float_nodel', 'type': 'float', 'mode': 'w'}, {'id': 'foo_boolean_nodel', 'type': 'boolean', 'mode': 'w'}, ) if context is None: context = self._makeContext() if environ is None: environ = DummySetupEnviron() return Foo(context, environ)
def setUp(self): from OFS.PropertyManager import PropertyManager obj = PropertyManager('obj') obj.foobarbaz = ('Foo', 'Bar', 'Baz') obj._properties = () obj.manage_addProperty('foo_boolean', '', 'boolean') obj.manage_addProperty('foo_date', '1970/01/01', 'date') obj.manage_addProperty('foo_float', '0', 'float') obj.manage_addProperty('foo_int', '0', 'int') obj.manage_addProperty('foo_lines', '', 'lines') obj.manage_addProperty('foo_long', '0', 'long') obj.manage_addProperty('foo_string', '', 'string') obj.manage_addProperty('foo_text', '', 'text') obj.manage_addProperty('foo_tokens', '', 'tokens') obj.manage_addProperty('foo_selection', 'foobarbaz', 'selection') obj.manage_addProperty('foo_mselection', 'foobarbaz', 'multiple selection') obj.manage_addProperty('foo_boolean0', '', 'boolean') obj.manage_addProperty('foo_ro', '', 'string') obj._properties[-1]['mode'] = '' # Read-only, not exported or purged obj.manage_addProperty('foo_int_nodel', 0, 'int') obj._properties[-1]['mode'] = 'w' # Not deletable obj.manage_addProperty('foo_float_nodel', 0, 'float') obj._properties[-1]['mode'] = 'w' # Not deletable obj.manage_addProperty('foo_boolean_nodel', '', 'boolean') obj._properties[-1]['mode'] = 'w' # Not deletable self.helpers = self._makeOne(obj, DummySetupEnviron())
def test_body_set(self): context = DummySetupEnviron() adapted = getMultiAdapter((self._obj, context), IBody) adapted.body = self._BODY self._verifyImport(self._obj) self.assertEqual(adapted.body, self._BODY) # now in update mode context._should_purge = False adapted = getMultiAdapter((self._obj, context), IBody) adapted.body = self._BODY self._verifyImport(self._obj) self.assertEqual(adapted.body, self._BODY) # and again in update mode adapted = getMultiAdapter((self._obj, context), IBody) adapted.body = self._BODY self._verifyImport(self._obj) self.assertEqual(adapted.body, self._BODY)
def test_blacklist_set(self): obj = self._obj # Register our blacklist gsm = getGlobalSiteManager() gsm.registerUtility(DummyBlacklist(), IComponentsHandlerBlacklist, name=u'dummy') context = DummySetupEnviron() adapted = getMultiAdapter((obj, context), IBody) adapted.body = self._BODY util = queryUtility(IDummyInterface2, name=u'foo') self.failUnless(IDummyInterface.providedBy(util)) self.failUnless(util.verify()) util = queryUtility(IDummyInterface) self.failUnless(util is None) # now in update mode context._should_purge = False adapted = getMultiAdapter((obj, context), IBody) adapted.body = self._BODY util = queryUtility(IDummyInterface2, name=u'foo') self.failUnless(IDummyInterface.providedBy(util)) self.failUnless(util.verify()) util = queryUtility(IDummyInterface) self.failUnless(util is None) # and again in update mode adapted = getMultiAdapter((obj, context), IBody) adapted.body = self._BODY util = queryUtility(IDummyInterface2, name=u'foo') self.failUnless(IDummyInterface.providedBy(util)) self.failUnless(util.verify()) util = queryUtility(IDummyInterface) self.failUnless(util is None)
def _makeOne(self, context=None, environ=None): from Products.GenericSetup.utils import NodeAdapterBase from Products.GenericSetup.testing import DummySetupEnviron class Foo(self._getTargetClass(), NodeAdapterBase): pass if context is None: context = self._makeContext() if environ is None: environ = DummySetupEnviron() return Foo(context, environ)
def test_blacklist_get(self): obj = self._obj self._populate(obj) # Register our blacklist gsm = getGlobalSiteManager() gsm.registerUtility(DummyBlacklist(), IComponentsHandlerBlacklist, name=u'dummy') context = DummySetupEnviron() adapted = getMultiAdapter((obj, context), IBody) body = adapted.body self.failIf('IComponentsHandlerBlacklist' in body) self.failIf('test_components.IDummyInterface"' in body)
def test_FilteredSet(self): from xml.dom.minidom import parseString from Products.PluginIndexes.TopicIndex.FilteredSet \ import PythonFilteredSet from Products.GenericSetup.testing import DummySetupEnviron from Products.GenericSetup.PluginIndexes.exportimport \ import FilteredSetNodeAdapter environ = DummySetupEnviron() def _no_clear(*a): raise AssertionError("Don't clear me!") index = PythonFilteredSet('bar', 'True') index.clear = _no_clear adapted = FilteredSetNodeAdapter(index, environ) adapted.node = parseString(_SET_XML).documentElement # no raise
def test_OddballIndex(self): # Some indexes, e.g. Plone's 'GopipIndex', use ths adapter but don't # have 'indexed_attrs'. from xml.dom.minidom import parseString from Products.GenericSetup.testing import DummySetupEnviron from Products.GenericSetup.PluginIndexes.exportimport \ import PluggableIndexNodeAdapter class Oddball(object): def clear(*a): raise AssertionError("Don't clear me!") index = Oddball() environ = DummySetupEnviron() adapted = PluggableIndexNodeAdapter(index, environ) adapted.node = parseString(_ODDBALL_XML).documentElement # no raise
def test_FieldIndex(self): from xml.dom.minidom import parseString from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex from Products.GenericSetup.testing import DummySetupEnviron from Products.GenericSetup.PluginIndexes.exportimport \ import PluggableIndexNodeAdapter environ = DummySetupEnviron() def _no_clear(*a): raise AssertionError("Don't clear me!") index = FieldIndex('foo_field') index.indexed_attrs = ['bar'] index.clear = _no_clear adapted = PluggableIndexNodeAdapter(index, environ) adapted.node = parseString(_FIELD_XML).documentElement # no raise
def test_DateIndex(self): from xml.dom.minidom import parseString from Products.PluginIndexes.DateIndex.DateIndex import DateIndex from Products.GenericSetup.testing import DummySetupEnviron from Products.GenericSetup.PluginIndexes.exportimport \ import DateIndexNodeAdapter environ = DummySetupEnviron() def _no_clear(*a): raise AssertionError("Don't clear me!") index = DateIndex('foo_date') index._setPropValue('index_naive_time_as_local', True) index.clear = _no_clear adapted = DateIndexNodeAdapter(index, environ) adapted.node = parseString(_DATE_XML).documentElement # no raise
def test_DateRangeIndex(self): from xml.dom.minidom import parseString from Products.PluginIndexes.DateRangeIndex.DateRangeIndex \ import DateRangeIndex from Products.GenericSetup.testing import DummySetupEnviron from Products.GenericSetup.PluginIndexes.exportimport \ import DateRangeIndexNodeAdapter environ = DummySetupEnviron() def _no_clear(*a): raise AssertionError("Don't clear me!") index = DateRangeIndex('foo_daterange') index._since_field = 'bar' index._until_field = 'baz' index.clear = _no_clear adapted = DateRangeIndexNodeAdapter(index, environ) adapted.node = parseString(_DATERANGE_XML).documentElement # no raise
def test_KeywordIndex(self): from xml.dom.minidom import parseString from Products.PluginIndexes.KeywordIndex.KeywordIndex import \ KeywordIndex from ...testing import DummySetupEnviron from ..exportimport import PluggableIndexNodeAdapter environ = DummySetupEnviron() def _no_clear(*a): raise AssertionError("Don't clear me!") index = KeywordIndex('foo_keyword') index.indexed_attrs = ['bar'] index.clear = _no_clear adapted = PluggableIndexNodeAdapter(index, environ) adapted.node = parseString(_KEYWORD_XML).documentElement # no raise
def test_TopicIndex(self): from xml.dom.minidom import parseString from Products.PluginIndexes.TopicIndex.TopicIndex import TopicIndex from Products.GenericSetup.testing import DummySetupEnviron from Products.GenericSetup.PluginIndexes.exportimport \ import TopicIndexNodeAdapter environ = DummySetupEnviron() def _no_clear(*a): raise AssertionError("Don't clear me!") index = TopicIndex('topics') index.addFilteredSet('bar', 'PythonFilteredSet', 'True') index.addFilteredSet('baz', 'PythonFilteredSet', 'False') bar = index.filteredSets['bar'] baz = index.filteredSets['baz'] bar.clear = baz.clear = _no_clear adapted = TopicIndexNodeAdapter(index, environ) adapted.node = parseString(_SET_XML).documentElement # no raise
def test_no_overwrite(self): # make sure we don't overwrite an existing tool when it # already exists and has the same factory context = DummySetupEnviron() context._should_purge = False importer = getMultiAdapter((self._obj, context), IBody) importer.body = self._BODY # <-- triggers the import :( util = queryUtility(IDummyInterface) value = 'bar' util.foo = value # re-retrieve to make sure it's the same object util = queryUtility(IDummyInterface) self.assertEquals(getattr(util, 'foo', None), value) context = DummySetupEnviron() context._should_purge = False importer = getMultiAdapter((self._obj, context), IBody) importer.body = self._BODY # <-- triggers the import :( util = queryUtility(IDummyInterface) self.assertEquals(getattr(util, 'foo', None), value)
def setUp(self): obj = Item('obj') self.helpers = self._makeOne(obj, DummySetupEnviron()) provideAdapter(MarkerInterfacesAdapter, (IItem, )) provideInterface('', IDummyMarker)
def afterSetUp(self): self.sm = getSiteManager(self.portal) self.importer = self.exporter = PortletsXMLAdapter( self.sm, DummySetupEnviron())
def setUp(self): from OFS.ObjectManager import ObjectManager obj = ObjectManager('obj') self.helpers = self._makeOne(obj, DummySetupEnviron())
def test_body_get_special(self): self._populate_special(self._obj) context = DummySetupEnviron() adapted = zapi.getMultiAdapter((self._obj, context), IBody) self.assertEqual(adapted.body, _CATALOG_BODY % (_VOCABULARY_XML, _TEXT_XML))