diff --git a/openwisp_notifications/templates/admin/base_site.html b/openwisp_notifications/templates/admin/base_site.html
index e4205407..9ce09069 100644
--- a/openwisp_notifications/templates/admin/base_site.html
+++ b/openwisp_notifications/templates/admin/base_site.html
@@ -1,90 +1 @@
-{% extends "admin/base_site.html" %}
-{% load i18n static notification_tags %}
-
-{% block extrastyle %}
- {{ block.super }}
- {% if request|should_load_notifications_widget %}
-
-
- {% endif %}
-{% endblock extrastyle %}
-
-{% block extrahead %}
- {{ block.super }}
- {% if request|should_load_notifications_widget and not media.js and 'jquery' not in block.super %}
-
-
- {% endif %}
-{% endblock %}
-
-{% block user-tools %}
- {{ block.super }}
- {% if request|should_load_notifications_widget %}
-
- {% csrf_token %}
-
-
-
-
-
-
{% trans 'No new notification.' %}
-
-
- {% endif %}
-{% endblock %}
-
-{% block footer %}
- {{ block.super }}
- {% if request|should_load_notifications_widget %}
-
-
-
×
-
-
-
-
-
-
-
-
-
-
-
-
- {% endif %}
-{% endblock footer %}
+{% extends 'admin/openwisp_notifications/base_site.html' %}
diff --git a/openwisp_notifications/templates/admin/change_form.html b/openwisp_notifications/templates/admin/change_form.html
index e76434d4..388a3c33 100644
--- a/openwisp_notifications/templates/admin/change_form.html
+++ b/openwisp_notifications/templates/admin/change_form.html
@@ -1,35 +1 @@
-{% extends 'admin/change_form.html' %}
-
-{% comment %}
- This template is required to supply information regarding the displayed object
- from Django's template context to JavaScript for proper functioning of object notification
- widget. Following data is supplied:
- 1. object's app_label
- 2. object's model_name
- 3. object's primary key
-{% endcomment %}
-
-{% block admin_change_form_document_ready %}
- {{ block.super }}
- {% if change %}
-
- {% endif %}
-{% endblock %}
+{% extends 'admin/openwisp_notifications/change_form.html' %}
diff --git a/openwisp_notifications/templates/admin/openwisp_notifications/base_site.html b/openwisp_notifications/templates/admin/openwisp_notifications/base_site.html
new file mode 100644
index 00000000..e4205407
--- /dev/null
+++ b/openwisp_notifications/templates/admin/openwisp_notifications/base_site.html
@@ -0,0 +1,90 @@
+{% extends "admin/base_site.html" %}
+{% load i18n static notification_tags %}
+
+{% block extrastyle %}
+ {{ block.super }}
+ {% if request|should_load_notifications_widget %}
+
+
+ {% endif %}
+{% endblock extrastyle %}
+
+{% block extrahead %}
+ {{ block.super }}
+ {% if request|should_load_notifications_widget and not media.js and 'jquery' not in block.super %}
+
+
+ {% endif %}
+{% endblock %}
+
+{% block user-tools %}
+ {{ block.super }}
+ {% if request|should_load_notifications_widget %}
+
+ {% csrf_token %}
+
+
+
+
+
+
{% trans 'No new notification.' %}
+
+
+ {% endif %}
+{% endblock %}
+
+{% block footer %}
+ {{ block.super }}
+ {% if request|should_load_notifications_widget %}
+
+
+
×
+
+
+
+
+
+
+
+
+
+
+
+
+ {% endif %}
+{% endblock footer %}
diff --git a/openwisp_notifications/templates/admin/openwisp_notifications/change_form.html b/openwisp_notifications/templates/admin/openwisp_notifications/change_form.html
new file mode 100644
index 00000000..e76434d4
--- /dev/null
+++ b/openwisp_notifications/templates/admin/openwisp_notifications/change_form.html
@@ -0,0 +1,35 @@
+{% extends 'admin/change_form.html' %}
+
+{% comment %}
+ This template is required to supply information regarding the displayed object
+ from Django's template context to JavaScript for proper functioning of object notification
+ widget. Following data is supplied:
+ 1. object's app_label
+ 2. object's model_name
+ 3. object's primary key
+{% endcomment %}
+
+{% block admin_change_form_document_ready %}
+ {{ block.super }}
+ {% if change %}
+
+ {% endif %}
+{% endblock %}
diff --git a/openwisp_notifications/tests/test_admin.py b/openwisp_notifications/tests/test_admin.py
index 69b7568a..377515cc 100644
--- a/openwisp_notifications/tests/test_admin.py
+++ b/openwisp_notifications/tests/test_admin.py
@@ -6,6 +6,7 @@
from django.contrib.auth import get_user_model
from django.core.cache import cache
from django.forms.widgets import MediaOrderConflictWarning
+from django.templatetags.static import static
from django.test import TestCase, override_settings, tag
from django.urls import reverse
@@ -193,6 +194,33 @@ def test_notification_preferences_button_staff_user(self):
response = self.client.get(user_admin_page)
self.assertNotContains(response, expected_html, html=True)
+ def test_base_site_template(self):
+ response = self.client.get(self._url)
+ self.assertContains(response, static("openwisp-notifications/css/loader.css"))
+ self.assertContains(
+ response, static("openwisp-notifications/css/notifications.css")
+ )
+ self.assertContains(
+ response, static("openwisp-notifications/js/notifications.js")
+ )
+ self.assertContains(
+ response,
+ static("openwisp-notifications/js/vendor/reconnecting-websocket.min.js"),
+ )
+ self.assertContains(response, 'id="openwisp_notifications"')
+
+ def test_change_form_template(self):
+ org = self._get_org()
+ url = reverse(
+ f"admin:{self.users_app_label}_organization_change", args=(org.pk,)
+ )
+ response = self.client.get(url)
+ self.assertContains(response, "owIsChangeForm = true")
+ self.assertContains(
+ response, f"const owNotifyAppLabel = '{self.users_app_label}'"
+ )
+ self.assertContains(response, "owNotifyModelName = 'organization'")
+
def test_notification_preferences_button_with_permission(self):
perm = get_notification_setting_permission("change")
org = self._get_org()
diff --git a/tests/openwisp2/sample_notifications/templates/admin/base_site.html b/tests/openwisp2/sample_notifications/templates/admin/base_site.html
new file mode 100644
index 00000000..d3042c76
--- /dev/null
+++ b/tests/openwisp2/sample_notifications/templates/admin/base_site.html
@@ -0,0 +1,5 @@
+{% extends 'admin/openwisp_notifications/base_site.html' %}
+{% block user-tools %}
+ {{ block.super }}
+
+{% endblock %}
diff --git a/tests/openwisp2/sample_notifications/templates/admin/change_form.html b/tests/openwisp2/sample_notifications/templates/admin/change_form.html
new file mode 100644
index 00000000..85717625
--- /dev/null
+++ b/tests/openwisp2/sample_notifications/templates/admin/change_form.html
@@ -0,0 +1,5 @@
+{% extends 'admin/openwisp_notifications/change_form.html' %}
+{% block admin_change_form_document_ready %}
+ {{ block.super }}
+
+{% endblock %}
diff --git a/tests/openwisp2/sample_notifications/tests/test_django.py b/tests/openwisp2/sample_notifications/tests/test_django.py
index 8ebdca95..0eceab8b 100644
--- a/tests/openwisp2/sample_notifications/tests/test_django.py
+++ b/tests/openwisp2/sample_notifications/tests/test_django.py
@@ -3,6 +3,7 @@
from django.apps.registry import apps
from django.contrib.contenttypes.models import ContentType
from django.core.cache import cache
+from django.urls import reverse
from openwisp_notifications.swapper import load_model, swapper_load_model
from openwisp_notifications.tests.test_admin import TestAdmin as BaseTestAdmin
@@ -45,6 +46,18 @@
class TestAdmin(BaseTestAdmin):
app_label = "sample_notifications"
+ def test_base_site_template(self):
+ response = self.client.get(self._url)
+ self.assertContains(response, 'id="sample-notifications-base-site"')
+
+ def test_change_form_template(self):
+ org = self._get_org()
+ url = reverse(
+ f"admin:{self.users_app_label}_organization_change", args=(org.pk,)
+ )
+ response = self.client.get(url)
+ self.assertContains(response, 'id="sample-notifications-change-form"')
+
class TestAdminMedia(BaseTestAdminMedia):
pass
diff --git a/tests/openwisp2/settings.py b/tests/openwisp2/settings.py
index f5a381d9..f992d33f 100644
--- a/tests/openwisp2/settings.py
+++ b/tests/openwisp2/settings.py
@@ -94,8 +94,8 @@
"OPTIONS": {
"loaders": [
"django.template.loaders.filesystem.Loader",
- "openwisp_utils.loaders.DependencyLoader",
"django.template.loaders.app_directories.Loader",
+ "openwisp_utils.loaders.DependencyLoader",
],
"context_processors": [
"django.template.context_processors.debug",
@@ -203,9 +203,10 @@
pass
if os.environ.get("SAMPLE_APP", False):
+ notifications_index = INSTALLED_APPS.index("openwisp_notifications")
+ INSTALLED_APPS.insert(notifications_index, "openwisp2.sample_notifications")
INSTALLED_APPS.remove("openwisp_notifications")
EXTENDED_APPS = ["openwisp_notifications"]
- INSTALLED_APPS.append("openwisp2.sample_notifications")
OPENWISP_NOTIFICATIONS_NOTIFICATION_MODEL = "sample_notifications.Notification"
OPENWISP_NOTIFICATIONS_NOTIFICATIONSETTING_MODEL = (
"sample_notifications.NotificationSetting"