Beispiel #1
0
    def test_service_exception(self):
        email.add_service(self.fake_service2)

        # no send function, exception should be handled
        result = email.send('*****@*****.**', '*****@*****.**', 'subject', 'body')
        self.assertFalse(result)

        self.fake_service.send = Mock()
        self.fake_service.send.side_effect = Exception('Oops')

        result = email.send('*****@*****.**', '*****@*****.**', 'subject', 'body')
        self.assertFalse(result)
Beispiel #2
0
def send_email(from_email, to_email, subject, body):
    from uber import email
    success = email.send(from_email, to_email, subject, body)

    task_id = send_email.request.id
    email_status = EmailStatus.objects.get(task_id=task_id)

    if success:
        email_status.status = constants.EMAIL_STATUS['success']
    else:
        email_status.status = constants.EMAIL_STATUS['failure']

    email_status.save()
Beispiel #3
0
    def test_service_success(self):
        email.add_service(self.fake_service2)

        self.fake_service.send = Mock()
        self.fake_service.send.return_value = False

        self.fake_service2.send = Mock()
        self.fake_service2.send.return_value = True

        # repeat 10 times to make sure the service failure isn't causing
        # the send to fail
        results = [email.send('*****@*****.**', '*****@*****.**', 'subject', 'body') for x in xrange(10)]

        self.assertNotIn(False, results)
Beispiel #4
0
    def test_multi_service_failure(self):
        email.add_service(self.fake_service2)

        self.fake_service.send = Mock()
        self.fake_service.send.return_value = False

        self.fake_service2.send = Mock()
        self.fake_service2.send.return_value = False

        result = email.send('*****@*****.**', '*****@*****.**', 'subject', 'body')
        self.assertFalse(result)

        self.fake_service.send.assert_called_with('*****@*****.**', '*****@*****.**', 'subject', 'body')
        self.fake_service2.send.assert_called_with('*****@*****.**', '*****@*****.**', 'subject', 'body')
Beispiel #5
0
def index():
    form = EmailForm()

    if form.validate_on_submit():
        from_email = form.from_email.data
        to_email = form.to_email.data
        subject = form.subject.data
        body = form.body.data

        success = email.send(from_email, to_email, subject, body)

        if success:
            flash('Email sent!', 'success')
        else:
            flash(
                'There was a problem sending your email! Please try again later.',
                'error')

    recent_results = EmailServiceResult.objects.order_by('-timestamp').limit(
        20)

    return render_template('index.html',
                           form=form,
                           recent_results=recent_results)
Beispiel #6
0
    def test_service_failure(self):
        self.fake_service.send = Mock()
        self.fake_service.send.return_value = False

        result = email.send('*****@*****.**', '*****@*****.**', 'subject', 'body')
        self.assertFalse(result)
Beispiel #7
0
    def test_service_error(self):
        self.fake_service.send = Mock()
        self.fake_service.send.side_effect = requests.ConnectionError('Could not connect')

        result = email.send('*****@*****.**', '*****@*****.**', 'subject', 'body')
        self.assertFalse(result)
Beispiel #8
0
    def test_service_send(self):
        self.fake_service.send = Mock()
        email.send('*****@*****.**', '*****@*****.**', 'subject', 'body')

        self.fake_service.send.assert_called_with('*****@*****.**', '*****@*****.**', 'subject', 'body')