Back to index

plone3  3.1.7
test_rule_assignment_mapping.py
Go to the documentation of this file.
00001 import transaction
00002 from zope.component import getUtility
00003 
00004 from plone.contentrules.engine.interfaces import IRuleStorage
00005 from plone.contentrules.engine.interfaces import IRuleAssignmentManager
00006 
00007 from plone.contentrules.engine.assignments import RuleAssignment
00008 
00009 from plone.app.contentrules.rule import Rule
00010 from plone.app.contentrules.rule import get_assignments
00011 
00012 from plone.app.contentrules.tests.base import ContentRulesTestCase
00013 
00014 class TestRuleAssignmentMapping(ContentRulesTestCase):
00015 
00016     def afterSetUp(self):
00017         self.folder.invokeFactory('Folder', 'f1')
00018         self.folder.f1.invokeFactory('Folder', 'f11')
00019         self.folder.f1.invokeFactory('Folder', 'f12')
00020         
00021         self.storage = getUtility(IRuleStorage)
00022         self.storage['r1'] = Rule()
00023         self.storage['r2'] = Rule()
00024         
00025         self.f11a = IRuleAssignmentManager(self.folder.f1.f11)
00026         self.f11a['r1'] = RuleAssignment('r1')
00027         get_assignments(self.storage['r1']).insert('/'.join(self.folder.f1.f11.getPhysicalPath()))
00028         
00029         self.f12a = IRuleAssignmentManager(self.folder.f1.f12)
00030         self.f12a['r1'] = RuleAssignment('r1')
00031         get_assignments(self.storage['r1']).insert('/'.join(self.folder.f1.f12.getPhysicalPath()))
00032         
00033         self.f12a['r2'] = RuleAssignment('r2')
00034         get_assignments(self.storage['r2']).insert('/'.join(self.folder.f1.f12.getPhysicalPath()))
00035         
00036     def testRuleRemoved(self):
00037         self.failUnless('r1' in self.f11a)
00038         self.failUnless('r1' in self.f12a)
00039         
00040         del self.storage['r1']
00041         
00042         self.failIf('r1' in self.f11a)
00043         self.failIf('r1' in self.f12a)
00044         
00045     def testContainerMoved(self):
00046         f12path = '/'.join(self.folder.f1.f12.getPhysicalPath())
00047         self.failUnless(f12path in get_assignments(self.storage['r1']))
00048         self.failUnless(f12path in get_assignments(self.storage['r2']))
00049         
00050         transaction.savepoint(1)
00051         self.folder.f1.manage_renameObject('f12', 'f12a')
00052         f12apath = '/'.join(self.folder.f1.f12a.getPhysicalPath())
00053         
00054         self.failIf(f12path in get_assignments(self.storage['r1']))
00055         self.failIf(f12path in get_assignments(self.storage['r2']))
00056         
00057         self.failUnless(f12apath in get_assignments(self.storage['r1']))
00058         self.failUnless(f12apath in get_assignments(self.storage['r1']))
00059         
00060     def testParentOfContainerMoved(self):
00061         f12path = '/'.join(self.folder.f1.f12.getPhysicalPath())
00062         self.failUnless(f12path in get_assignments(self.storage['r1']))
00063         self.failUnless(f12path in get_assignments(self.storage['r2']))
00064         
00065         transaction.savepoint(1)
00066         self.folder.manage_renameObject('f1', 'f1a')
00067         f12apath = '/'.join(self.folder.f1a.f12.getPhysicalPath())
00068         
00069         self.failIf(f12path in get_assignments(self.storage['r1']))
00070         self.failIf(f12path in get_assignments(self.storage['r2']))
00071         
00072         self.failUnless(f12apath in get_assignments(self.storage['r1']))
00073         self.failUnless(f12apath in get_assignments(self.storage['r1']))
00074         
00075     def testContainerRemoved(self):
00076         f12path = '/'.join(self.folder.f1.f12.getPhysicalPath())
00077         self.failUnless(f12path in get_assignments(self.storage['r1']))
00078         self.failUnless(f12path in get_assignments(self.storage['r2']))
00079         
00080         transaction.savepoint(1)
00081         self.folder._delObject('f1')
00082         
00083         self.failIf(f12path in get_assignments(self.storage['r1']))
00084         self.failIf(f12path in get_assignments(self.storage['r2']))
00085         
00086 def test_suite():
00087     from unittest import TestSuite, makeSuite
00088     suite = TestSuite()
00089     suite.addTest(makeSuite(TestRuleAssignmentMapping))
00090     return suite