示例#1
0
    def setUpPloneSite(self, portal):
        portal.acl_users.userFolderAddUser(
            'admin',
            'secret',
            ['Manager'],
            []
        )
        login(portal, 'admin')
        portal.portal_workflow.setDefaultChain("simple_publication_workflow")
        setRoles(portal, TEST_USER_ID, ['Manager'])
        portal.invokeFactory(
            "Folder",
            id="test-folder",
            title=u"Test Folder"
        )
        # XXX: this is needed for tests that rely on the Members folder to be
        # present. This folder is otherwise created by a setup handler in
        # ATContentTypes, but that package is optional now.
        if 'Members' not in portal.keys():
            portal.invokeFactory(
                "Folder",
                id="Members",
                title=u"Members"
            )

        portal._original_MailHost = portal.MailHost
        mail_host = MockMailHost('MailHost')
        mail_host.smtp_host = 'localhost'
        portal.MailHost = mail_host
        site_manager = getSiteManager(portal)
        site_manager.unregisterUtility(provided=IMailHost)
        site_manager.registerUtility(mail_host, IMailHost)
示例#2
0
    def setUp(self):
        super(TestInvitationFormEmailing, self).setUp()
        self.login_as_portal_owner()
        provideAdapter(adapts=(Interface, IBrowserRequest),
                       provides=Interface,
                       factory=InviteForm,
                       name="invite")

        # create a workspace
        self.ws = api.content.create(self.workspace_container,
                                     "ploneintranet.workspace.workspacefolder",
                                     "alejandro-workspace",
                                     title="Alejandro workspace")

        self.app = self.layer['app']
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        # don't import this at the top, because it screws up the setup
        # and none of the tests can run
        from Products.CMFPlone.tests.utils import MockMailHost
        #    # Mock the mail host so we can test sending the email
        mockmailhost = MockMailHost('MailHost')

        if not hasattr(mockmailhost, 'smtp_host'):
            mockmailhost.smtp_host = 'localhost'

        self.portal.MailHost = mockmailhost
        sm = self.portal.getSiteManager()
        sm.registerUtility(component=mockmailhost, provided=IMailHost)

        self.mailhost = api.portal.get_tool('MailHost')
        registry = getUtility(IRegistry)
        self.mail_settings = registry.forInterface(IMailSchema, prefix="plone")
        self.mail_settings.email_from_name = u'Portal Owner'
        self.mail_settings.email_from_address = '*****@*****.**'
    def setUp(self):
        self.app = self.layer['app']
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        # Mock the mail host so we can test sending the email
        # NEVER EVER IMPORT MOCKMAILHOST OUTSIDE OF SETUP!
        # IT WILL BREAK YOUR TEST_ISOLATION AND KILL YOUR FIRSTBORN
        from Products.CMFPlone.tests.utils import MockMailHost
        from Products.MailHost.interfaces import IMailHost
        mockmailhost = MockMailHost('MailHost')

        if not hasattr(mockmailhost, 'smtp_host'):
            mockmailhost.smtp_host = 'localhost'

        self.portal.MailHost = mockmailhost
        sm = self.portal.getSiteManager()
        sm.registerUtility(component=mockmailhost, provided=IMailHost)

        self.mailhost = api.portal.get_tool('MailHost')

        self.portal._updateProperty('email_from_name', 'Portal Owner')
        self.portal._updateProperty('email_from_address', '*****@*****.**')

        self.browser = Browser(self.app)
        self.browser.handleErrors = False

        # Commit so that the test browser sees these changes
        import transaction
        transaction.commit()
示例#4
0
    def setUp(self):
        self.app = self.layer['app']
        self.portal = self.layer['portal']
        self.qi_tool = getToolByName(self.portal, 'portal_quickinstaller')

        self.portal._original_MailHost = self.portal.MailHost
        self.portal.MailHost = mailhost = MockMailHost('MailHost')
        sm = getSiteManager(context=self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(mailhost, provided=IMailHost)

        mm = self.portal['MultiMailHost']

        mm._setObject('one', MockMailHost('one'))
        mm._setObject('two', MockMailHost('two'))
        mm._setObject('catch_all', MockMailHost('catch_all'))

        mm._setChain("default", [{
            'header-match': {
                'to': 'one'
            },
            'action': 'send and stop',
            'mailhost': 'one'
        }, {
            'header-match': {
                'to': 'two'
            },
            'action': 'send and stop',
            'mailhost': 'two'
        }, {
            'action': 'send and stop',
            'mailhost': 'default'
        }])
    def setUp(self):
        self.app = self.layer["app"]
        self.portal = self.layer["portal"]
        self.request = self.layer["request"]
        # Mock the mail host so we can test sending the email
        # NEVER EVER IMPORT MOCKMAILHOST OUTSIDE OF SETUP!
        # IT WILL BREAK YOUR TEST_ISOLATION AND KILL YOUR FIRSTBORN
        from Products.CMFPlone.tests.utils import MockMailHost
        from Products.MailHost.interfaces import IMailHost

        mockmailhost = MockMailHost("MailHost")

        if not hasattr(mockmailhost, "smtp_host"):
            mockmailhost.smtp_host = "localhost"

        self.portal.MailHost = mockmailhost
        sm = self.portal.getSiteManager()
        sm.registerUtility(component=mockmailhost, provided=IMailHost)

        self.mailhost = api.portal.get_tool("MailHost")
        registry = getUtility(IRegistry)
        self.mail_settings = registry.forInterface(IMailSchema, prefix="plone")
        self.mail_settings.email_from_name = u"Portal Owner"
        self.mail_settings.email_from_address = "*****@*****.**"

        self.browser = Browser(self.app)
        self.browser.handleErrors = False

        # Commit so that the test browser sees these changes
        import transaction

        transaction.commit()
示例#6
0
 def send(self, *kwargs):
     logger.log("***Message***")
     logger.log("From: {0}".format(kwargs["mfrom"]))
     logger.log("To: {0}".format(kwargs["mto"]))
     logger.log("Subject: {0}".format(kwargs["subject"]))
     logger.log("Length: {0}".format(len(kwargs["messageText"])))
     _MMH.send(self, *kwargs)
    def setUp(self):
        self.app = self.layer['app']
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        # Mock the mail host so we can test sending the email
        mockmailhost = MockMailHost('MailHost')

        if not hasattr(mockmailhost, 'smtp_host'):
            mockmailhost.smtp_host = 'localhost'

        self.portal.MailHost = mockmailhost
        sm = self.portal.getSiteManager()
        sm.registerUtility(component=mockmailhost, provided=IMailHost)

        self.mailhost = api.portal.get_tool('MailHost')

        self.portal._updateProperty('email_from_name', 'Portal Owner')
        self.portal._updateProperty('email_from_address', '*****@*****.**')

        self.browser = Browser(self.app)
        self.browser.handleErrors = False

        # Commit so that the test browser sees these changes
        import transaction
        transaction.commit()
示例#8
0
 def send(self, *kwargs):
     logger.log("***Message***")
     logger.log("From: {0}".format(kwargs['mfrom']))
     logger.log("To: {0}".format(kwargs['mto']))
     logger.log("Subject: {0}".format(kwargs['subject']))
     logger.log("Length: {0}".format(len(kwargs['messageText'])))
     _MMH.send(self, *kwargs)
示例#9
0
    def setUp(self):
        self.app = self.layer['app']
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        # Mock the mail host so we can test sending the email
        # NEVER EVER IMPORT MOCKMAILHOST OUTSIDE OF SETUP!
        # IT WILL BREAK YOUR TEST_ISOLATION AND KILL YOUR FIRSTBORN
        from Products.CMFPlone.tests.utils import MockMailHost
        from Products.MailHost.interfaces import IMailHost
        mockmailhost = MockMailHost('MailHost')

        if not hasattr(mockmailhost, 'smtp_host'):
            mockmailhost.smtp_host = 'localhost'

        self.portal.MailHost = mockmailhost
        sm = self.portal.getSiteManager()
        sm.registerUtility(component=mockmailhost, provided=IMailHost)

        self.mailhost = api.portal.get_tool('MailHost')
        registry = getUtility(IRegistry)
        self.mail_settings = registry.forInterface(IMailSchema, prefix="plone")
        self.mail_settings.email_from_name = u'Portal Owner'
        self.mail_settings.email_from_address = '*****@*****.**'

        self.browser = Browser(self.app)
        self.browser.handleErrors = False

        # Commit so that the test browser sees these changes
        import transaction
        transaction.commit()
示例#10
0
    def setUp(self):
        """Shared test environment set-up, ran before every test."""
        self.portal = self.layer['portal']

        # Mock the mail host so we can test sending the email
        mockmailhost = MockMailHost('MailHost')

        if not getattr(mockmailhost, 'smtp_host', None):
            mockmailhost.smtp_host = 'localhost'

        self.portal.MailHost = mockmailhost
        sm = self.portal.getSiteManager()
        sm.registerUtility(component=mockmailhost, provided=IMailHost)

        self.mailhost = portal.get_tool('MailHost')
        if HAS_PLONE5:
            portal.set_registry_record(
                'plone.email_from_name', u'Portal Owner'
            )
            portal.set_registry_record(
                'plone.email_from_address',
                '*****@*****.**'
            )
        else:
            self.portal._updateProperty('email_from_name', 'Portal Owner')
            self.portal._updateProperty(
                'email_from_address', '*****@*****.**'
            )
示例#11
0
    def setUp(self):
        """Shared test environment set-up, ran before every test."""
        self.portal = self.layer['portal']

        # Mock the mail host so we can test sending the email
        mockmailhost = MockMailHost('MailHost')

        if not getattr(mockmailhost, 'smtp_host', None):
            mockmailhost.smtp_host = 'localhost'

        self.portal.MailHost = mockmailhost
        sm = self.portal.getSiteManager()
        sm.registerUtility(component=mockmailhost, provided=IMailHost)

        self.mailhost = portal.get_tool('MailHost')
        if HAS_PLONE5:
            portal.set_registry_record(
                'plone.email_from_name',
                u'Portal Owner',
            )
            portal.set_registry_record(
                'plone.email_from_address',
                '*****@*****.**',
            )
        else:
            self.portal._updateProperty(
                'email_from_name',
                'Portal Owner',
            )
            self.portal._updateProperty(
                'email_from_address',
                '*****@*****.**',
            )
    def setUp(self):
        super(TestInvitationFormEmailing, self).setUp()
        self.login_as_portal_owner()
        provideAdapter(adapts=(Interface, IBrowserRequest),
                       provides=Interface,
                       factory=InviteForm,
                       name="invite")

        # create a workspace
        self.ws = api.content.create(
            self.portal,
            "ploneintranet.workspace.workspacefolder",
            "alejandro-workspace",
            title="Alejandro workspace")

        self.app = self.layer['app']
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        # don't import this at the top, because it screws up the setup
        # and none of the tests can run
        from Products.CMFPlone.tests.utils import MockMailHost
    #    # Mock the mail host so we can test sending the email
        mockmailhost = MockMailHost('MailHost')

        if not hasattr(mockmailhost, 'smtp_host'):
            mockmailhost.smtp_host = 'localhost'

        self.portal.MailHost = mockmailhost
        sm = self.portal.getSiteManager()
        sm.registerUtility(component=mockmailhost, provided=IMailHost)

        self.mailhost = api.portal.get_tool('MailHost')

        self.portal._updateProperty('email_from_name', 'Portal Owner')
        self.portal._updateProperty('email_from_address', '*****@*****.**')
示例#13
0
    def testRegisteredNotifyEncoding(self):
        mails = self.portal.MailHost = MockMailHost('MailHost')
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(mails, IMailHost)
        # Register a user
        self.registration.addMember(member_id,
                                    'secret',
                                    properties={
                                        'username': member_id,
                                        'email': '*****@*****.**'
                                    })
        # Set the portal email info
        self.portal.setTitle('Test Portal')
        self.portal.email_from_name = 'Test Admin'
        self.portal.email_from_address = '*****@*****.**'

        # Set the portal email encoding
        self.portal.email_charset = 'us-ascii'

        # Notify the registered user
        self.registration.registeredNotify(member_id)
        self.assertEqual(len(mails.messages), 1)
        msg = message_from_string(mails.messages[0])

        # Ensure charset (and thus Content-Type) were set via template
        self.assertEqual(msg['Content-Type'], 'text/plain; charset="us-ascii"')
    def testRegisteredNotifyEncoding(self):
        mails = self.portal.MailHost = MockMailHost('MailHost')
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(mails, IMailHost)
        # Register a user
        self.registration.addMember(member_id,
                                    'secret',
                                    properties={
                                        'username': member_id,
                                        'email': '*****@*****.**'
                                    })
        registry = getUtility(IRegistry)
        site_settings = registry.forInterface(ISiteSchema, prefix='plone')
        site_settings.site_title = 'Test Portal'
        mail_settings = registry.forInterface(IMailSchema, prefix="plone")
        mail_settings.email_from_name = 'Test Admin'
        mail_settings.email_from_address = '*****@*****.**'

        # Set the portal email encoding
        mail_settings.email_charset = 'us-ascii'

        # Notify the registered user
        self.registration.registeredNotify(member_id)
        self.assertEqual(len(mails.messages), 1)
        msg = message_from_bytes(mails.messages[0])

        # Ensure charset (and thus Content-Type) were set via template
        self.assertEqual(msg['Content-Type'], 'text/plain; charset="us-ascii"')
    def testRegisteredNotify(self):
        # tests email sending on registration
        # First install a fake mailhost utility
        mails = self.portal.MailHost = MockMailHost('MailHost')
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(mails, IMailHost)
        # Register a user
        self.registration.addMember(member_id,
                                    'secret',
                                    properties={
                                        'username': member_id,
                                        'email': '*****@*****.**'
                                    })

        registry = getUtility(IRegistry)
        site_settings = registry.forInterface(ISiteSchema, prefix='plone')
        site_settings.site_title = 'Tëst Portal'
        mail_settings = registry.forInterface(IMailSchema, prefix="plone")
        mail_settings.email_from_name = 'Tëst Admin'
        mail_settings.email_from_address = '*****@*****.**'

        # Notify the registered user
        self.registration.registeredNotify(member_id)
        self.assertEqual(len(mails.messages), 1)
        msg = message_from_bytes(mails.messages[0])
        # We get an encoded subject
        self.assertEqual(
            msg['Subject'],
            '=?utf-8?q?User_Account_Information_for_T=C3=ABst_Portal?=')
        # Also a partially encoded from header
        self.assertEqual(msg['From'],
                         '=?utf-8?q?T=C3=ABst_Admin?= <*****@*****.**>')
        self.assertEqual(msg['Content-Type'], 'text/plain; charset="utf-8"')
示例#16
0
    def setUp(self):
        self.app = self.layer["app"]
        self.request = self.layer["request"]
        self.portal = self.layer["portal"]
        self.portal_url = self.portal.absolute_url()
        setRoles(self.portal, TEST_USER_ID, ["Manager"])

        # set up blocksdocument content type with IBlock behavior
        fti = DexterityFTI("blocksdocument")
        self.portal.portal_types._setObject("blocksdocument", fti)
        fti.klass = "plone.dexterity.content.Container"
        fti.behaviors = ("volto.blocks", )
        self.portal.invokeFactory("blocksdocument", id="doc")
        self.doc = self.portal["doc"]
        alsoProvides(self.doc, IBlocks)

        # Set up a mock mailhost
        self.portal._original_MailHost = self.portal.MailHost
        self.portal.MailHost = mailhost = MockMailHost('MailHost')
        sm = getSiteManager(context=self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(mailhost, provided=IMailHost)

        # We need to fake a valid mail setup
        registry = getUtility(IRegistry)
        mail_settings = registry.forInterface(IMailSchema, prefix='plone')
        mail_settings.email_from_address = '*****@*****.**'
        self.mailhost = self.portal.MailHost

        transaction.commit()
示例#17
0
 def afterSetUp(self):
     self.portal._original_MailHost = self.portal.MailHost
     self.portal.MailHost = mailhost = MockMailHost('MailHost')
     sm = getSiteManager(context=self.portal)
     sm.unregisterUtility(provided=IMailHost)
     sm.registerUtility(mailhost, provided=IMailHost)
     transaction.commit()
示例#18
0
    def setUp(self):
        self.portal = self.layer["portal"]
        self.portal_url = self.portal.absolute_url()
        self.browser = Browser(self.portal)
        self.browser.handleErrors = False
        self.mail_settings = get_portal_mail_settings()
        self.mail_settings.email_from_address = "*****@*****.**"
        # Set up a mock mailhost
        self.portal._original_MailHost = self.portal.MailHost
        self.portal.MailHost = mailhost = MockMailHost("MailHost")
        self.portal.MailHost.smtp_host = "localhost"
        self.portal.MailHost.email_from_address = "*****@*****.**"
        sm = getSiteManager(context=self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(mailhost, provided=IMailHost)
        # We need to fake a valid mail setup

        # create EasyNewsletter instance and add some subscribers
        setRoles(self.portal, TEST_USER_ID, ["Manager"])
        # self.portal.portal_workflow.setDefaultChain(
        #     "simple_publication_workflow",
        # )
        self.portal.invokeFactory("Newsletter", "enl1", title="ENL 1")
        self.newsletter = self.portal.get("enl1")
        self.newsletter.senderEmail = "*****@*****.**"
        self.newsletter.senderName = "ACME newsletter"
        self.newsletter.testEmail = "*****@*****.**"

        # Commit so that the test browser sees these changes
        import transaction as zt

        zt.commit()
示例#19
0
    def setUp(self):
        self.portal = self.layer['portal']
        self.portal_url = self.portal.portal_url()
        # create EasyNewsletter instance and add some subscribers
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        login(self.portal, TEST_USER_NAME)
        self.portal._original_MailHost = self.portal.MailHost
        self.portal.MailHost = mailhost = MockMailHost('MailHost')
        sm = getSiteManager(context=self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(mailhost, provided=IMailHost)
        self.mail_host = getUtility(IMailHost)

        if not IS_PLONE_5:  # BBB
            self.portal.email_from_address = "*****@*****.**"
            self.portal.email_from_name = u"Plone Master"
            self.mail_host.smtp_host = u"example.com"
            self.mail_host.smtp_port = 25
            self.mail_host.smtp_userid = u"*****@*****.**"
            self.mail_host.smtp_pass = u"Password"
        else:
            self.registry = getUtility(IRegistry)
            reg_mail = self.registry.forInterface(
                IMailSchema, prefix='plone')
            reg_mail.email_from_address = '*****@*****.**'
            reg_mail.email_from_name = u'Plone Master'
            reg_mail.smtp_host = u'example.com'
            reg_mail.smtp_port = 25
            reg_mail.smtp_userid = u'*****@*****.**'
            reg_mail.smtp_pass = u'Password'
示例#20
0
    def setUpPloneSite(self, portal):
        # Workaround for the importVocabularies setuphandler calls
        # createSimpleVocabs which throws:
        # KeyError: 'ACTUAL_URL'
        portal.REQUEST["ACTUAL_URL"] = portal.REQUEST["SERVER_URL"]

        # Install all the Plone stuff + content (including the
        # Members folder)
        applyProfile(portal, 'Products.CMFPlone:plone')
        applyProfile(portal, 'Products.CMFPlone:plone-content')

        # quick install ATVocabularyManager or else we don't have
        # portal.portal_vocabularies
        quickInstallProduct(portal, "Products.ATVocabularyManager")
        quickInstallProduct(portal, "Products.PloneHelpCenter")
        quickInstallProduct(portal, "Products.ATCountryWidget")
        quickInstallProduct(portal, "Products.Collage")
        quickInstallProduct(portal, "plonetheme.classic")
        quickInstallProduct(portal, "Products.LinguaPlone")
        quickInstallProduct(portal, 'osha.adaptation')
        quickInstallProduct(portal, 'slc.googlesearch')

        applyProfile(portal, 'osha.policy:default')
        applyProfile(portal, 'osha.theme:default')
        applyProfile(portal, 'slc.linkcollection:default')

        # Needed to properly install content types
        applyProfile(portal, 'Products.RichDocument:default')
        applyProfile(portal, 'Products.RemoteProvider:default')
        applyProfile(portal, 'Products.CaseStudy:default')
        applyProfile(portal, 'Products.OSHContentLink:default')
        applyProfile(portal, 'slc.seminarportal:default')
        applyProfile(portal, 'slc.outdated:default')
        applyProfile(portal, 'Products.PloneHelpCenter:default')
        applyProfile(portal, 'osha.whoswho:default')

        # We need this imports here, otherwise we get an error
        from Products.CMFPlone.tests.utils import MockMailHost
        from Products.MailHost.interfaces import IMailHost

        # Mock MailHost
        mockmailhost = MockMailHost('MailHost')
        portal.MailHost = mockmailhost
        sm = portal.getSiteManager()
        sm.registerUtility(component=mockmailhost, provided=IMailHost)

        # Login as manager and create a test folder
        setRoles(portal, TEST_USER_ID, ['Manager'])
        login(portal, TEST_USER_NAME)
        portal.invokeFactory('Folder', 'folder')

        # Enable Members folder
        from plone.app.controlpanel.security import ISecuritySchema
        security_adapter = ISecuritySchema(portal)
        security_adapter.set_enable_user_folders(True)

        # Commit so that the test browser sees these objects
        portal.portal_catalog.clearFindAndRebuild()
        import transaction
        transaction.commit()
示例#21
0
def setUp(self):
    layer = self.globs['layer']
    browser = Browser(layer['app'])
    portal = layer['portal']
    self.globs.update({
        'browser': browser,
        'portal': portal,
        'TEST_USER_NAME': TEST_USER_NAME,
        'TEST_USER_PASSWORD': TEST_USER_PASSWORD,
    })

    browser.setBaseUrl(portal.absolute_url())

    browser.handleErrors = True
    portal.error_log._ignored_exceptions = ()

    setRoles(portal, TEST_USER_ID, ['Manager'])

    # portal._original_MailHost = portal.MailHost
    portal.MailHost = mailhost = MockMailHost('MailHost')
    sm = getSiteManager(context=portal)
    sm.unregisterUtility(provided=IMailHost)
    sm.registerUtility(mailhost, provided=IMailHost)
    self.globs['messages'] = mailhost.messages
    self.globs['prink'] = prink

    transaction.commit()
    def testMailPassword(self):
        # tests email sending for password emails
        # First install a fake mailhost utility
        mails = self.portal.MailHost = MockMailHost('MailHost')
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(mails, IMailHost)
        # Register a user
        self.registration.addMember(member_id,
                                    'secret',
                                    properties={
                                        'username': member_id,
                                        'email': '*****@*****.**'
                                    })

        registry = getUtility(IRegistry)
        site_settings = registry.forInterface(ISiteSchema, prefix='plone')
        site_settings.site_title = u'Tëst Portal'
        mail_settings = registry.forInterface(IMailSchema, prefix="plone")
        mail_settings.email_from_name = u'Tëst Admin'
        mail_settings.email_from_address = '*****@*****.**'

        from zope.publisher.browser import TestRequest
        self.registration.mailPassword(member_id, TestRequest())
        self.assertEqual(len(mails.messages), 1)
        msg = message_from_string(mails.messages[0])
        # We get an encoded subject
        self.assertEqual(msg['Subject'], '=?utf-8?q?Password_reset_request?=')
        # Also a partially encoded from header
        self.assertEqual(msg['From'],
                         '=?utf-8?q?T=C3=ABst_Admin?= <*****@*****.**>')
        self.assertEqual(msg['Content-Type'], 'text/plain; charset="utf-8"')
示例#23
0
 def setUp(self):
     self.portal = self.layer['portal']
     setRoles(self.portal, TEST_USER_ID, ['Manager'])
     # Set up a mock mailhost
     self.portal._original_MailHost = self.portal.MailHost
     self.portal.MailHost = mailhost = MockMailHost('MailHost')
     sm = getSiteManager(context=self.portal)
     sm.unregisterUtility(provided=IMailHost)
     sm.registerUtility(mailhost, provided=IMailHost)
     # We need to fake a valid mail setup
     registry = getUtility(IRegistry)
     mail_settings = registry.forInterface(IMailSchema, prefix='plone')
     mail_settings.email_from_address = '*****@*****.**'
     self.mailhost = self.portal.MailHost
     # Enable comment moderation
     self.portal.portal_types['Document'].allow_discussion = True
     self.portal.portal_workflow.setChainForPortalTypes(
         ('Discussion Item', ), ('comment_review_workflow', ))
     # Enable moderator notification setting
     registry = queryUtility(IRegistry)
     registry['plone.app.discussion.interfaces.IDiscussionSettings.' +
              'moderator_notification_enabled'] = True
     # Archetypes content types store data as utf-8 encoded strings
     # The missing u in front of a string is therefor not missing
     self.portal.doc1.title = 'Kölle Alaaf'  # What is 'Fasching'?
     self.conversation = IConversation(self.portal.doc1)
示例#24
0
 def setUp(self):
     self.portal = self.layer["portal"]
     self.portal_url = self.portal.portal_url()
     # create EasyNewsletter instance and add some subscribers
     setRoles(self.portal, TEST_USER_ID, ["Manager"])
     self.portal.portal_workflow.setDefaultChain(
         "simple_publication_workflow", )
     login(self.portal, TEST_USER_NAME)
     self.portal.invokeFactory("Newsletter", "enl1", title="ENL 1")
     self.newsletter = self.portal.get("enl1")
     self.newsletter.senderEmail = "*****@*****.**"
     self.newsletter.senderName = "ACME newsletter"
     self.newsletter.testEmail = "*****@*****.**"
     self.mail_settings = get_portal_mail_settings()
     # Set up a mock mailhost
     self.portal._original_MailHost = self.portal.MailHost
     self.portal.MailHost = mailhost = MockMailHost("MailHost")
     self.portal.MailHost.smtp_host = "localhost"
     registry = getUtility(IRegistry)
     self.mail_settings = registry.forInterface(IMailSchema, prefix="plone")
     self.mail_settings.email_from_address = "*****@*****.**"
     self.mail_settings.smtp_host = "localhost"
     sm = getSiteManager(context=self.portal)
     sm.unregisterUtility(provided=IMailHost)
     sm.registerUtility(mailhost, provided=IMailHost)
     # We need to fake a valid mail setup
     self.mailhost = self.portal.MailHost
     self.enl_reg_tool = getUtility(IENLRegistrationTool,
                                    "enl_registration_tool")
示例#25
0
    def afterSetUp(self):
        """ Set up """
        self.portal._original_MailHost = self.portal.MailHost
        self.portal.MailHost = mailhost = MockMailHost('MailHost')
        sm = getSiteManager(context=self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(mailhost, provided=IMailHost)

        self.workflow = self.portal.portal_workflow
        self.portal.acl_users._doAddUser('manager', 'secret', ['Manager'], [])
        self.setRoles('Manager')

        if not hasattr(self.folder, 'sandbox'):
            self.folder.invokeFactory('Folder', 'sandbox')
        self.sandbox = self.folder['sandbox']

        children = list(self.ptypes)
        self.sandbox.setConstrainTypesMode(1)
        self.sandbox.setImmediatelyAddableTypes(children)
        self.sandbox.setLocallyAllowedTypes(children)

        ptypes = self.portal.portal_types
        for ptype in children:
            ptypes[ptype].global_allow = True

        for ptype in self.ptypes:
            try:
                self.sandbox.invokeFactory(ptype, id=ptype, title=ptype)
            except Exception:
                continue
 def setUp(self):
     self.portal = self.layer['portal']
     self.portal_url = self.portal.portal_url()
     # create EasyNewsletter instance and add some subscribers
     setRoles(self.portal, TEST_USER_ID, ['Manager'])
     login(self.portal, TEST_USER_NAME)
     self.portal.invokeFactory('EasyNewsletter', 'enl1', title=u"ENL 1")
     self.newsletter = self.portal.get('enl1')
     self.newsletter.senderEmail = "*****@*****.**"
     self.newsletter.senderName = "ACME newsletter"
     self.newsletter.testEmail = "*****@*****.**"
     self.mail_settings = get_portal_mail_settings()
     # Set up a mock mailhost
     self.portal._original_MailHost = self.portal.MailHost
     self.portal.MailHost = mailhost = MockMailHost('MailHost')
     self.portal.MailHost.smtp_host = 'localhost'
     if not IS_PLONE_5:  # BBB
         self.portal.email_from_address = "*****@*****.**"
     else:
         registry = getUtility(IRegistry)
         self.mail_settings = registry.forInterface(IMailSchema,
                                                    prefix='plone')
         self.mail_settings.email_from_address = "*****@*****.**"
         self.mail_settings.smtp_host = u"localhost"
     sm = getSiteManager(context=self.portal)
     sm.unregisterUtility(provided=IMailHost)
     sm.registerUtility(mailhost, provided=IMailHost)
     # We need to fake a valid mail setup
     self.mailhost = self.portal.MailHost
     self.newsletter.invokeFactory("ENLIssue", id="issue")
     self.newsletter.issue.title = \
         "This is a very long newsletter issue title with special "\
         "characters such as äüö. Will this really work?"
 def testRegisteredNotify(self):
     # tests email sending on registration
     # First install a fake mailhost utility
     mails = self.portal.MailHost = MockMailHost('MailHost')
     sm = getSiteManager(self.portal)
     sm.unregisterUtility(provided=IMailHost)
     sm.registerUtility(mails, IMailHost)
     # Register a user
     self.registration.addMember(member_id,
                                 'secret',
                                 properties={
                                     'username': member_id,
                                     'email': '*****@*****.**'
                                 })
     # Set the portal email info
     self.portal.setTitle('T\xc3\xa4st Portal')
     self.portal.email_from_name = 'T\xc3\xa4st Admin'
     self.portal.email_from_address = '*****@*****.**'
     self.registration.registeredNotify(member_id)
     self.assertEqual(len(mails.messages), 1)
     msg = message_from_string(mails.messages[0])
     # We get an encoded subject
     self.assertEqual(
         msg['Subject'],
         '=?utf-8?q?User_Account_Information_for_T=C3=A4st_Portal?=')
     # Also a partially encoded from header
     self.assertEqual(msg['From'],
                      '=?utf-8?q?T=C3=A4st_Admin?= <*****@*****.**>')
     self.assertEqual(msg['Content-Type'], 'text/plain; charset="utf-8"')
     # And a Quoted Printable encoded body
     self.failUnless('T=C3=A4st Admin' in msg.get_payload())
    def testMailPasswordEncoding(self):
        # tests email sending for password emails
        # First install a fake mailhost utility
        mails = self.portal.MailHost = MockMailHost('MailHost')
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(mails, IMailHost)
        # Register a user
        self.registration.addMember(member_id,
                                    'secret',
                                    properties={
                                        'username': member_id,
                                        'email': '*****@*****.**'
                                    })
        registry = getUtility(IRegistry)
        site_settings = registry.forInterface(ISiteSchema, prefix='plone')
        site_settings.site_title = u'Tëst Portal'
        mail_settings = registry.forInterface(IMailSchema, prefix="plone")
        mail_settings.email_from_name = u'Test Admin'
        mail_settings.email_from_address = '*****@*****.**'

        # Set the portal email encoding
        mail_settings.email_charset = 'us-ascii'

        from zope.publisher.browser import TestRequest
        self.registration.mailPassword(member_id, TestRequest())
        self.assertEqual(len(mails.messages), 1)
        msg = message_from_string(mails.messages[0])

        # Ensure charset (and thus Content-Type) were set via template
        self.assertEqual(msg['Content-Type'], 'text/plain; charset="us-ascii"')
示例#29
0
    def setUpPloneSite(self, portal):
        """Set up Plone."""
        # Install into Plone site using portal_setup
        applyProfile(portal, 'niteoweb.jvzoo:default')

        # Login as Manager
        setRoles(portal, TEST_USER_ID, ['Manager'])
        login(portal, TEST_USER_NAME)

        # Mock mailhost
        portal.email_from_address = '*****@*****.**'
        mockmailhost = MockMailHost('MailHost')
        portal.MailHost = mockmailhost
        sm = getSite().getSiteManager()
        sm.registerUtility(component=mockmailhost, provided=IMailHost)

        # Commit so that the test browser sees these objects
        portal.portal_catalog.clearFindAndRebuild()
        import transaction
        transaction.commit()

        # add a logging handler that stores everything in a list so we can
        # later assert on it
        logger = logging.getLogger('niteoweb.jvzoo')
        logger.addHandler(MockedLoggingHandler())
示例#30
0
 def afterSetUp(self):
     # Use the fake mailhost
     self.portal._original_MailHost = self.portal.MailHost
     self.portal.MailHost = MockMailHost('MailHost')
     roles = ('Member', 'Contributor')
     self.portal.portal_membership.addMember('contributor', 'secret', roles,
                                             [])
 def setUp(self):
     self.mail_settings = get_portal_mail_settings()
     self.portal = self.layer['portal']
     setRoles(self.portal, TEST_USER_ID, ['Manager'])
     login(self.portal, TEST_USER_NAME)
     self.portal.invokeFactory('Folder', 'test-folder')
     self.folder = self.portal['test-folder']
     self.portal = self.layer['portal']
     self.folder.invokeFactory("EasyNewsletter", "newsletter")
     self.newsletter = self.folder.newsletter
     self.newsletter.senderEmail = "*****@*****.**"
     self.newsletter.senderName = "ACME newsletter"
     self.newsletter.testEmail = "*****@*****.**"
     # Set up a mock mailhost
     self.portal._original_MailHost = self.portal.MailHost
     self.portal.MailHost = mailhost = MockMailHost('MailHost')
     sm = getSiteManager(context=self.portal)
     sm.unregisterUtility(provided=IMailHost)
     sm.registerUtility(mailhost, provided=IMailHost)
     # We need to fake a valid mail setup
     # self.mail_settings.email_from_address = u'*****@*****.**'
     self.mailhost = self.portal.MailHost
     # image for image testing
     self.folder.invokeFactory("Image", "image")
     self.image = self.folder.image
     image = self.folder['image']
     image.title = 'My Image'
     image.description = 'This is my image.'
     image.image = dummy_image(image)
     self.image = image
示例#32
0
    def setUp(self):

        # treat sqlalchemy warnings as errors
        import warnings
        from sqlalchemy.exc import SAWarning
        warnings.simplefilter("error", SAWarning)

        self.app = self.layer['app']
        self.portal = self.layer['portal']

        # setup mock mail host
        self._original_MailHost = self.portal.MailHost
        self.portal.MailHost = mailhost = MockMailHost('MailHost')
        sm = getSiteManager(context=self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(mailhost, provided=IMailHost)

        self.portal.email_from_address = '*****@*****.**'

        # remove all test event subscribers
        event.subscribers = [
            e for e in event.subscribers if type(e) != TestEventSubscriber
        ]
        setuphandlers.dbsetup(None)

        self.setup_expected_date_formats()
        self.logged_in = False
示例#33
0
    def setUp(self):
        self.portal = self.layer["portal"]
        self.catalog = getToolByName(self.portal, "portal_catalog")
        setRoles(self.portal, TEST_USER_ID, ["Manager"])

        # creating test objects: folder, news, newsletter and subscriber
        self.portal.invokeFactory("Folder", "testfolder")
        self.folder = self.portal["testfolder"]
        self.folder.invokeFactory("News Item", "news01")

        self.folder.invokeFactory("EasyNewsletter", "daily-news")
        self.newsletter = self.folder["daily-news"]
        self.newsletter.setTitle("Daily News")

        criteria = self.newsletter.addCriterion("portal_type",
                                                "ATSimpleStringCriterion")
        criteria.setValue("News Item")

        self.newsletter.invokeFactory("ENLSubscriber", "subscriber01")
        self.view = getMultiAdapter((self.newsletter, self.layer["request"]),
                                    name="daily-issue")

        self.mail_settings = get_portal_mail_settings()
        self.mail_settings.email_from_address = "*****@*****.**"
        # setting a Mock mailhost
        self.portal._original_MailHost = self.portal.MailHost
        self.portal.MailHost = mailhost = MockMailHost("MailHost")
        sm = getSiteManager(context=self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(mailhost, provided=IMailHost)
示例#34
0
 def testMailPassword(self):
     # tests email sending for password emails
     # First install a fake mailhost utility
     mails = self.portal.MailHost = MockMailHost('MailHost')
     sm = getSiteManager(self.portal)
     sm.unregisterUtility(provided=IMailHost)
     sm.registerUtility(mails, IMailHost)
     # Register a user
     self.registration.addMember(member_id,
                                 'secret',
                                 properties={
                                     'username': member_id,
                                     'email': '*****@*****.**'
                                 })
     # Set the portal email info
     self.portal.setTitle('T\xc3\xa4st Portal')
     self.portal.email_from_name = 'T\xc3\xa4st Admin'
     self.portal.email_from_address = '*****@*****.**'
     from zope.publisher.browser import TestRequest
     self.registration.mailPassword(member_id, TestRequest())
     self.assertEqual(len(mails.messages), 1)
     msg = message_from_string(mails.messages[0])
     # We get an encoded subject
     self.assertEqual(msg['Subject'], '=?utf-8?q?Password_reset_request?=')
     # Also a partially encoded from header
     self.assertEqual(msg['From'],
                      '=?utf-8?q?T=C3=A4st_Admin?= <*****@*****.**>')
     self.assertEqual(msg['Content-Type'], 'text/plain; charset="utf-8"')
     # And a Quoted Printable encoded body
     self.assertTrue('T=C3=A4st Porta' in msg.get_payload())
 def afterSetUp(self):
     self.portal._original_MailHost = self.portal.MailHost
     self.portal.MailHost = MockMailHost('MailHost')
     PHCTestCase.PHCTestCase.afterSetUp(self)
     self.tf = self.folder.hc.tutorial  # tutorial folder
     self.tf.invokeFactory('HelpCenterTutorial', id='t')
     self.tutorial = self.tf.t
     self.tutorial.invokeFactory('HelpCenterLeafPage', 'page1')
示例#36
0
 def _setup_mockmail(self):
     sm = getSiteManager(self.portal)
     sm.unregisterUtility(provided=IMailHost)
     dummyMailHost = MockMailHost('MailHost')
     sm.registerUtility(dummyMailHost, IMailHost)
     self.portal._original_MailHost = self.portal.MailHost
     self.portal.MailHost = dummyMailHost
     return dummyMailHost
 def afterSetUp(self):
     self.portal._original_MailHost = self.portal.MailHost
     self.portal.MailHost = mailhost = MockMailHost('MailHost')
     mailhost.smtp_host = 'localhost'
     sm = getSiteManager(context=self.portal)
     sm.unregisterUtility(provided=IMailHost)
     sm.registerUtility(mailhost, provided=IMailHost)
     self.portal.email_from_address = '*****@*****.**'
示例#38
0
    def setUp(self):
        """Shared test environment set-up, ran before every test."""
        self.portal = self.layer["portal"]

        # Mock the mail host so we can test sending the email
        mockmailhost = MockMailHost("MailHost")

        if not hasattr(mockmailhost, "smtp_host"):
            mockmailhost.smtp_host = "localhost"

        self.portal.MailHost = mockmailhost
        sm = self.portal.getSiteManager()
        sm.registerUtility(component=mockmailhost, provided=IMailHost)

        self.mailhost = portal.get_tool("MailHost")

        self.portal._updateProperty("email_from_name", "Portal Owner")
        self.portal._updateProperty("email_from_address", "*****@*****.**")
示例#39
0
    def setUp(self):
        """Shared test environment set-up, ran before every test."""
        self.portal = self.layer['portal']

        # Mock the mail host so we can test sending the email
        mockmailhost = MockMailHost('MailHost')

        if not hasattr(mockmailhost, 'smtp_host'):
            mockmailhost.smtp_host = 'localhost'

        self.portal.MailHost = mockmailhost
        sm = self.portal.getSiteManager()
        sm.registerUtility(component=mockmailhost, provided=IMailHost)

        self.mailhost = getToolByName(self.portal, 'MailHost')

        self.portal._updateProperty('email_from_name', 'Portal Owner')
        self.portal._updateProperty('email_from_address', '*****@*****.**')
示例#40
0
    def setUpPloneSite(self, portal):
        super(EestecPortalLayer, self).setUpPloneSite(portal)

        # Mock MailHost
        mockmailhost = MockMailHost('MailHost')
        mockmailhost.smtp_host = 'nohost'
        portal.MailHost = mockmailhost
        sm = api.portal.get().getSiteManager()
        sm.registerUtility(component=mockmailhost, provided=IMailHost)

        # Login
        setRoles(portal, TEST_USER_ID, ['Manager'])
        login(portal, TEST_USER_NAME)

        # Rebuild the catalog and commit changes
        portal.portal_catalog.clearFindAndRebuild()
        import transaction
        transaction.commit()