Skip to content

Commit

Permalink
make email notifications automatic
Browse files Browse the repository at this point in the history
  • Loading branch information
bengolder committed May 12, 2016
1 parent 76a20e4 commit ab9f5a4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
13 changes: 0 additions & 13 deletions tests/integration/test_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,3 @@ def test_save_submission(self):
self.assertTrue(getattr(s, 'id'))
self.assertTrue(getattr(s, 'date_received'))
self.assertTrue(getattr(s, 'answers'))

@attr(speed="slow")
def test_save_everything(self):
data = generate_fake_data(num_users=10)
user_report, user_data, users, form_sets, doc_sets, response_sets = data
users = User.query.all()
forms = Typeform.query.all()
docs = SeamlessDoc.query.all()
responses = TypeformResponse.query.all()
self.assertTrue(len(users) == 10)
self.assertTrue(len(forms) > 0)
self.assertTrue(len(docs) > 0)
self.assertTrue(len(responses) > 0)
12 changes: 9 additions & 3 deletions tests/unit/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class TestTasks(TestCase):
@patch('typeseam.form_filler.tasks.app')
def test_send_submission_notification(self, app, sg, sendgrid, request, render_template):
app.config = {
'DEFAULT_NOTIFICATION_EMAIL': 'me'
'DEFAULT_NOTIFICATION_EMAIL': 'me',
'MAIN_INTAKE_EMAIL': 'louise'
}
fake_rendered_template = Mock()
render_template.return_value = fake_rendered_template
Expand All @@ -29,12 +30,17 @@ def test_send_submission_notification(self, app, sg, sendgrid, request, render_t
fake_Mail.return_value = message
sendgrid.Mail = fake_Mail
tasks.send_submission_notification(submission)
fake_Mail.assert_called_once_with(
fake_Mail.assert_any_call(
subject="New application to https://localtesting:80/yolo received <nice time format>",
to='me',
text=fake_rendered_template
)
sg.send.assert_called_once_with(message)
fake_Mail.assert_any_call(
subject="You’ve received a new online application to Clean Slate from Code for America",
to='louise',
text=fake_rendered_template
)
sg.send.assert_any_call(message)


@patch('typeseam.form_filler.tasks.render_template')
Expand Down
6 changes: 5 additions & 1 deletion typeseam/form_filler/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ def send_submission_notification(submission):
to=app.config['DEFAULT_NOTIFICATION_EMAIL'],
text=text)
sg.send(message)

message = sendgrid.Mail(
subject="You’ve received a new online application to Clean Slate from Code for America",
to=app.config['MAIN_INTAKE_EMAIL'],
text=text)
sg.send(message)

def send_submission_viewed_notification(submission):
text = render_template('submission_viewed_email.txt',
Expand Down
1 change: 1 addition & 0 deletions typeseam/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Config(AuthConfig):
SEAMLESS_DOCS_API_SECRET = os.environ.get('SEAMLESS_DOCS_API_SECRET')
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')
SENDGRID_API_KEY = os.environ.get('SENDGRID_API_KEY')
MAIN_INTAKE_EMAIL = os.environ.get('MAIN_INTAKE_EMAIL')
DEFAULT_ADMIN_EMAIL = os.environ.get('DEFAULT_ADMIN_EMAIL')
DEFAULT_NOTIFICATION_EMAIL = os.environ.get('DEFAULT_NOTIFICATION_EMAIL')
if server_name:
Expand Down
2 changes: 1 addition & 1 deletion typeseam/templates/app_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block body %}
<div class="container">
<div class="row">
<h1>Applications</h1>
<h1>Clean Slate Applications</h1>
</div>
<div class="row">
<table class="table applications_list">
Expand Down
4 changes: 4 additions & 0 deletions typeseam/templates/notification_email.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ You can review this and all previous applications here:
'form_filler.applications_index', _external=True
)}}

{% if submission.get_contact_preferences() %}
This client prefers to be contacted through:
{%- for medium in submission.get_contact_preferences() %}
- {{ medium }}
{%- endfor %}
{%- else %}
This client did not give a preferred method of contact
{% endif %}

To protect client privacy, you must login to view the application. You should have already received an invitation to create a login, but if you do not yet have a login or have any trouble, please let us know and we will create one right away. You can reset your password at any time.

Expand Down

0 comments on commit ab9f5a4

Please sign in to comment.