import pytest import json from apps.communications.models import Announcement from apps.users.models import User from core.authentication import create_jwt_token @pytest.mark.django_db @pytest.mark.integration class TestAnnouncementDeliveryTests: def setup_method(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)}'} def test_publishing_announcement_does_not_send_manual_notifications(self, mocker): notify_user = mocker.patch('apps.notifications.services.notify_user') response = self.client.post('/api/communications/announcements/', json.dumps({'title': 'News', 'content': '# Story', 'is_published': True}), content_type='application/json', **self.auth) assert response.status_code == 200 assert 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) assert response.status_code == 422 assert self.client.post('/api/communications/newsletter/subscribe/').status_code == 404 @pytest.fixture(autouse=True) def _pytest_client(self, client): self.client = client