def testExecuteNoSource(self):
        self.loginAsPortalOwner()
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        dummyMailHost = DummySecureMailHost('dMailhost')
        sm.registerUtility(dummyMailHost, IMailHost)
        e = MailLocalRoleAction()
        e.localrole = "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))
    def testExecuteAcquired(self):
        self.loginAsPortalOwner()
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        dummyMailHost = DummySecureMailHost('dMailhost')
        sm.registerUtility(dummyMailHost, IMailHost)
        e = MailLocalRoleAction()
        e.source = "*****@*****.**"
        e.localrole = "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("P\xc3\xa4ge 'W\xc3\xa4lkommen' created in http://nohost/plone/Members/test_user_1_/d1 !",
                             mailSent.get_payload(decode=True))
 def testExecuteNoEmptyMail(self):
     self.loginAsPortalOwner()
     sm = getSiteManager(self.portal)
     sm.unregisterUtility(provided=IMailHost)
     dummyMailHost = DummySecureMailHost('dMailhost')
     sm.registerUtility(dummyMailHost, IMailHost)
     e = MailLocalRoleAction()
     e.source = "*****@*****.**"
     e.localrole = "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.loginAsPortalOwner()
     sm = getSiteManager(self.portal)
     sm.unregisterUtility(provided=IMailHost)
     dummyMailHost = DummySecureMailHost('dMailhost')
     sm.registerUtility(dummyMailHost, IMailHost)
     e = MailLocalRoleAction()
     e.source = "*****@*****.**"
     e.localrole = "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 testExecuteWithSubGroup(self):
     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 = MailLocalRoleAction()
     e.source = "*****@*****.**"
     e.localrole = "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)