-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDAN-710 Send monitoring alerts with articles in body (#1153)
- Loading branch information
1 parent
3e2463c
commit 5d01305
Showing
6 changed files
with
116 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{ monitoring_report_name }} Monitoring: {{ monitoring_profile.name }} {% if current_date %}({{ current_date }}){% endif %} | ||
{% for d in date_items_dict.keys() %} | ||
{{ d.strftime('%d/%m/%Y') }} | ||
{% for item in date_items_dict[d] %} | ||
Headline: {{ item.get('headline', '') }} | ||
Source: {{ item.get('source', '') }} | ||
Keywords: {{ get_keywords_in_text(item.get('body_str', ''), monitoring_profile.keywords)|join(',') }} | ||
{% if item.byline %} | ||
By {{ item.get('byline', '') }} | ||
{% endif %} | ||
{{ item.get('body_str', '') | safe }} | ||
{% if monitoring_profile.alert_type == 'linked_text' and not print%} | ||
{{ url_for('monitoring.index', item=item._id, _external=True) }} | ||
{% endif %} | ||
|
||
{% endfor %} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -820,3 +820,32 @@ def test_send_immediate_headline_subject_alerts(client, app): | |
assert outbox[0].sender == 'newsroom@localhost' | ||
assert outbox[0].subject == 'Article headline about product' | ||
assert 'Newsroom Monitoring: W1' in outbox[0].body | ||
|
||
|
||
@mock.patch('newsroom.monitoring.email_alerts.utcnow', mock_utcnow) | ||
@mock.patch('newsroom.email.send_email', mock_send_email) | ||
def test_send_immediate_email_alerts(client, app): | ||
test_login_succeeds_for_admin(client) | ||
post_json(client, '/settings/general_settings', | ||
{"monitoring_report_logo_path": get_fixture_path('thumbnail.jpg')}) | ||
app.data.insert('items', [{ | ||
'_id': 'foo', | ||
'headline': 'product immediate', | ||
'products': [{'code': '12345'}], | ||
"versioncreated": utcnow(), | ||
'byline': 'Testy McTestface', | ||
'body_html': '<p>line 1 of the article text\nline 2 of the story\nand a bit more.</p>', | ||
'source': 'AAAA' | ||
}]) | ||
w = app.data.find_one('monitoring', None, _id='5db11ec55f627d8aa0b545fb') | ||
assert w is not None | ||
app.data.update('monitoring', ObjectId('5db11ec55f627d8aa0b545fb'), | ||
{"format_type": "monitoring_email", "alert_type": "linked_text", | ||
'keywords': ['text']}, w) | ||
with app.mail.record_messages() as outbox: | ||
MonitoringEmailAlerts().run(immediate=True) | ||
assert len(outbox) == 1 | ||
assert outbox[0].recipients == ['[email protected]', '[email protected]'] | ||
assert outbox[0].sender == 'newsroom@localhost' | ||
assert outbox[0].subject == 'Monitoring Subject' | ||
assert 'Newsroom Monitoring: W1' in outbox[0].body |