コード例 #1
0
 def test_mandril_get_status_failure(self, post):
     
     data = {
      "id" : "45ccde84-78b2-4e91-b460-609d0c678ad5",
      "email" : "*****@*****.**"
     }
     
     post.side_effect = ConnectTimeout
     
     mandril_mailer = MandrilMailer()
     status_info = mandril_mailer.get_message_status(data)
     
     assert status_info == None
コード例 #2
0
 def test_mandril_get_status_successful(self, post):
     
     data = {
      "id" : "45ccde84-78b2-4e91-b460-609d0c678ad5",
      "email" : "*****@*****.**"
     }
     
     post.return_value.status_code = 200
     post.return_value.content = '{ "state" : "sent" }'
     
     mandril_mailer = MandrilMailer()
     status_info = mandril_mailer.get_message_status(data)
     
     assert status_info['status'] == 'sent'
コード例 #3
0
 def test_mandril_send_message_successful(self, post):
     
     data = {
          "from_email" : "Testing API <*****@*****.**>",
          "to" : ["*****@*****.**"],
          "subject" : "Testing API",
          "text" : "test"
     }
     
     post.return_value.status_code = 200
     post.return_value.content = '[{"email" : "*****@*****.**", "_id" : "someid"}]'
     
     mandril_mailer = MandrilMailer()
     messages_info = mandril_mailer.send_message(**data)
     
     assert len(messages_info) == 1
     assert messages_info[0]['email_address'] == '*****@*****.**'
     assert messages_info[0]['id'] == 'someid'
コード例 #4
0
 def test_mandril_end_message_failure(self, post):
     
     data = {
          "from_email" : "Testing API <*****@*****.**>",
          "to" : ["*****@*****.**"],
          "subject" : "Testing API",
          "text" : "test"
     }
     
     post.return_value.status_code = 400
     
     mandril_mailer = MandrilMailer()
     self.assertRaises(MailNotSentException,mandril_mailer.send_message, **data)
コード例 #5
0
# Setup flask
app = Flask(__name__)

# Setup Redis
redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379')
conn = redis.from_url(redis_url)
q = Queue(connection=conn)

# Setup mailers
# When checking status of a message, we'll use the mailers directly as these
# calls shouldn't take too much of time. Also, because our worker doesn't poll
# for status in the background automatically.
# Ideally we should have a worker that polls the underlying email service to get the
# status of the messages that were sent using it
mailgun_mailer = MailGunMailer()
mandril_mailer = MandrilMailer()

available_mailers = {
    mailgun_mailer.__class__.__name__: mailgun_mailer,
    mandril_mailer.__class__.__name__: mandril_mailer
}

# Read JSON schemas for input
send_input_schema_dict = None
with open("./static/send_input_schema.json", "r") as schema_file:
    send_input_schema_string = schema_file.read()
    send_input_schema_dict = json.loads(send_input_schema_string)

info_input_schema_dict = None
with open("./static/info_input_schema.json", "r") as schema_file:
    info_input_schema_string = schema_file.read()