diff --git a/requirements.txt b/requirements.txt index 6d5fefb..f3cc9b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ coveralls==1.3.0 +requests==2.18.4 diff --git a/tests/test_builder.py b/tests/test_builder.py index 60745ca..1e0ab8b 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -9,5 +9,6 @@ def test_build_msg(self): msg = builder.build_msg('Test ', 'Example ', None, None, 'The Subject', 'Some Text', 'Some Bold Text', attachment_list=None, inline_attachment_dict=None) self.assertIsNotNone(msg) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_sender.py b/tests/test_sender.py new file mode 100644 index 0000000..60926c8 --- /dev/null +++ b/tests/test_sender.py @@ -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', 'Some Bold Text', 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()