Commit 48dedecb authored by Łukasz Nowak's avatar Łukasz Nowak

- convert subobject reindexation tests to easy to understand assertions

Instead of relaying on logic of real site, wrap catalogObjectList method and
store list being catalogged paths. Then compare such list with expected result.
Thanks Seb for idea of simple wrapper.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36987 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f5ff59b8
...@@ -39,6 +39,17 @@ from DateTime import DateTime ...@@ -39,6 +39,17 @@ from DateTime import DateTime
from zLOG import LOG from zLOG import LOG
from Products.ERP5Type.tests.Sequence import SequenceList from Products.ERP5Type.tests.Sequence import SequenceList
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.ERP5Type.Globals import PersistentMapping
from Products.ZSQLCatalog.SQLCatalog import Catalog
def catalogObjectListWrapper(self, object_list, method_id_list=None,
disable_cache=0, check_uid=1, idxs=None):
"""Wrapper to mark inside of portal object list of catalogged objects"""
import transaction
portal = self.getPortalObject()
for q in object_list:
portal.catalogged_object_path_dict[q.getPath()] = 1
transaction.commit()
class TestOrderMixin: class TestOrderMixin:
...@@ -69,6 +80,13 @@ class TestOrderMixin: ...@@ -69,6 +80,13 @@ class TestOrderMixin:
user = uf.getUserById('rc').__of__(uf) user = uf.getUserById('rc').__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
def wrap_catalogObjectList(self):
self.original_catalogObjectList = Catalog.catalogObjectList
Catalog.catalogObjectList = catalogObjectListWrapper
def unwrap_catalogObjectList(self):
Catalog.catalogObjectList = self.original_catalogObjectList
def setUpPreferences(self): def setUpPreferences(self):
#create apparel variation preferences #create apparel variation preferences
portal_preferences = self.getPreferenceTool() portal_preferences = self.getPreferenceTool()
...@@ -2843,63 +2861,40 @@ class TestOrder(TestOrderMixin, ERP5TypeTestCase): ...@@ -2843,63 +2861,40 @@ class TestOrder(TestOrderMixin, ERP5TypeTestCase):
def test_subcontent_reindexing(self): def test_subcontent_reindexing(self):
"""Tests, that modification on Order are propagated to lines and cells """Tests, that modification on Order are propagated to lines and cells
during reindxation""" during reindxation"""
organisation1 = self.portal.organisation_module.newContent( self.portal.catalogged_object_path_dict = PersistentMapping()
portal_type='Organisation') transaction.commit()
organisation2 = self.portal.organisation_module.newContent( try:
portal_type='Organisation') # wrap call to catalogObjectList
order = self.portal.getDefaultModule(self.order_portal_type).newContent( self.wrap_catalogObjectList()
portal_type=self.order_portal_type, # prepare test data
source_value=organisation1) order = self.portal.getDefaultModule(self.order_portal_type).newContent(
order_line = order.newContent(portal_type=self.order_line_portal_type) portal_type=self.order_portal_type)
inner_order_line = order.newContent(portal_type=self.order_line_portal_type order_line = order.newContent(portal_type=self.order_line_portal_type)
).newContent(portal_type=self.order_line_portal_type) inner_order_line = order.newContent(
order_cell = order.newContent(portal_type=self.order_line_portal_type)\ portal_type=self.order_line_portal_type).newContent(
.newContent(portal_type=self.order_cell_portal_type) portal_type=self.order_line_portal_type)
self.stepTic() order_cell = order_line.newContent(
# self-tests... portal_type=self.order_cell_portal_type)
# ...assertions of acquisition expected_path_list = [order.getPath(), order_line.getPath(),
source, source_uid = order.getSource(), order.getSourceUid() inner_order_line.getPath(), order_cell.getPath()]
self.assertEqual(source, order_line.getSource()) self.stepTic()
self.assertEqual(source, inner_order_line.getSource()) # check that all would be catalogged
self.assertEqual(source, order_cell.getSource()) self.assertSameSet(
# ...assertions that only acquisition is used self.portal.catalogged_object_path_dict.keys(),
self.assertFalse('source/'+source in order_line.getCategoryList()) expected_path_list
self.assertFalse('source/'+source in inner_order_line.getCategoryList()) )
self.assertFalse('source/'+source in order_cell.getCategoryList()) # do real assertions
# ...assertions that they are movement self.portal.catalogged_object_path_dict = PersistentMapping()
self.assertTrue(order_line.isMovement()) transaction.commit()
self.assertTrue(order_cell.isMovement()) order.reindexObject()
self.assertTrue(inner_order_line.isMovement()) self.stepTic()
# real assertions self.assertSameSet(
kw = {"movement.source_uid":source_uid} self.portal.catalogged_object_path_dict.keys(),
catalog_tool = self.portal.portal_catalog expected_path_list
self.assertEqual(1, len(catalog_tool(uid=order.getUid(), )
source_relative_url=source))) finally:
self.assertEqual(1, len(catalog_tool(uid=order_line.getUid(), **kw))) # unwrap catalogObjectList
self.assertEqual(1, len(catalog_tool(uid=inner_order_line.getUid(), **kw))) self.unwrap_catalogObjectList()
self.assertEqual(1, len(catalog_tool(uid=order_cell.getUid(), **kw)))
# change to different source
order.setSourceValue(organisation2)
self.stepTic()
# ...assertions of acquisition
source, source_uid = order.getSource(), order.getSourceUid()
self.assertEqual(source, order_line.getSource())
self.assertEqual(source, inner_order_line.getSource())
self.assertEqual(source, order_cell.getSource())
# ...assertions that only acquisition is used
self.assertFalse('source/'+source in order_line.getCategoryList())
self.assertFalse('source/'+source in inner_order_line.getCategoryList())
self.assertFalse('source/'+source in order_cell.getCategoryList())
# real assertions
kw = {"movement.source_uid":source_uid}
catalog_tool = self.portal.portal_catalog
self.assertEqual(1, len(catalog_tool(uid=order.getUid(),
source_relative_url=source)))
self.assertEqual(1, len(catalog_tool(uid=order_line.getUid(), **kw)))
self.assertEqual(1, len(catalog_tool(uid=inner_order_line.getUid(), **kw)))
self.assertEqual(1, len(catalog_tool(uid=order_cell.getUid(), **kw)))
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
...@@ -36,6 +36,7 @@ from zLOG import LOG ...@@ -36,6 +36,7 @@ from zLOG import LOG
from Products.ERP5Type.tests.Sequence import SequenceList from Products.ERP5Type.tests.Sequence import SequenceList
from testOrder import TestOrderMixin from testOrder import TestOrderMixin
from DateTime import DateTime from DateTime import DateTime
from Products.ERP5Type.Globals import PersistentMapping
class TestPackingListMixin(TestOrderMixin): class TestPackingListMixin(TestOrderMixin):
""" """
...@@ -1572,57 +1573,81 @@ class TestPackingList(TestPackingListMixin, ERP5TypeTestCase) : ...@@ -1572,57 +1573,81 @@ class TestPackingList(TestPackingListMixin, ERP5TypeTestCase) :
sequence_list.play(self, quiet=quiet) sequence_list.play(self, quiet=quiet)
def test_subcontent_reindexing(self): def test_subcontent_reindexing_packing_list_line_cell(self):
"""Tests, that modification on Packing List are propagated to subobjects """Tests, that indexation of Packing List are propagated to subobjects
during reindxation""" during reindxation"""
organisation1 = self.portal.organisation_module.newContent( self.portal.catalogged_object_path_dict = PersistentMapping()
portal_type='Organisation') transaction.commit()
organisation2 = self.portal.organisation_module.newContent( try:
portal_type='Organisation') # wrap call to catalogObjectList
packing_list = self.portal.getDefaultModule(self.packing_list_portal_type).newContent( self.wrap_catalogObjectList()
portal_type=self.packing_list_portal_type, # prepare test data
source_value=organisation1) packing_list = self.portal.getDefaultModule(
packing_list_line = packing_list.newContent(portal_type=self.packing_list_line_portal_type) self.packing_list_portal_type).newContent(
packing_list_cell = packing_list.newContent(portal_type=self.packing_list_line_portal_type)\ portal_type=self.packing_list_portal_type)
.newContent(portal_type=self.packing_list_cell_portal_type) packing_list_line = packing_list.newContent(
self.stepTic() portal_type=self.packing_list_line_portal_type)
# self-tests... packing_list_cell = packing_list_line.newContent(
# ...assertions of acquisition portal_type=self.packing_list_cell_portal_type)
source, source_uid = packing_list.getSource(), packing_list.getSourceUid() expected_path_list = [packing_list.getPath(),
self.assertEqual(source, packing_list_line.getSource()) packing_list_line.getPath(), packing_list_cell.getPath()]
self.assertEqual(source, packing_list_cell.getSource()) self.stepTic()
# ...assertions that only acquisition is used # check that all would be catalogged
self.assertFalse('source/'+source in packing_list_line.getCategoryList()) self.assertSameSet(
self.assertFalse('source/'+source in packing_list_cell.getCategoryList()) self.portal.catalogged_object_path_dict.keys(),
# ...assertions that they are movement expected_path_list
self.assertTrue(packing_list_line.isMovement()) )
self.assertTrue(packing_list_cell.isMovement()) # do real assertions
# real assertions self.portal.catalogged_object_path_dict = PersistentMapping()
kw = {"movement.source_uid":source_uid} transaction.commit()
catalog_tool = self.portal.portal_catalog packing_list.reindexObject()
self.assertEqual(1, len(catalog_tool(uid=packing_list.getUid(), self.stepTic()
source_relative_url=source))) self.assertSameSet(
self.assertEqual(1, len(catalog_tool(uid=packing_list_line.getUid(), **kw))) self.portal.catalogged_object_path_dict.keys(),
self.assertEqual(1, len(catalog_tool(uid=packing_list_cell.getUid(), **kw))) expected_path_list
)
# change to different source finally:
packing_list.setSourceValue(organisation2) # unwrap catalogObjectList
self.stepTic() self.unwrap_catalogObjectList()
# ...assertions of acquisition def test_subcontent_reindexing_packing_list_container_line_cell(self):
source, source_uid = packing_list.getSource(), packing_list.getSourceUid() """Tests, that indexation of Packing List are propagated to subobjects
self.assertEqual(source, packing_list_line.getSource()) during reindxation, for Container, Container Line and Container Cell"""
self.assertEqual(source, packing_list_cell.getSource()) self.portal.catalogged_object_path_dict = PersistentMapping()
# ...assertions that only acquisition is used transaction.commit()
self.assertFalse('source/'+source in packing_list_line.getCategoryList()) try:
self.assertFalse('source/'+source in packing_list_cell.getCategoryList()) # wrap call to catalogObjectList
# real assertions self.wrap_catalogObjectList()
kw = {"movement.source_uid":source_uid} # prepare test data
catalog_tool = self.portal.portal_catalog packing_list = self.portal.getDefaultModule(
self.assertEqual(1, len(catalog_tool(uid=packing_list.getUid(), self.packing_list_portal_type).newContent(
source_relative_url=source))) portal_type=self.packing_list_portal_type)
self.assertEqual(1, len(catalog_tool(uid=packing_list_line.getUid(), **kw))) container = packing_list.newContent(
self.assertEqual(1, len(catalog_tool(uid=packing_list_cell.getUid(), **kw))) portal_type=self.container_portal_type)
container_line = container.newContent(
portal_type=self.container_line_portal_type)
container_cell = container_line.newContent(
portal_type=self.container_cell_portal_type)
expected_path_list = [packing_list.getPath(), container.getPath(),
container_line.getPath(), container_cell]
self.stepTic()
# check that all would be catalogged
self.assertSameSet(
self.portal.catalogged_object_path_dict.keys(),
expected_path_list
)
# do real assertions
self.portal.catalogged_object_path_dict = PersistentMapping()
transaction.commit()
packing_list.reindexObject()
self.stepTic()
self.assertSameSet(
self.portal.catalogged_object_path_dict.keys(),
expected_path_list
)
finally:
# unwrap catalogObjectList
self.unwrap_catalogObjectList()
class TestAutomaticSolvingPackingList(TestPackingListMixin, ERP5TypeTestCase): class TestAutomaticSolvingPackingList(TestPackingListMixin, ERP5TypeTestCase):
quiet = 0 quiet = 0
...@@ -1756,7 +1781,9 @@ class TestPurchasePackingListMixin(TestPackingListMixin): ...@@ -1756,7 +1781,9 @@ class TestPurchasePackingListMixin(TestPackingListMixin):
stepCheckPackingListIsNotPacked = ignored_step stepCheckPackingListIsNotPacked = ignored_step
stepCheckPackingListIsPacked = ignored_step stepCheckPackingListIsPacked = ignored_step
stepCheckNewPackingListIsPacked = ignored_step stepCheckNewPackingListIsPacked = ignored_step
def test_subcontent_reindexing_packing_list_container_line_cell(self):
"""No need to check Containers in Purchase Packing List"""
pass
class TestPurchasePackingList(TestPurchasePackingListMixin, TestPackingList): class TestPurchasePackingList(TestPurchasePackingListMixin, TestPackingList):
"""Tests for purchase packing list. """Tests for purchase packing list.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment