def testRuleConditionAdding(self): storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter( (rule, self.portal.REQUEST), name='+condition') d = DummyCondition() self.assertEqual(0, len(rule.conditions)) adding.add(d) self.assertEqual(1, len(rule.conditions)) self.assertTrue(rule.conditions[0] is d)
def testInvokeAddView(self): element = getUtility(IRuleAction, name='plone.actions.Delete') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule.__of__(self.portal), self.portal.REQUEST), name='+action') addview = getMultiAdapter((adding.__of__(rule), self.portal.REQUEST), name=element.addview) addview() e = rule.actions[0] self.assertTrue(isinstance(e, DeleteAction))
def _create_rule(portal, rule_id, title, event): storage = component.getUtility(IRuleStorage) if rule_id not in storage: storage[rule_id] = Rule() rule = storage.get(rule_id) rule.title = title rule.enabled = True # Clear out conditions and actions since we're expecting new ones del rule.conditions[:] del rule.actions[:] rule.event = event rule = rule.__of__(portal) return rule
def afterSetUp(self): self.folder.invokeFactory('Folder', 'f1') self.folder.f1.invokeFactory('Folder', 'f11') self.folder.f1.invokeFactory('Folder', 'f12') self.storage = getUtility(IRuleStorage) self.storage['r1'] = Rule() self.storage['r2'] = Rule() self.storage['r3'] = Rule() self.f11a = IRuleAssignmentManager(self.folder.f1.f11) self.f11a['r1'] = RuleAssignment('r1', bubbles=True) insert_assignment(self.storage['r1'], '/'.join(self.folder.f1.f11.getPhysicalPath())) self.f12a = IRuleAssignmentManager(self.folder.f1.f12) self.f12a['r1'] = RuleAssignment('r1', bubbles=True) insert_assignment(self.storage['r1'], '/'.join(self.folder.f1.f12.getPhysicalPath())) self.f12a['r2'] = RuleAssignment('r2', bubbles=True) insert_assignment(self.storage['r2'], '/'.join(self.folder.f1.f12.getPhysicalPath()))
def testInvokeAddView(self): element = getUtility(IRuleCondition, name='plone.conditions.WorkflowState') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+condition') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) addview.createAndAdd(data={'wf_states': ['visible', 'published']}) e = rule.conditions[0] self.failUnless(isinstance(e, WorkflowStateCondition)) self.assertEquals(['visible', 'published'], e.wf_states)
def testInvokeAddView(self): element = getUtility(IRuleAction, name='plone.actions.Move') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) addview.createAndAdd(data={'target_folder': '/target', }) e = rule.actions[0] self.assertTrue(isinstance(e, MoveAction)) self.assertEqual('/target', e.target_folder)
def testInvokeAddView(self): element = getUtility(IRuleCondition, name='plone.conditions.Role') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+condition') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) addview.createAndAdd(data={'role_names': ['Manager', 'Member']}) e = rule.conditions[0] self.assertTrue(isinstance(e, RoleCondition)) self.assertEqual(['Manager', 'Member'], e.role_names)
def testInvokeAddView(self): element = getUtility(IRuleCondition, name='plone.conditions.TalesExpression') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+condition') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) addview.createAndAdd(data={'tales_expression': 'python:"plone" in object.Subject()'}) e = rule.conditions[0] self.failUnless(isinstance(e, TalesExpressionCondition)) self.assertEquals('python:"plone" in object.Subject()', e.tales_expression)
def testRuleStopModification(self): storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') view = rule.restrictedTraverse('manage-elements') view.template = lambda: 'No template thanks' self.portal.REQUEST.form['stopExecuting'] = 'on' self.portal.REQUEST.form['form.button.Save'] = True self.addAuthToRequest() self.assertEqual(False, rule.stop) view() self.assertEqual(True, rule.stop)
def testInvokeAddView(self): element = getUtility(IRuleAction, name='plone.actions.Versioning') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.request), name='+action') addview = getMultiAdapter((adding, self.request), name=element.addview) addview.form_instance.update() content = addview.form_instance.create(data={'comment': 'Hello world'}) addview.form_instance.add(content) e = rule.actions[0] self.assertTrue(isinstance(e, VersioningAction)) self.assertEqual('Hello world', e.comment)
def testInvokeAddView(self): element = getUtility(IRuleAction, name='plone.actions.Workflow') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) addview.form_instance.update() content = addview.form_instance.create(data={'transition': 'publish', }) addview.form_instance.add(content) e = rule.actions[0] self.assertTrue(isinstance(e, WorkflowAction)) self.assertEqual('publish', e.transition)
def test_invoke_add_view(self): element = getUtility(IRuleAction, name='sc.contentrules.actions.ExcludeFromNav') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) addview.createAndAdd(data={'exclude': False}) e = rule.actions[0] self.failUnless(isinstance(e, ExcludeFromNavAction)) self.assertEquals(False, e.exclude)
def testInvokeAddView(self): element = getUtility(IRuleAction, name='sc.contentrules.actions.layout') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) addview.createAndAdd(data={'layout': 'folder_summary_view'}) e = rule.actions[0] self.failUnless(isinstance(e, SetLayoutAction)) self.assertEquals('folder_summary_view', e.layout)
def create(self, transition): rule = self.get_rule(transition) if rule is None: rule_id = generateRuleName(transition) r = Rule() r.title = _(u"%s transition content rule") % transition.id r.description = _(u"This content rule was automatically created " u"the workflow manager to create actions on " u"workflow events. If you want the behavior to " u"work as expected, do not modify this out of " u"the workflow manager.") self.storage[rule_id] = r rule = RuleAdapter(r, transition) rule.activate() return rule
def testInvokeAddView(self): element = getUtility(IRuleCondition, name='plone.conditions.Group') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+condition') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) addview.form_instance.update() content = addview.form_instance.create(data={'group_names': ['Manager']}) addview.form_instance.add(content) e = rule.conditions[0] self.assertTrue(isinstance(e, GroupCondition)) self.assertEqual(['Manager'], e.group_names)
def testInvokeAddView(self): element = getUtility(IRuleAction, name='plone.actions.MailGroup') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) self.assertTrue(isinstance(addview, MailGroupAddFormView)) if IS_PLONE_5: addview.form_instance.update() output = addview.form_instance() self.assertIn('<h1>Substitutions</h1>', output) content = addview.form_instance.create( data={ 'subject': 'My Subject', 'source': '*****@*****.**', 'groups': ['group1', 'group2'], 'members': [ default_user, ], 'message': 'Hey, Oh!' }) addview.form_instance.add(content) else: addview.createAndAdd( data={ 'subject': 'My Subject', 'source': '*****@*****.**', 'groups': ['group1', 'group2'], 'members': [ default_user, ], 'message': 'Hey, Oh!' }) e = rule.actions[0] self.assertTrue(isinstance(e, MailGroupAction)) self.assertEqual('My Subject', e.subject) self.assertEqual('*****@*****.**', e.source) self.assertEqual(['group1', 'group2'], e.groups) self.assertEqual([ default_user, ], e.members) self.assertEqual('Hey, Oh!', e.message)
def test_invoke_add_view(self): element = getUtility(IRuleAction, name='sc.contentrules.actions.Creators') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) addview.createAndAdd(data={'creators': ('bar', ), 'only_empty': False}) e = rule.actions[0] self.failUnless(isinstance(e, CreatorsAction)) self.assertEquals(('bar', ), e.creators) self.assertEquals(False, e.only_empty)
def testInvokeAddView(self): element = getUtility(IRuleCondition, name='plone.conditions.PortalType') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+condition') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) addview.createAndAdd(data={'check_types': ['Folder', 'Image']}) e = rule.conditions[0] self.failUnless(isinstance(e, PortalTypeCondition)) self.assertEquals(['Folder', 'Image'], e.check_types)
def testInvokeAddView(self): element = getUtility(IRuleAction, name='plone.actions.Notify') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.request), name='+action') addview = getMultiAdapter((adding, self.request), name=element.addview) addview.createAndAdd(data={ 'message': 'Hello world', 'message_type': 'info' }) e = rule.actions[0] self.assertTrue(isinstance(e, NotifyAction)) self.assertEqual('Hello world', e.message) self.assertEqual('info', e.message_type)
def testInvokeAddView(self): self._loadAccounts(2) element = getUtility(IRuleAction, name='collective.twitter.tweet.TweetContent') storage = getUtility(IRuleStorage) storage[u'tweet'] = Rule() rule = self.portal.restrictedTraverse('++rule++tweet') adding = getMultiAdapter((rule, self.request), name='+action') addview = getMultiAdapter((adding, self.request), name=element.addview) addview.createAndAdd(data={'tw_account': 'first-valid-account'}) e = rule.actions[0] self.failUnless(isinstance(e, Action)) self.assertEquals(e.tw_account, 'first-valid-account') self.assertEquals(e.different_host, '')
def testInvokeAddView(self): element = getUtility(IRuleAction, name='sc.contentrules.actions.groupbydate') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) addview.createAndAdd(data={ 'base_folder': '/target', 'structure': 'ymd' }) e = rule.actions[0] self.failUnless(isinstance(e, GroupByDateAction)) self.assertEquals('/target', e.base_folder)
def testInvokeAddView(self): """ testInvokeAddView """ element = self._element() storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) addview.createAndAdd(data={ 'action': 'enabled', }) e = rule.actions[0] self.failUnless(isinstance(e, EnableDisableDiscussionAction)) self.assertEquals('enabled', e.action)
def test_invoke_add_view(self): element = getUtility(IRuleAction, name='sc.contentrules.actions.Subject') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) addview.createAndAdd(data={'same_as_parent': False, 'subject': ['Foo', ]}) e = rule.actions[0] self.failUnless(isinstance(e, SubjectAction)) self.assertEquals(False, e.same_as_parent) self.assertEquals(['Foo', ], e.subject)
def testInvokeAddView(self): element = getUtility(IRuleAction, name='plone.actions.Logger') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action') addview = getMultiAdapter( (adding, self.portal.REQUEST), name=element.addview) addview.form_instance.update() content = addview.form_instance.create( data={'targetLogger': 'foo', 'loggingLevel': 10, 'message': 'bar'}) addview.form_instance.add(content) e = rule.actions[0] self.assertTrue(isinstance(e, LoggerAction)) self.assertEqual('foo', e.targetLogger) self.assertEqual(10, e.loggingLevel) self.assertEqual('bar', e.message)
def test_invoke_add_view(self): element = getUtility(IRuleCondition, name='brasil.gov.vcge.conditions.VCGE') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+condition') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) addview.createAndAdd(data={'skos': [ self.term, ]}) e = rule.conditions[0] self.assertTrue(isinstance(e, VCGECondition)) self.assertEqual([ self.term, ], e.skos)
def testTraverseToRuleAction(self): r = Rule() e1 = DummyAction() e1.x = "x" e2 = DummyAction() e2.x = "y" r.actions.append(e1) r.actions.append(e2) storage = getUtility(IRuleStorage) storage[u'r1'] = r tr = self.portal.restrictedTraverse('++rule++r1') te1 = tr.restrictedTraverse('++action++0') te2 = tr.restrictedTraverse('++action++1') self.failUnless(aq_parent(te1) is tr) self.assertEquals("x", te1.x) self.failUnless(aq_parent(te2) is tr) self.assertEquals("y", te2.x)
def testTraverseToRuleAction(self): r = Rule() e1 = DummyAction() e1.x = 'x' e2 = DummyAction() e2.x = 'y' r.actions.append(e1) r.actions.append(e2) storage = getUtility(IRuleStorage) storage[u'r1'] = r tr = self.portal.restrictedTraverse('++rule++r1') te1 = tr.restrictedTraverse('++action++0') te2 = tr.restrictedTraverse('++action++1') self.assertTrue(aq_parent(te1) is tr) self.assertEqual('x', te1.x) self.assertTrue(aq_parent(te2) is tr) self.assertEqual('y', te2.x)
def testInvokeAddView(self): element = getUtility(IRuleAction, name='rapido.plone.Action') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.request), name='+action') addview = getMultiAdapter((adding, self.request), name=element.addview) addview.form_instance.update() content = addview.form_instance.create(data={ 'app': 'testapp', 'block': 'rule', 'method': 'hello', }) addview.form_instance.add(content) e = rule.actions[0] self.assertTrue(isinstance(e, Action)) self.assertEqual('testapp', e.app) self.assertEqual(e.summary, u'Call Rapido method hello from testapp/rule')
def testInvokeAddView(self): element = getUtility(IRuleAction, name='plone.actions.Mail') storage = getUtility(IRuleStorage) storage[u'foo'] = Rule() rule = self.portal.restrictedTraverse('++rule++foo') adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action') addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview) self.failUnless(isinstance(addview, MailAddForm)) addview.createAndAdd(data={'subject': 'My Subject', 'source': '*****@*****.**', 'recipients': '[email protected],[email protected]', 'message': 'Hey, Oh!'}) e = rule.actions[0] self.failUnless(isinstance(e, MailAction)) self.assertEquals('My Subject', e.subject) self.assertEquals('*****@*****.**', e.source) self.assertEquals('[email protected],[email protected]', e.recipients) self.assertEquals('Hey, Oh!', e.message)
def test_already_registered_email(self): """ try to re-register an email for the same rule id """ rule = Rule() rule.event = IObjectAddedEvent rule.title = "Test rule" #add the rule to rule's storage storage = getUtility(IRuleStorage) chooser = INameChooser(storage) storage[chooser.chooseName(None, rule)] = rule #set the action and add it to the rule action = MailSubscriptionsAction() action.subject = "Test Rule subject" action.message = "Test Rule message" rule.actions.append(action) tool = getToolByName(self.portal, SUBSCRIPTION_TOOL, None) email = "*****@*****.**" result, msg = tool.registerUser(action.actionUID, email) result2, msg2 = tool.registerUser(action.actionUID, email) self.assertTrue(result) self.assertFalse(result2) self.assertEquals(msg2, 'already_subscribed_error')