mirror of
https://github.com/sartography/uva-covid19-testing-communicator.git
synced 2025-02-23 12:28:26 +00:00
fixing a few bugs and missing libraries.
This commit is contained in:
parent
bdee709324
commit
ab07ea783d
1
Pipfile
1
Pipfile
@ -34,6 +34,7 @@ psycopg2-binary = "*"
|
||||
google-cloud-firestore = "*"
|
||||
globus-sdk = "*"
|
||||
gunicorn = "*"
|
||||
twilio = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.8"
|
||||
|
39
Pipfile.lock
generated
39
Pipfile.lock
generated
@ -1,7 +1,7 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "cab43a07d915cc528153009278d8402c8350e6d2df0e1f629dc514d402c639d6"
|
||||
"sha256": "ab12e64675592a61635bac5221044eb2d23bc232b4db303cae88e5cb8f4f2251"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
@ -429,14 +429,6 @@
|
||||
],
|
||||
"version": "==2.10"
|
||||
},
|
||||
"importlib-metadata": {
|
||||
"hashes": [
|
||||
"sha256:90bb658cdbbf6d1735b6341ce708fc7024a3e14e99ffdc5783edea9f9b077f83",
|
||||
"sha256:dc15b2969b4ce36305c51eebe62d418ac7791e9a157911d58bfb1f9ccd8e2070"
|
||||
],
|
||||
"markers": "python_version < '3.8'",
|
||||
"version": "==1.7.0"
|
||||
},
|
||||
"inflection": {
|
||||
"hashes": [
|
||||
"sha256:1a29730d366e996aaacffb2f1f1cb9593dc38e2ddd30c91250c6dde09ea9b417",
|
||||
@ -813,6 +805,13 @@
|
||||
"index": "pypi",
|
||||
"version": "==0.0.8"
|
||||
},
|
||||
"twilio": {
|
||||
"hashes": [
|
||||
"sha256:df1cf8f7e62fbe4d412e66204ee7f948cd31ff18173ff4690475834174eedaf0"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==6.45.3"
|
||||
},
|
||||
"urllib3": {
|
||||
"hashes": [
|
||||
"sha256:91056c15fa70756691db97756772bb1eb9678fa585d9184f24534b100dc60f4a",
|
||||
@ -855,13 +854,6 @@
|
||||
"sha256:81195de0ac94fbc8368abbaf9197b88c4f3ffd6c2719b5bf5fc9da744f3d829c"
|
||||
],
|
||||
"version": "==2.3.3"
|
||||
},
|
||||
"zipp": {
|
||||
"hashes": [
|
||||
"sha256:43f4fa8d8bb313e65d8323a3952ef8756bf40f9a5c3ea7334be23ee4ec8278b6",
|
||||
"sha256:b52f22895f4cfce194bc8172f3819ee8de7540aa6d873535a8668b730b8b411f"
|
||||
],
|
||||
"version": "==3.2.0"
|
||||
}
|
||||
},
|
||||
"develop": {
|
||||
@ -912,14 +904,6 @@
|
||||
"index": "pypi",
|
||||
"version": "==5.3"
|
||||
},
|
||||
"importlib-metadata": {
|
||||
"hashes": [
|
||||
"sha256:90bb658cdbbf6d1735b6341ce708fc7024a3e14e99ffdc5783edea9f9b077f83",
|
||||
"sha256:dc15b2969b4ce36305c51eebe62d418ac7791e9a157911d58bfb1f9ccd8e2070"
|
||||
],
|
||||
"markers": "python_version < '3.8'",
|
||||
"version": "==1.7.0"
|
||||
},
|
||||
"iniconfig": {
|
||||
"hashes": [
|
||||
"sha256:80cf40c597eb564e86346103f609d74efce0f6b4d4f30ec8ce9e2c26411ba437",
|
||||
@ -991,13 +975,6 @@
|
||||
"sha256:bda89d5935c2eac546d648028b9901107a595863cb36bae0c73ac804a9b4ce88"
|
||||
],
|
||||
"version": "==0.10.1"
|
||||
},
|
||||
"zipp": {
|
||||
"hashes": [
|
||||
"sha256:43f4fa8d8bb313e65d8323a3952ef8756bf40f9a5c3ea7334be23ee4ec8278b6",
|
||||
"sha256:b52f22895f4cfce194bc8172f3819ee8de7540aa6d873535a8668b730b8b411f"
|
||||
],
|
||||
"version": "==3.2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,11 +29,15 @@ class NotificationService(object):
|
||||
self.sender = app.config['MAIL_SENDER']
|
||||
|
||||
def __enter__(self):
|
||||
if 'TESTING' in self.app.config and self.app.config['TESTING']:
|
||||
return self
|
||||
self.email_server = self._get_email_server()
|
||||
self.twilio_client = self._get_twilio_client()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
if 'TESTING' in self.app.config and self.app.config['TESTING']:
|
||||
return
|
||||
self.email_server.close()
|
||||
# No way to close the twilio client that I can see.
|
||||
|
||||
@ -68,26 +72,25 @@ class NotificationService(object):
|
||||
|
||||
def send_invitations(self, date, location, email_string):
|
||||
emails = email_string.splitlines()
|
||||
for email in emails:
|
||||
subject = "UVA: BE SAFE - Appointment"
|
||||
tracking_code = self._tracking_code()
|
||||
text_body = render_template("invitation_email.txt",
|
||||
date=date,
|
||||
location=location,
|
||||
tracking_code=tracking_code)
|
||||
subject = "UVA: BE SAFE - Appointment"
|
||||
tracking_code = self._tracking_code()
|
||||
text_body = render_template("invitation_email.txt",
|
||||
date=date,
|
||||
location=location,
|
||||
tracking_code=tracking_code)
|
||||
|
||||
html_body = render_template("invitation_email.html",
|
||||
date=date,
|
||||
location=location,
|
||||
tracking_code=tracking_code)
|
||||
html_body = render_template("invitation_email.html",
|
||||
date=date,
|
||||
location=location,
|
||||
tracking_code=tracking_code)
|
||||
|
||||
self._send_email(subject, recipients=[email], text_body=text_body, html_body=html_body)
|
||||
self._send_email(subject, recipients=[self.sender], bcc=emails, text_body=text_body, html_body=html_body)
|
||||
|
||||
def _tracking_code(self):
|
||||
return str(uuid.uuid4())[:16]
|
||||
|
||||
def _get_email_server(self):
|
||||
print("Server:" + self.app.config['MAIL_SERVER'])
|
||||
|
||||
server = smtplib.SMTP(host=self.app.config['MAIL_SERVER'],
|
||||
port=self.app.config['MAIL_PORT'],
|
||||
timeout=self.app.config['MAIL_TIMEOUT'])
|
||||
@ -103,7 +106,7 @@ class NotificationService(object):
|
||||
return Client(self.app.config['TWILIO_SID'],
|
||||
self.app.config['TWILIO_TOKEN'])
|
||||
|
||||
def _send_email(self, subject, recipients, text_body, html_body, sender=None, ical=None):
|
||||
def _send_email(self, subject, recipients, text_body, html_body, bcc=[], sender=None, ical=None):
|
||||
msgRoot = MIMEMultipart('related')
|
||||
msgRoot.set_charset('utf8')
|
||||
|
||||
@ -136,8 +139,10 @@ class NotificationService(object):
|
||||
TEST_MESSAGES.append(msgRoot)
|
||||
return
|
||||
|
||||
all_recipients = recipients + bcc
|
||||
|
||||
try:
|
||||
self.email_server.sendmail(sender, recipients, msgRoot.as_bytes())
|
||||
self.email_server.sendmail(sender, all_recipients, msgRoot.as_bytes())
|
||||
except Exception as e:
|
||||
app.logger.error('An exception happened in EmailService', exc_info=True)
|
||||
app.logger.error(str(e))
|
||||
|
@ -47,6 +47,7 @@ MAIL_USE_TLS = environ.get('MAIL_USE_TLS', default=False)
|
||||
MAIL_USERNAME = environ.get('MAIL_USERNAME', default='xxx')
|
||||
MAIL_PASSWORD = environ.get('MAIL_PASSWORD', default='yyy')
|
||||
MAIL_SENDER = 'askresearch@virginia.edu'
|
||||
MAIL_TIMEOUT = 10
|
||||
|
||||
# Ivy Directory
|
||||
IVY_IMPORT_DIR = os.path.join(basedir, '..', 'example_ivy_data')
|
||||
|
@ -10,8 +10,9 @@ class TestNotificationService(BaseTest):
|
||||
|
||||
def test_send_notification(self):
|
||||
message_count = len(TEST_MESSAGES)
|
||||
notifier = NotificationService(app)
|
||||
sample = Sample(email="dan@stauntonmakerspace.com", result_code="1234")
|
||||
notifier.send_result_email(sample)
|
||||
with NotificationService(app) as notifier:
|
||||
notifier.send_result_email(sample)
|
||||
self.assertEqual(len(TEST_MESSAGES), message_count + 1)
|
||||
self.assertEqual("UVA: BE SAFE Notification", self.decode(TEST_MESSAGES[-1]['subject']))
|
||||
self.assertEqual("UVA: BE SAFE Notification", self.decode(TEST_MESSAGES[-1]['subject']))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user