def testExecuteAcquired(self):
        self.setRoles('Manager')
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        dummyMailHost = DummySecureMailHost('dMailhost')
        sm.registerUtility(dummyMailHost, IMailHost)
        e = MailRoleAction()
        e.source = "*****@*****.**"
        e.role = "Owner"
        e.acquired = True
        e.message = u"Päge '${title}' created in ${url} !"
        ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                             IExecutable)
        ex()
        self.failUnless(isinstance(dummyMailHost.sent[0], MIMEText))
        self.failUnless(isinstance(dummyMailHost.sent[1], MIMEText))

        for mailSent in dummyMailHost.sent:

            self.assertEqual('text/plain; charset="utf-8"',
                            mailSent.get('Content-Type'))

            self.failUnless(mailSent.get('To') in ("*****@*****.**",
                                                   "*****@*****.**"))
            self.assertEqual("*****@*****.**", mailSent.get('From'))
            self.assertEqual("\nP\xc3\xa4ge 'W\xc3\xa4lkommen' created in http://nohost/plone/d1 !",
                             mailSent.get_payload(decode=True))
    def testExecuteNoSource(self):
        self.loginAsPortalOwner()
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        dummyMailHost = DummySecureMailHost('dMailhost')
        sm.registerUtility(dummyMailHost, IMailHost)
        e = MailRoleAction()
        e.role = "Owner"
        e.acquired = False
        e.message = 'Document created !'
        ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                             IExecutable)
        self.assertRaises(ValueError, ex)
        # if we provide a site mail address this won't fail anymore
        sm.manage_changeProperties({'email_from_address': '*****@*****.**', 'email_from_name':'ploneRulez'})
        ex()
        self.failUnless(isinstance(dummyMailHost.sent[0], MIMEText))
        mailSent = dummyMailHost.sent[0]
        self.assertEqual('text/plain; charset="utf-8"',
                        mailSent.get('Content-Type'))
        self.assertEqual("*****@*****.**", mailSent.get('To'))
        assert("<*****@*****.**>" in mailSent.get('From'))
        assert("ploneRulez" in mailSent.get('From'))

        self.assertEqual("Document created !",
                         mailSent.get_payload(decode=True))
コード例 #3
0
    def testExecuteNoSource(self):
        self.setRoles('Manager')
        if IS_PLONE_5:
            self.loginAsPortalOwner()
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        dummyMailHost = DummySecureMailHost('dMailhost')
        sm.registerUtility(dummyMailHost, IMailHost)
        e = MailRoleAction()
        e.role = "Owner"
        e.acquired = False
        e.message = 'Document created !'
        ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                             IExecutable)
        self.assertRaises(ValueError, ex)
        if IS_PLONE_5:
            api.portal.set_registry_record('plone.email_from_address',
                                           '*****@*****.**')
            api.portal.set_registry_record('plone.email_from_name',
                                           u'ploneRulez')
        else:
            portal = api.portal.get()
            portal.email_from_name = u'ploneRulez'
            portal.email_from_address = '*****@*****.**'
        ex()
        self.failUnless(isinstance(dummyMailHost.sent[0], MIMEText))
        mailSent = dummyMailHost.sent[0]
        self.assertEqual('text/plain; charset="utf-8"',
                         mailSent.get('Content-Type'))
        self.assertEqual("*****@*****.**", mailSent.get('To'))
        assert ("<*****@*****.**>" in mailSent.get('From'))
        assert ("ploneRulez" in mailSent.get('From'))

        self.assertEqual("\nDocument created !",
                         mailSent.get_payload(decode=True))
コード例 #4
0
    def testExecuteAcquired(self):
        self.setRoles('Manager')
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        dummyMailHost = DummySecureMailHost('dMailhost')
        sm.registerUtility(dummyMailHost, IMailHost)
        e = MailRoleAction()
        e.source = "*****@*****.**"
        e.role = "Owner"
        e.acquired = True
        e.message = u"Päge '${title}' created in ${url} !"
        ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                             IExecutable)
        ex()
        self.failUnless(isinstance(dummyMailHost.sent[0], MIMEText))
        self.failUnless(isinstance(dummyMailHost.sent[1], MIMEText))

        for mailSent in dummyMailHost.sent:

            self.assertEqual('text/plain; charset="utf-8"',
                             mailSent.get('Content-Type'))

            self.failUnless(
                mailSent.get('To') in ("*****@*****.**",
                                       "*****@*****.**"))
            self.assertEqual("*****@*****.**", mailSent.get('From'))
            self.assertEqual(
                "\nP\xc3\xa4ge 'W\xc3\xa4lkommen' created in http://nohost/plone/d1 !",
                mailSent.get_payload(decode=True))
 def testExecuteNoEmptyMail(self):
     self.setRoles('Manager')
     sm = getSiteManager(self.portal)
     sm.unregisterUtility(provided=IMailHost)
     dummyMailHost = DummySecureMailHost('dMailhost')
     sm.registerUtility(dummyMailHost, IMailHost)
     e = MailRoleAction()
     e.source = "*****@*****.**"
     e.role = "Reviewer"
     e.acquired = False
     e.message = u"Päge '${title}' created in ${url} !"
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d2)),
                          IExecutable)
     ex()
     self.assertEqual(len(dummyMailHost.sent), 0)
コード例 #6
0
 def testExecuteNoEmptyMail(self):
     self.setRoles('Manager')
     sm = getSiteManager(self.portal)
     sm.unregisterUtility(provided=IMailHost)
     dummyMailHost = DummySecureMailHost('dMailhost')
     sm.registerUtility(dummyMailHost, IMailHost)
     e = MailRoleAction()
     e.source = "*****@*****.**"
     e.role = "Reviewer"
     e.acquired = False
     e.message = u"Päge '${title}' created in ${url} !"
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d2)),
                          IExecutable)
     ex()
     self.assertEqual(len(dummyMailHost.sent), 0)
 def testExecuteWithGroup(self):
     self.setRoles('Manager')
     sm = getSiteManager(self.portal)
     sm.unregisterUtility(provided=IMailHost)
     dummyMailHost = DummySecureMailHost('dMailhost')
     sm.registerUtility(dummyMailHost, IMailHost)
     e = MailRoleAction()
     e.source = "*****@*****.**"
     e.role = "Reader"
     e.acquired = True
     e.message = u"Päge '${title}' created in ${url} !"
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                          IExecutable)
     ex()
     self.failUnless(isinstance(dummyMailHost.sent[0], MIMEText))
     self.assertEqual(len(dummyMailHost.sent), 2)
     mailSentTo = [mailSent.get('To') for mailSent in dummyMailHost.sent]
     assert("*****@*****.**" in mailSentTo)
     assert("*****@*****.**" in mailSentTo)
コード例 #8
0
 def testExecuteWithGroup(self):
     self.setRoles('Manager')
     sm = getSiteManager(self.portal)
     sm.unregisterUtility(provided=IMailHost)
     dummyMailHost = DummySecureMailHost('dMailhost')
     sm.registerUtility(dummyMailHost, IMailHost)
     e = MailRoleAction()
     e.source = "*****@*****.**"
     e.role = "Reader"
     e.acquired = True
     e.message = u"Päge '${title}' created in ${url} !"
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                          IExecutable)
     ex()
     self.failUnless(isinstance(dummyMailHost.sent[0], MIMEText))
     self.assertEqual(len(dummyMailHost.sent), 2)
     mailSentTo = [mailSent.get('To') for mailSent in dummyMailHost.sent]
     assert ("*****@*****.**" in mailSentTo)
     assert ("*****@*****.**" in mailSentTo)
    def testExecuteNoSource(self):
        self.setRoles('Manager')
        if IS_PLONE_5:
            self.loginAsPortalOwner()
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        dummyMailHost = DummySecureMailHost('dMailhost')
        sm.registerUtility(dummyMailHost, IMailHost)
        e = MailRoleAction()
        e.role = "Owner"
        e.acquired = False
        e.message = 'Document created !'
        ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                             IExecutable)
        self.assertRaises(ValueError, ex)
        if IS_PLONE_5:
            api.portal.set_registry_record(
                'plone.email_from_address',
                '*****@*****.**'
            )
            api.portal.set_registry_record(
                'plone.email_from_name',
                u'ploneRulez'
            )
        else:
            portal = api.portal.get()
            portal.email_from_name = u'ploneRulez'
            portal.email_from_address = '*****@*****.**'
        ex()
        self.failUnless(isinstance(dummyMailHost.sent[0], MIMEText))
        mailSent = dummyMailHost.sent[0]
        self.assertEqual('text/plain; charset="utf-8"',
                        mailSent.get('Content-Type'))
        self.assertEqual("*****@*****.**", mailSent.get('To'))
        assert("<*****@*****.**>" in mailSent.get('From'))
        assert("ploneRulez" in mailSent.get('From'))

        self.assertEqual("\nDocument created !",
                         mailSent.get_payload(decode=True))
    def testExecuteWithSubGroup(self):
        self.setRoles('Manager')
        if IS_PLONE_5:
            self.loginAsPortalOwner()
        membership = getToolByName(self.portal, 'portal_membership')
        groups = getToolByName(self.portal, 'portal_groups')

        # set up additional group and its subgroups
        groups.addGroup('group2')
        groups.addGroup('subgroup1')
        groups.addGroup('subgroup2')

        # put subgroup1 into group2
        groups.addPrincipalToGroup('subgroup1', 'group2')

        # put subgroup2 into subgroup1
        groups.addPrincipalToGroup('subgroup2', 'subgroup1')

        # put submember1 into group2
        membership.addMember(
            'submember1',
            'secret',
            ('Member',),
            (),
            properties={'email': '*****@*****.**'})
        groups.addPrincipalToGroup('submember1', 'group2')

        # put submember2 into subgroup1
        membership.addMember(
            'submember2',
            'secret',
            ('Member',),
            (),
            properties={'email': '*****@*****.**'})
        groups.addPrincipalToGroup('submember2', 'subgroup1')

        # put submember3 into subgroup2
        membership.addMember(
            'submember3',
            'secret',
            ('Member',),
            (),
            properties={'email': '*****@*****.**'})
        groups.addPrincipalToGroup('submember3', 'subgroup2')

        # create new folder and document in it
        self.portal.invokeFactory('Folder', 'test_subgroups', title=u'Test subgroups')
        test_folder = self.portal['test_subgroups']
        test_folder.invokeFactory('Document', 'subgroups_page', title=u'Subgroups page')

        # assign Reader role to group2 which containes several subgroups and members in several levels
        test_folder.manage_setLocalRoles('group2', ['Reader', ])

        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        dummyMailHost = DummySecureMailHost('dMailhost')
        sm.registerUtility(dummyMailHost, IMailHost)
        e = MailRoleAction()
        e.source = "*****@*****.**"
        e.role = "Reader"
        e.acquired = True
        e.message = u"Päge '${title}' created in ${url} !"
        ex = getMultiAdapter((test_folder, e, DummyEvent(test_folder.subgroups_page)),
                             IExecutable)
        ex()
        self.failUnless(isinstance(dummyMailHost.sent[0], MIMEText))
        self.assertEqual(len(dummyMailHost.sent), 3)
        mailSentTo = [mailSent.get('To') for mailSent in dummyMailHost.sent]
        assert("*****@*****.**" in mailSentTo)
        assert("*****@*****.**" in mailSentTo)
        assert("*****@*****.**" in mailSentTo)
コード例 #11
0
    def testExecuteWithSubGroup(self):
        self.setRoles('Manager')
        if IS_PLONE_5:
            self.loginAsPortalOwner()
        membership = getToolByName(self.portal, 'portal_membership')
        groups = getToolByName(self.portal, 'portal_groups')

        # set up additional group and its subgroups
        groups.addGroup('group2')
        groups.addGroup('subgroup1')
        groups.addGroup('subgroup2')

        # put subgroup1 into group2
        groups.addPrincipalToGroup('subgroup1', 'group2')

        # put subgroup2 into subgroup1
        groups.addPrincipalToGroup('subgroup2', 'subgroup1')

        # put submember1 into group2
        membership.addMember('submember1',
                             'secret', ('Member', ), (),
                             properties={'email': '*****@*****.**'})
        groups.addPrincipalToGroup('submember1', 'group2')

        # put submember2 into subgroup1
        membership.addMember('submember2',
                             'secret', ('Member', ), (),
                             properties={'email': '*****@*****.**'})
        groups.addPrincipalToGroup('submember2', 'subgroup1')

        # put submember3 into subgroup2
        membership.addMember('submember3',
                             'secret', ('Member', ), (),
                             properties={'email': '*****@*****.**'})
        groups.addPrincipalToGroup('submember3', 'subgroup2')

        # create new folder and document in it
        self.portal.invokeFactory('Folder',
                                  'test_subgroups',
                                  title=u'Test subgroups')
        test_folder = self.portal['test_subgroups']
        test_folder.invokeFactory('Document',
                                  'subgroups_page',
                                  title=u'Subgroups page')

        # assign Reader role to group2 which containes several subgroups and members in several levels
        test_folder.manage_setLocalRoles('group2', [
            'Reader',
        ])

        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        dummyMailHost = DummySecureMailHost('dMailhost')
        sm.registerUtility(dummyMailHost, IMailHost)
        e = MailRoleAction()
        e.source = "*****@*****.**"
        e.role = "Reader"
        e.acquired = True
        e.message = u"Päge '${title}' created in ${url} !"
        ex = getMultiAdapter(
            (test_folder, e, DummyEvent(test_folder.subgroups_page)),
            IExecutable)
        ex()
        self.failUnless(isinstance(dummyMailHost.sent[0], MIMEText))
        self.assertEqual(len(dummyMailHost.sent), 3)
        mailSentTo = [mailSent.get('To') for mailSent in dummyMailHost.sent]
        assert ("*****@*****.**" in mailSentTo)
        assert ("*****@*****.**" in mailSentTo)
        assert ("*****@*****.**" in mailSentTo)