Esempio n. 1
0
    def test_send_bulletin_factory_exception(self):
        stdout = StringIO()
        stderr = StringIO()

        def call_ESMTPSenderFactory(username,
                                    password,
                                    fromEmail,
                                    toEmail,
                                    f,
                                    d,
                                    retries=5,
                                    timeout=None,
                                    contextFactory=None,
                                    heloFallback=False,
                                    requireAuthentication=True,
                                    requireTransportSecurity=True):
            raise MarkerException()

        self.patch(send_email, 'ESMTPSenderFactory', call_ESMTPSenderFactory)

        d = send_bulletin(self.PUBIP, self.CUSTOMER_NAME, self.CUSTOMER_EMAIL,
                          '', stdout, stderr)

        def _bad_success(ign):
            self.fail("should have got a failure")

        def _check_failure(f):
            f.trap(MarkerException)
            out = stdout.getvalue()
            self.failUnlessIn("Sending of bulletin e-mail failed", out)

        d.addCallbacks(_bad_success, _check_failure)
        return d
Esempio n. 2
0
    def _test_send_bulletin_success(self, call_factory, customer_keyinfo):
        self.the_factory = Mock()
        self.patch(send_email, 'ESMTPSenderFactory', call_factory)

        connected = {}

        def call_connectTCP(smtphost, port, factory):
            self.failUnlessEqual(smtphost, self.SMTP_HOST)
            self.failUnlessEqual(port, self.SMTP_PORT)
            self.failUnlessEqual(factory, self.the_factory)
            self.failUnlessEqual(factory.domain, self.SENDER_DOMAIN)
            connected['flag'] = True

        self.patch(send_email, 'connectTCP', call_connectTCP)

        stdout = StringIO()
        stderr = StringIO()
        d = send_bulletin(self.PUBIP, self.CUSTOMER_NAME, self.CUSTOMER_EMAIL,
                          customer_keyinfo, stdout, stderr)

        def _check(ign):
            self.failUnless('flag' in connected)
            out = stdout.getvalue()
            self.failUnlessIn("update bulletin e-mail", out)
            self.failUnlessIn(self.CUSTOMER_EMAIL, out)
            self.failUnlessIn("sent.", out)

        d.addCallback(_check)
        return d
    def test_send_bulletin_factory_exception(self):
        stdout = StringIO()
        stderr = StringIO()

        def call_ESMTPSenderFactory(username, password, fromEmail, toEmail, f, d,
                                    retries=5, timeout=None, contextFactory=None, heloFallback=False,
                                    requireAuthentication=True, requireTransportSecurity=True):
            raise MarkerException()
        self.patch(send_email, 'ESMTPSenderFactory', call_ESMTPSenderFactory)

        d = send_bulletin(self.PUBIP, self.CUSTOMER_NAME, self.CUSTOMER_EMAIL, '', stdout, stderr)
        def _bad_success(ign):
            self.fail("should have got a failure")
        def _check_failure(f):
            f.trap(MarkerException)
            out = stdout.getvalue()
            self.failUnlessIn("Sending of bulletin e-mail failed", out)
        d.addCallbacks(_bad_success, _check_failure)
        return d
    def _test_send_bulletin_success(self, call_factory, customer_keyinfo):
        self.the_factory = Mock()
        self.patch(send_email, 'ESMTPSenderFactory', call_factory)

        connected = {}
        def call_connectTCP(smtphost, port, factory):
            self.failUnlessEqual(smtphost, self.SMTP_HOST)
            self.failUnlessEqual(port, self.SMTP_PORT)
            self.failUnlessEqual(factory, self.the_factory)
            self.failUnlessEqual(factory.domain, self.SENDER_DOMAIN)
            connected['flag'] = True
        self.patch(send_email, 'connectTCP', call_connectTCP)

        stdout = StringIO()
        stderr = StringIO()
        d = send_bulletin(self.PUBIP, self.CUSTOMER_NAME, self.CUSTOMER_EMAIL, customer_keyinfo, stdout, stderr)
        def _check(ign):
            self.failUnless('flag' in connected)
            out = stdout.getvalue()
            self.failUnlessIn("update bulletin e-mail", out)
            self.failUnlessIn(self.CUSTOMER_EMAIL, out)
            self.failUnlessIn("sent.", out)
        d.addCallback(_check)
        return d