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.
36 lines
1.8 KiB
Python
36 lines
1.8 KiB
Python
import pytest
|
|
from types import SimpleNamespace
|
|
from datetime import timedelta
|
|
from django.contrib import admin
|
|
from django.utils import timezone
|
|
from apps.events.admin import EventAdmin, RegistrationAdmin
|
|
from apps.events.models import Event, Registration
|
|
from apps.events.tasks import send_registration_cancellation_notification, send_registration_confirmation_notification
|
|
from apps.users.models import User
|
|
|
|
@pytest.mark.django_db
|
|
@pytest.mark.integration
|
|
class TestEventModelTests:
|
|
|
|
def setup_method(self):
|
|
now = timezone.now()
|
|
self.event = Event.objects.create(title='Workshop', description='**Important** details', start_time=now + timedelta(days=1), end_time=now + timedelta(days=1, hours=2), capacity=1, registration_start_date=now - timedelta(days=1), registration_end_date=now + timedelta(hours=1))
|
|
self.user = User.objects.create_user(username='attendee', mobile='09191110003', password='password')
|
|
|
|
def test_markdown_description_and_registration_window_remain_available(self):
|
|
assert '<strong>Important</strong>' in self.event.description_html
|
|
assert self.event.is_registration_open
|
|
self.event.registration_end_date = timezone.now() - timedelta(minutes=1)
|
|
assert not self.event.is_registration_open
|
|
|
|
def test_capacity_counts_confirmed_registration(self, mocker):
|
|
delay = mocker.patch('apps.events.tasks.send_registration_confirmation_notification.delay')
|
|
Registration.objects.create(event=self.event, user=self.user, status=Registration.StatusChoices.CONFIRMED)
|
|
assert self.event.current_attendees_count == 1
|
|
assert not self.event.has_available_slots
|
|
delay.assert_called_once()
|
|
|
|
def test_unlimited_capacity_allows_registration(self):
|
|
self.event.capacity = None
|
|
assert self.event.has_available_slots
|