Exemple #1
0
 def test_mailgun_get_status_failure(self, get):
     
     data = {
      "id" : "45ccde84-78b2-4e91-b460-609d0c678ad5",
      "email" : "*****@*****.**"
     }
     
     get.side_effect = ConnectTimeout
     
     mailgun_mailer = MailGunMailer()
     status_info = mailgun_mailer.get_message_status(data)
     
     assert status_info == None
Exemple #2
0
 def test_mailgun_get_status_successful(self, get):
     
     data = {
      "id" : "45ccde84-78b2-4e91-b460-609d0c678ad5",
      "email" : "*****@*****.**"
     }
     
     get.return_value.status_code = 200
     get.return_value.content = '{ "event" : "delivered" }'
     
     mailgun_mailer = MailGunMailer()
     status_info = mailgun_mailer.get_message_status(data)
     
     assert status_info['status'] == 'sent'
Exemple #3
0
 def test_mailgun_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 = '{ "id" : "<someid>" }'
     
     mailgun_mailer = MailGunMailer()
     messages_info = mailgun_mailer.send_message(**data)
     
     assert len(messages_info) == 1
     assert messages_info[0]['email_address'] == '*****@*****.**'
     assert messages_info[0]['id'] == 'someid'
Exemple #4
0
 def test_mailgun_send_message_failure(self, post):
     
     data = {
          "from_email" : "Testing API <*****@*****.**>",
          "to" : ["*****@*****.**"],
          "subject" : "Testing API",
          "text" : "test"
     }
     
     post.return_value.status_code = 400
     
     mailgun_mailer = MailGunMailer()
     self.assertRaises(MailNotSentException,mailgun_mailer.send_message, **data)
Exemple #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: