mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
add tests for notifications
This commit is contained in:
parent
41b75e4928
commit
47f9bd911a
@ -1,8 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from common.notifications import NotificationMethod, SingleNotificationMethod, BulkNotificationMethod
|
||||
from common.notifications import NotificationMethod, SingleNotificationMethod, BulkNotificationMethod, storage
|
||||
from plugin.models import NotificationUserSetting
|
||||
from part.test_part import BaseNotificationIntegrationTest
|
||||
import plugin.templatetags.plugin_extras as plugin_tags
|
||||
|
||||
|
||||
class BaseNotificationTests(BaseNotificationIntegrationTest):
|
||||
@ -116,3 +118,47 @@ class SingleNotificationMethodTests(BaseNotificationIntegrationTest):
|
||||
self._notification_run(WrongImplementation)
|
||||
|
||||
# A integration test for notifications is provided in test_part.PartNotificationTest
|
||||
|
||||
class NotificationUserSettingTests(BaseNotificationIntegrationTest):
|
||||
""" Tests for NotificationUserSetting """
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.client.login(username=self.user.username, password='password')
|
||||
|
||||
def test_setting_attributes(self):
|
||||
"""check notification method plugin methods: usersettings and tags """
|
||||
|
||||
class SampleImplementation(BulkNotificationMethod):
|
||||
METHOD_NAME = 'test'
|
||||
GLOBAL_SETTING = 'ENABLE_NOTIFICATION_TEST'
|
||||
USER_SETTING = {
|
||||
'name': 'Enable test notifications',
|
||||
'description': 'Allow sending of test for event notifications',
|
||||
'default': True,
|
||||
'validator': bool,
|
||||
'units': 'alpha',
|
||||
}
|
||||
|
||||
def get_targets(self):
|
||||
return [1, ]
|
||||
|
||||
def send_bulk(self):
|
||||
return True
|
||||
|
||||
# run thorugh notification
|
||||
self._notification_run(SampleImplementation)
|
||||
# make sure the array fits
|
||||
array = storage.get_usersettings(self.user)
|
||||
setting = NotificationUserSetting.objects.all().first()
|
||||
|
||||
# assertions for settings
|
||||
self.assertEqual(setting.name, 'Enable test notifications')
|
||||
self.assertEqual(setting.default_value, True)
|
||||
self.assertEqual(setting.description, 'Allow sending of test for event notifications')
|
||||
self.assertEqual(setting.units, 'alpha')
|
||||
|
||||
# test tag and array
|
||||
self.assertEqual(plugin_tags.notification_settings_list({'user': self.user}), array)
|
||||
self.assertEqual(array[0]['key'], 'NOTIFICATION_METHOD_TEST')
|
||||
self.assertEqual(array[0]['method'], 'test')
|
||||
|
Loading…
Reference in New Issue
Block a user