Skip to content

Commit

Permalink
First pass at e2e testing of the sender (using Post-Shift API)
Browse files Browse the repository at this point in the history
  • Loading branch information
Murray Christopherson committed Apr 10, 2018
1 parent 5c9d8ea commit 2b46362
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
coveralls==1.3.0
requests==2.18.4
1 change: 1 addition & 0 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ def test_build_msg(self):
msg = builder.build_msg('Test <test@test.com>', 'Example <example@example.com>', None, None, 'The Subject', 'Some Text', '<b>Some Bold Text</b>', attachment_list=None, inline_attachment_dict=None)
self.assertIsNotNone(msg)


if __name__ == '__main__':
unittest.main()
81 changes: 81 additions & 0 deletions tests/test_sender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import unittest
import os

import requests

from quick_email import builder, sender

SMTP_HOST = os.environ['SMTP_HOST']
SMTP_PORT = int(os.environ['SMTP_PORT'])
SMTP_USER = os.environ['SMTP_USER']
SMTP_PASSWORD = os.environ['SMTP_PASSWORD']
SMTP_IS_TLS = os.environ.get('SMTP_IS_TLS') == 'true'
SMTP_SENDER = os.environ['SMTP_SENDER']

MASHAPE_KEY = os.environ['MASHAPE_KEY']

class PostShift:
ENDPOINT_URL = 'https://reuleaux-post-shift-v1.p.mashape.com/api.php'
@staticmethod
def create():
r = requests.get(PostShift.ENDPOINT_URL, params={
'action': 'new',
'type': 'json',
}, headers={
'X=Mashape-Key': MASHAPE_KEY,
'Accept': 'application/json',
})

_json = r.json()

return _json

@staticmethod
def get_list(email_key):
r = requests.get(PostShift.ENDPOINT_URL, params={
'action': 'getlist',
'key': email_key,
'type': 'json',
}, headers={
'X=Mashape-Key': MASHAPE_KEY,
'Accept': 'application/json',
})

_json = r.json()

return _json

@staticmethod
def clear(email_key):
requests.get(PostShift.ENDPOINT_URL, params={
'action': 'clear',
'key': email_key,
'type': 'json',
}, headers={
'X=Mashape-Key': MASHAPE_KEY,
'Accept': 'application/json',
})

class TestSender(unittest.TestCase):
@classmethod
def setUpClass(cls):
_json = PostShift.create()

cls.test_email = _json['email']
cls.postshift_key = _json['key']

def tearDown(self):
PostShift.clear(TestSender.postshift_key)

# TODO write test suite
def test_send_msg(self):
msg = builder.build_msg(SMTP_SENDER, TestSender.test_email, None, None, 'The Subject', 'Some Text', '<b>Some Bold Text</b>', attachment_list=None, inline_attachment_dict=None)
sender.send_msg(SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, SMTP_IS_TLS, SMTP_SENDER, msg)

_json = PostShift.get_list(TestSender.postshift_key)

self.assertEquals(len(_json), 1)


if __name__ == '__main__':
unittest.main()

0 comments on commit 2b46362

Please sign in to comment.