<s> from __future__ import unicode_literals <EOL> import os <EOL> import unittest <EOL> from django . core import mail <EOL> from django . test import TestCase <EOL> from django . test . utils import override_settings <EOL> from djrill import MandrillAPIError , MandrillRecipientsRefused <EOL> MANDRILL_TEST_API_KEY = os . getenv ( '<STR_LIT>' ) <EOL> @ unittest . skipUnless ( MANDRILL_TEST_API_KEY , <EOL> "<STR_LIT>" ) <EOL> @ override_settings ( MANDRILL_API_KEY = MANDRILL_TEST_API_KEY , <EOL> EMAIL_BACKEND = "<STR_LIT>" ) <EOL> class DjrillIntegrationTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . message = mail . EmailMultiAlternatives ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> self . message . attach_alternative ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> def test_send_mail ( self ) : <EOL> sent_count = self . message . send ( ) <EOL> self . assertEqual ( sent_count , <NUM_LIT:1> ) <EOL> response = self . message . mandrill_response <EOL> self . assertIn ( response [ <NUM_LIT:0> ] [ '<STR_LIT:status>' ] , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( response [ <NUM_LIT:0> ] [ '<STR_LIT:email>' ] , '<STR_LIT>' ) <EOL> self . assertGreater ( len ( response [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> def test_invalid_from ( self ) : <EOL> self . message . from_email = '<STR_LIT>' <EOL> try : <EOL> self . message . send ( ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except MandrillAPIError as err : <EOL> self . assertEqual ( err . status_code , <NUM_LIT> ) <EOL> self . assertIn ( "<STR_LIT>" , str ( err ) ) <EOL> def test_invalid_to ( self ) : <EOL> self . message . to = [ '<STR_LIT>' ] <EOL> try : <EOL> self . message . send ( ) <EOL> except MandrillRecipientsRefused : <EOL> response = self . message . mandrill_response <EOL> self . assertEqual ( response [ <NUM_LIT:0> ] [ '<STR_LIT:status>' ] , '<STR_LIT>' ) <EOL> else : <EOL> response = self . message . mandrill_response <EOL> if response [ <NUM_LIT:0> ] [ '<STR_LIT:status>' ] == '<STR_LIT>' : <EOL> self . skipTest ( "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_rejected_to ( self ) : <EOL> self . message . to = [ '<STR_LIT>' ] <EOL> try : <EOL> self . message . send ( ) <EOL> except MandrillRecipientsRefused : <EOL> response = self . message . mandrill_response <EOL> self . assertEqual ( response [ <NUM_LIT:0> ] [ '<STR_LIT:status>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( response [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , '<STR_LIT:test>' ) <EOL> else : <EOL> response = self . message . mandrill_response <EOL> if response [ <NUM_LIT:0> ] [ '<STR_LIT:status>' ] == '<STR_LIT>' : <EOL> self . skipTest ( "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> @ override_settings ( MANDRILL_API_KEY = "<STR_LIT>" ) <EOL> def test_invalid_api_key ( self ) : <EOL> try : <EOL> self . message . send ( ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except MandrillAPIError as err : <EOL> self . assertEqual ( err . status_code , <NUM_LIT> ) <EOL> self . assertIn ( "<STR_LIT>" , str ( err ) ) </s>
