Skip to content

Commit

Permalink
notifications: exclude some users from long-running tasks email
Browse files Browse the repository at this point in the history
Bugzilla: https://bugzilla.redhat.com/2245056

Verify that users with disabled account or disabled email don't receive
email notifications about long-running tasks.
  • Loading branch information
pnovotny committed Apr 8, 2024
1 parent f1799c9 commit 5a94b8b
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions tests/foreman/api/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ def admin_user_with_localhost_email(target_sat):
user.delete()


@pytest.fixture
def admin_user_with_custom_settings(request, admin_user_with_localhost_email):
"""Admin user with custom properties set via parametrization.
`request.param` should be a dict-like value.
"""
for key, value in request.param.items():
setattr(admin_user_with_localhost_email, key, value)
admin_user_with_localhost_email.update(list(request.param.keys()))
return admin_user_with_localhost_email


@pytest.fixture
def sysadmin_user_with_subscription_reposync_fail(target_sat):
"""System admin user with `root@localhost` e-mail
Expand Down Expand Up @@ -162,6 +173,25 @@ def wait_for_failed_repo_sync_mail(
)


@pytest.fixture
def wait_for_no_long_running_task_mail(target_sat, clean_root_mailbox, long_running_task):
"""Wait and check that no long-running task ID is found in the Satellite's mbox file."""
timeout = 120
try:
wait_for_mail(
sat_obj=target_sat,
mailbox_file=clean_root_mailbox,
contains_string=long_running_task["task"]["id"],
timeout=timeout,
)
except AssertionError:
return True
raise AssertionError(
f'E-mail with long running task ID "{long_running_task["task"]["id"]}" '
f'should not have arrived to mailbox {clean_root_mailbox}!'
)


@pytest.fixture
def root_mailbox_copy(target_sat, clean_root_mailbox):
"""Parsed local system copy of the Satellite's root user mailbox.
Expand Down Expand Up @@ -362,3 +392,48 @@ def test_positive_notification_recipients(target_sat):
recipients = target_sat.api.NotificationRecipients().read()
for notification in recipients.notifications:
assert set(notification_keys) == set(notification.keys())


@pytest.mark.tier3
@pytest.mark.parametrize(
'admin_user_with_custom_settings',
[
pytest.param({'disabled': True, 'mail_enabled': True}, id='account_disabled'),
pytest.param({'disabled': False, 'mail_enabled': False}, id='mail_disabled'),
],
indirect=True,
)
@pytest.mark.usefixtures(
'reschedule_long_running_tasks_notification',
'wait_for_no_long_running_task_mail',
)
def test_negative_no_notification_for_long_running_tasks(
admin_user_with_custom_settings, long_running_task, root_mailbox_copy
):
"""Check that an e-mail notification for a long-running task
(i.e., running or paused for more than two days)
is NOT sent to users with disabled account or disabled e-mail.
:id: 03b41216-f39b-11ee-b9ea-000c2989e153
:setup:
1. Create an admin user with e-mail address set and:
a. account disabled & mail enabled
b. account enabled & mail disabled
:steps:
1. Create a long-running task.
3. For each user, wait and check that the notification e-mail has NOT been sent.
:BZ: 2245056
:customerscenario: true
"""
assert admin_user_with_custom_settings
task_id = long_running_task['task']['id']
assert task_id

for email in root_mailbox_copy:
assert (
task_id not in email.as_string()
), f'Unexpected notification e-mail with long-running task ID {task_id} found in user mailbox!'

0 comments on commit 5a94b8b

Please sign in to comment.