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
from zLOG import LOG
from Products.ERP5Type.tests.Sequence import SequenceList
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:
......@@ -69,6 +80,13 @@ class TestOrderMixin:
user = uf.getUserById('rc').__of__(uf)
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):
#create apparel variation preferences
portal_preferences = self.getPreferenceTool()
......@@ -2843,63 +2861,40 @@ class TestOrder(TestOrderMixin, ERP5TypeTestCase):
def test_subcontent_reindexing(self):
"""Tests, that modification on Order are propagated to lines and cells
during reindxation"""
organisation1 = self.portal.organisation_module.newContent(
portal_type='Organisation')
organisation2 = self.portal.organisation_module.newContent(
portal_type='Organisation')
order = self.portal.getDefaultModule(self.order_portal_type).newContent(
portal_type=self.order_portal_type,
source_value=organisation1)
order_line = order.newContent(portal_type=self.order_line_portal_type)
inner_order_line = order.newContent(portal_type=self.order_line_portal_type
).newContent(portal_type=self.order_line_portal_type)
order_cell = order.newContent(portal_type=self.order_line_portal_type)\
.newContent(portal_type=self.order_cell_portal_type)
self.stepTic()
# self-tests...
# ...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())
# ...assertions that they are movement
self.assertTrue(order_line.isMovement())
self.assertTrue(order_cell.isMovement())
self.assertTrue(inner_order_line.isMovement())
# 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)))
# 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)))
self.portal.catalogged_object_path_dict = PersistentMapping()
transaction.commit()
try:
# wrap call to catalogObjectList
self.wrap_catalogObjectList()
# prepare test data
order = self.portal.getDefaultModule(self.order_portal_type).newContent(
portal_type=self.order_portal_type)
order_line = order.newContent(portal_type=self.order_line_portal_type)
inner_order_line = order.newContent(
portal_type=self.order_line_portal_type).newContent(
portal_type=self.order_line_portal_type)
order_cell = order_line.newContent(
portal_type=self.order_cell_portal_type)
expected_path_list = [order.getPath(), order_line.getPath(),
inner_order_line.getPath(), order_cell.getPath()]
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()
order.reindexObject()
self.stepTic()
self.assertSameSet(
self.portal.catalogged_object_path_dict.keys(),
expected_path_list
)
finally:
# unwrap catalogObjectList
self.unwrap_catalogObjectList()
def test_suite():
suite = unittest.TestSuite()
......
......@@ -36,6 +36,7 @@ from zLOG import LOG
from Products.ERP5Type.tests.Sequence import SequenceList
from testOrder import TestOrderMixin
from DateTime import DateTime
from Products.ERP5Type.Globals import PersistentMapping
class TestPackingListMixin(TestOrderMixin):
"""
......@@ -1572,57 +1573,81 @@ class TestPackingList(TestPackingListMixin, ERP5TypeTestCase) :
sequence_list.play(self, quiet=quiet)
def test_subcontent_reindexing(self):
"""Tests, that modification on Packing List are propagated to subobjects
def test_subcontent_reindexing_packing_list_line_cell(self):
"""Tests, that indexation of Packing List are propagated to subobjects
during reindxation"""
organisation1 = self.portal.organisation_module.newContent(
portal_type='Organisation')
organisation2 = self.portal.organisation_module.newContent(
portal_type='Organisation')
packing_list = self.portal.getDefaultModule(self.packing_list_portal_type).newContent(
portal_type=self.packing_list_portal_type,
source_value=organisation1)
packing_list_line = packing_list.newContent(portal_type=self.packing_list_line_portal_type)
packing_list_cell = packing_list.newContent(portal_type=self.packing_list_line_portal_type)\
.newContent(portal_type=self.packing_list_cell_portal_type)
self.stepTic()
# self-tests...
# ...assertions of acquisition
source, source_uid = packing_list.getSource(), packing_list.getSourceUid()
self.assertEqual(source, packing_list_line.getSource())
self.assertEqual(source, packing_list_cell.getSource())
# ...assertions that only acquisition is used
self.assertFalse('source/'+source in packing_list_line.getCategoryList())
self.assertFalse('source/'+source in packing_list_cell.getCategoryList())
# ...assertions that they are movement
self.assertTrue(packing_list_line.isMovement())
self.assertTrue(packing_list_cell.isMovement())
# real assertions
kw = {"movement.source_uid":source_uid}
catalog_tool = self.portal.portal_catalog
self.assertEqual(1, len(catalog_tool(uid=packing_list.getUid(),
source_relative_url=source)))
self.assertEqual(1, len(catalog_tool(uid=packing_list_line.getUid(), **kw)))
self.assertEqual(1, len(catalog_tool(uid=packing_list_cell.getUid(), **kw)))
# change to different source
packing_list.setSourceValue(organisation2)
self.stepTic()
# ...assertions of acquisition
source, source_uid = packing_list.getSource(), packing_list.getSourceUid()
self.assertEqual(source, packing_list_line.getSource())
self.assertEqual(source, packing_list_cell.getSource())
# ...assertions that only acquisition is used
self.assertFalse('source/'+source in packing_list_line.getCategoryList())
self.assertFalse('source/'+source in packing_list_cell.getCategoryList())
# real assertions
kw = {"movement.source_uid":source_uid}
catalog_tool = self.portal.portal_catalog
self.assertEqual(1, len(catalog_tool(uid=packing_list.getUid(),
source_relative_url=source)))
self.assertEqual(1, len(catalog_tool(uid=packing_list_line.getUid(), **kw)))
self.assertEqual(1, len(catalog_tool(uid=packing_list_cell.getUid(), **kw)))
self.portal.catalogged_object_path_dict = PersistentMapping()
transaction.commit()
try:
# wrap call to catalogObjectList
self.wrap_catalogObjectList()
# prepare test data
packing_list = self.portal.getDefaultModule(
self.packing_list_portal_type).newContent(
portal_type=self.packing_list_portal_type)
packing_list_line = packing_list.newContent(
portal_type=self.packing_list_line_portal_type)
packing_list_cell = packing_list_line.newContent(
portal_type=self.packing_list_cell_portal_type)
expected_path_list = [packing_list.getPath(),
packing_list_line.getPath(), packing_list_cell.getPath()]
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()
def test_subcontent_reindexing_packing_list_container_line_cell(self):
"""Tests, that indexation of Packing List are propagated to subobjects
during reindxation, for Container, Container Line and Container Cell"""
self.portal.catalogged_object_path_dict = PersistentMapping()
transaction.commit()
try:
# wrap call to catalogObjectList
self.wrap_catalogObjectList()
# prepare test data
packing_list = self.portal.getDefaultModule(
self.packing_list_portal_type).newContent(
portal_type=self.packing_list_portal_type)
container = packing_list.newContent(
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):
quiet = 0
......@@ -1756,7 +1781,9 @@ class TestPurchasePackingListMixin(TestPackingListMixin):
stepCheckPackingListIsNotPacked = ignored_step
stepCheckPackingListIsPacked = 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):
"""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