add tests for email notification

This commit is contained in:
Matthias 2022-04-06 01:22:52 +02:00
parent e1d261f989
commit b4654a7c71
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
2 changed files with 33 additions and 2 deletions

View File

@ -7,7 +7,7 @@ from allauth.account.models import EmailAddress
from plugin import IntegrationPluginBase
from plugin.mixins import BulkNotificationMethod, SettingsMixin
from common.models import InvenTreeUserSetting
from plugin.models import NotificationUserSetting
import InvenTree.tasks
@ -59,7 +59,7 @@ class CoreNotificationsPlugin(SettingsMixin, IntegrationPluginBase):
allowed_users = []
for user in self.targets:
allows_emails = InvenTreeUserSetting.get_setting('NOTIFICATION_SEND_EMAILS', user=user)
allows_emails = NotificationUserSetting.get_setting('NOTIFICATION_METHOD_MAIL', user=user, method=self.METHOD_NAME)
if allows_emails:
allowed_users.append(user)

View File

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from allauth.account.models import EmailAddress
from plugin.models import NotificationUserSetting
from part.test_part import BaseNotificationIntegrationTest
from plugin.builtin.integration.core_notifications import CoreNotificationsPlugin
from plugin import registry
class CoreNotificationTestTests(BaseNotificationIntegrationTest):
def test_email(self):
"""
Ensure that the email notifications run
"""
# enable plugin and set mail setting to true
plugin = registry.plugins.get('corenotificationsplugin')
plugin.set_setting('ENABLE_NOTIFICATION_EMAILS', True)
NotificationUserSetting.set_setting(
key='NOTIFICATION_METHOD_MAIL',
value=True,
change_user=self.user,
user=self.user,
method=CoreNotificationsPlugin.EmailNotification.METHOD_NAME
)
# run through
self._notification_run(CoreNotificationsPlugin.EmailNotification)