Add recipient notification detail and filtering, a queued admin composer, and contextual automatic titles. Retire email delivery, obsolete auth routes, newsletter data, and related templates and settings.
33 lines
1.5 KiB
Python
33 lines
1.5 KiB
Python
import json
|
|
from unittest import mock
|
|
|
|
from django.test import TestCase
|
|
|
|
from apps.communications.models import Announcement
|
|
from apps.users.models import User
|
|
from core.authentication import create_jwt_token
|
|
|
|
|
|
class AnnouncementDeliveryTests(TestCase):
|
|
def setUp(self):
|
|
self.staff = User.objects.create_user(
|
|
username="announcement_staff", mobile="09193000001", password="password", is_staff=True,
|
|
)
|
|
self.auth = {"HTTP_AUTHORIZATION": f"Bearer {create_jwt_token(self.staff)}"}
|
|
|
|
@mock.patch("apps.notifications.services.notify_user")
|
|
def test_publishing_announcement_does_not_send_manual_notifications(self, notify_user):
|
|
response = self.client.post("/api/communications/announcements/", json.dumps({
|
|
"title": "News", "content": "# Story", "is_published": True,
|
|
}), content_type="application/json", **self.auth)
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertTrue(Announcement.objects.filter(title="News").exists())
|
|
notify_user.assert_not_called()
|
|
|
|
def test_newsletter_category_and_routes_are_removed(self):
|
|
response = self.client.post("/api/communications/announcements/", json.dumps({
|
|
"title": "News", "content": "Story", "announcement_type": "newsletter",
|
|
}), content_type="application/json", **self.auth)
|
|
self.assertEqual(response.status_code, 422)
|
|
self.assertEqual(self.client.post("/api/communications/newsletter/subscribe/").status_code, 404)
|