1 | import unittest |
---|
2 | #import Testing |
---|
3 | |
---|
4 | #from zope.interface import implements |
---|
5 | from zope.component import getMultiAdapter |
---|
6 | from zope.component import provideUtility |
---|
7 | |
---|
8 | from Products.Five import zcml |
---|
9 | from Products.GenericSetup.interfaces import IBody |
---|
10 | from Products.GenericSetup.ZCatalog.tests import test_exportimport |
---|
11 | |
---|
12 | from Products.GenericSetup.testing import DummyLogger |
---|
13 | from Products.GenericSetup.testing import DummySetupEnviron |
---|
14 | |
---|
15 | from quintagroup.catalogupdater.interfaces import ICatalogUpdater |
---|
16 | |
---|
17 | from Products.CMFPlone.utils import getFSVersionTuple |
---|
18 | PLONEFOUR = getFSVersionTuple()[0] == 4 and True or False |
---|
19 | |
---|
20 | _CATALOG_BODY = test_exportimport._CATALOG_BODY |
---|
21 | _ZCTEXT_XML = test_exportimport._ZCTEXT_XML |
---|
22 | |
---|
23 | _CATALOG_UPDATE_BODY = """\ |
---|
24 | <?xml version="1.0"?> |
---|
25 | <object name="foo_catalog"> |
---|
26 | %s |
---|
27 | <index name="foo_text" remove="True"/> |
---|
28 | <index name="foo_text" meta_type="ZCTextIndex"> |
---|
29 | <indexed_attr value="foo_text"/> |
---|
30 | <extra name="index_type" value="Okapi BM25 Rank"/> |
---|
31 | <extra name="lexicon_id" value="foo_plexicon"/> |
---|
32 | </index> |
---|
33 | <index name="non_existing" remove="True"/> |
---|
34 | <column value="non_existing" remove="True"/> |
---|
35 | <column value="bacon" remove="True"/> |
---|
36 | <column value="eggs" update="True"/> |
---|
37 | <column value="spam" update="True"/> |
---|
38 | </object> |
---|
39 | """ % (PLONEFOUR and '<object name="old_plexicon" remove="True"/>' or \ |
---|
40 | '<object name="foo_vocabulary" remove="True"/>') |
---|
41 | |
---|
42 | |
---|
43 | class DummyCatalogUpdaterUtility: |
---|
44 | _logger = None |
---|
45 | |
---|
46 | def updateMetadata4All(self, catalog, columns): |
---|
47 | self._logger.info("%s:%s" % (catalog.id, columns)) |
---|
48 | |
---|
49 | |
---|
50 | class CatalogUpdaterZCMLLayer(test_exportimport.ZCatalogXMLAdapterTests.layer): |
---|
51 | |
---|
52 | @classmethod |
---|
53 | def setUp(cls): |
---|
54 | # Not import 'configure.zcml' - because it register 'catalog_updater' |
---|
55 | # utility, which we override with DummyCatalogUpdaterUtility |
---|
56 | test_exportimport.ZCatalogXMLAdapterTests.layer.setUp() |
---|
57 | import quintagroup.catalogupdater |
---|
58 | zcml.load_config('overrides.zcml', quintagroup.catalogupdater) |
---|
59 | |
---|
60 | |
---|
61 | class CatalogUpdaterXMLAdapterTest(test_exportimport.ZCatalogXMLAdapterTests): |
---|
62 | |
---|
63 | layer = CatalogUpdaterZCMLLayer |
---|
64 | |
---|
65 | def _getTargetClass(self): |
---|
66 | from quintagroup.catalogupdater.exportimport.catalogupdater \ |
---|
67 | import CatalogUpdaterXMLAdapter |
---|
68 | return CatalogUpdaterXMLAdapter |
---|
69 | |
---|
70 | def setUp(self): |
---|
71 | super(CatalogUpdaterXMLAdapterTest, self).setUp() |
---|
72 | |
---|
73 | self.logger = DummyLogger('CatalogUpdaterLogger', []) |
---|
74 | dummy_cu = DummyCatalogUpdaterUtility() |
---|
75 | dummy_cu._logger = self.logger |
---|
76 | provideUtility(dummy_cu, ICatalogUpdater, name="catalog_updater") |
---|
77 | |
---|
78 | def getLastMessage(self): |
---|
79 | messages = getattr(self.logger, '_messages', []) |
---|
80 | return messages[-1] or [None, ] * 3 |
---|
81 | |
---|
82 | def test_body_set_update(self): |
---|
83 | # Assert that the catalog ends up the way we expect it to. |
---|
84 | self._populate_special(self._obj) |
---|
85 | context = DummySetupEnviron() |
---|
86 | context._should_purge = False |
---|
87 | adapted = getMultiAdapter((self._obj, context), IBody) |
---|
88 | adapted.body = _CATALOG_UPDATE_BODY |
---|
89 | self.assertEqual(adapted.body, _CATALOG_BODY % ('', _ZCTEXT_XML, '')) |
---|
90 | |
---|
91 | message = self.getLastMessage() |
---|
92 | self.assertEqual(message[-1], "foo_catalog:['eggs', 'spam']", |
---|
93 | "Not updated columns in catalog") |
---|
94 | |
---|
95 | |
---|
96 | def test_suite(): |
---|
97 | return unittest.TestSuite(( |
---|
98 | unittest.makeSuite(CatalogUpdaterXMLAdapterTest), |
---|
99 | )) |
---|
100 | |
---|
101 | if __name__ == '__main__': |
---|
102 | from Products.GenericSetup.testing import run |
---|
103 | run(test_suite()) |
---|