Verified Commit 09fe17a0 authored by Huste, Tobias (FWCC) - 111645's avatar Huste, Tobias (FWCC) - 111645
Browse files

allow excluding users from getting status mails

parent a9f5b1e5
......@@ -94,3 +94,6 @@ UPLOADBYURL_REDIS_KEY_TTL = 7 * 24 * 3600
UPLOADBYURL_CACHE_DURATION = 7
"""Number of days after which cache entries shall be removed."""
UPLOADBYURL_USER_NOTIFICATIONS_OFF = []
"""List of user ids not being notified via E-Mail about the job status."""
......@@ -258,6 +258,9 @@ def connect_user_and_server(remote, username, password):
def notification_mail(user_id, failed=False, filepath=None, url=None):
"""Send notification mail after finished upload."""
if user_id in current_app.config['UPLOADBYURL_USER_NOTIFICATIONS_OFF']:
return None
from flask_mail import Message
from invenio_mail.tasks import send_email
......
......@@ -42,7 +42,7 @@ tests_require = [
'pytest-cache>=1.0',
'pytest-cov>=1.8.0',
'pytest-pep8>=1.0.6',
'pytest>=2.8.0',
'pytest>=3.1.0',
]
extras_require = {
......
......@@ -99,22 +99,31 @@ def test_sftp(client, db, user, user2, remote, bucket):
download_via_sftp.delay(bucket.id, remote.id, user.id, path)
def test_sftp_with_mail(app, client, db, user, user2, remote, bucket):
@pytest.mark.parametrize("user_list,mail_sent", [
([], True),
([1], False),
])
def test_sftp_with_mail(user_list, mail_sent, app, client, db,
user, remote, bucket):
"""Test sftp with activated notification."""
app.config['UPLOADBYURL_NOTIFICATION_ENABLED'] = True
app.config['UPLOADBYURL_USER_NOTIFICATIONS_OFF'] = user_list
path = 'upload/README.rst'
with app.extensions['mail'].record_messages() as outbox:
download_via_sftp.delay(bucket.id, remote.id, user.id, path)
# test if mail was sent
assert len(outbox) == 1
assert outbox[0].recipients == ['bucket@hzdr.de']
assert outbox[0].subject == app.config['UPLOADBYURL_EMAIL_TITLE']
assert outbox[0].body == app.config['UPLOADBYURL_EMAIL_BODY']
if mail_sent:
assert len(outbox) == 1
assert outbox[0].recipients == ['bucket@hzdr.de']
assert outbox[0].subject == app.config['UPLOADBYURL_EMAIL_TITLE']
assert outbox[0].body == app.config['UPLOADBYURL_EMAIL_BODY']
else:
assert len(outbox) == 0
@mock.patch('invenio_uploadbyurl.tasks.pexpect.spawn')
def test_sftp_failure_with_mail(mock_expect, app, client, db, user,
remote, bucket):
def test_sftp_failure_with_mail(mock_expect, app, client,
db, user, remote, bucket):
"""Test failing upload with notifications enabled."""
app.config['UPLOADBYURL_NOTIFICATION_ENABLED'] = True
path = 'upload/README.rst'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment