Exemple #1
0
    def test_notification_type_message_template(self):
        message_template = {
            'level': 'info',
            'verb': 'message template verb',
            'verbose_name': 'Message Template Type',
            'email_subject': '[{site.name}] Messsage Template Subject',
        }

        with self.subTest('Register type with non existent message template'):
            with self.assertRaises(TemplateDoesNotExist):
                message_template.update({'message_template': 'wrong/path.md'})
                register_notification_type('message_template', message_template)

        with self.subTest('Registering type with message template'):
            message_template.update(
                {'message_template': 'openwisp_notifications/default_message.md'}
            )
            register_notification_type('message_template', message_template)
            self.notification_options.update({'type': 'message_template'})
            self._create_notification()
            n = notification_queryset.first()
            self.assertEqual(n.type, 'message_template')
            self.assertEqual(n.email_subject, '[example.com] Messsage Template Subject')

        with self.subTest('Links in notification message'):
            url = _get_absolute_url(
                reverse('admin:openwisp_users_user_change', args=(self.admin.pk,))
            )
            message = (
                '<p>info : None message template verb </p>\n'
                f'<p><a href="{url}">admin</a>'
                '\nreports\n<a href="#">None</a>\nmessage template verb.</p>'
            )
            self.assertEqual(n.message, message)
 def redirect_view_url(self):
     return _get_absolute_url(
         reverse('notifications:notification_read_redirect', args=(self.pk,))
     )
 def get_target_object_url(self, obj):
     url = reverse(
         f'admin:{Notification._meta.app_label}_{Notification._meta.model_name}_change',
         args=(obj.id, ),
     )
     return _get_absolute_url(url)