Split backend tests into unit and integration suites, add isolated fixtures and coverage enforcement, and update CI and test documentation. Cover current authentication, content, notification, payment, media, and admin flows; fix behaviors revealed by the new tests. Validate both suites and the per-module gate against local PostgreSQL.
30 lines
1.5 KiB
Python
30 lines
1.5 KiB
Python
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
|