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.
91 lines
2.2 KiB
Python
91 lines
2.2 KiB
Python
"""Schemas for communications-related endpoints."""
|
|
|
|
from datetime import datetime
|
|
from typing import Literal, Optional
|
|
|
|
from ninja import ModelSchema, Schema
|
|
|
|
from apps.blog.api.schemas import AuthorSchema
|
|
from apps.communications.models import Announcement, PushNotificationDevice
|
|
|
|
|
|
class AnnouncementSchema(ModelSchema):
|
|
author: AuthorSchema
|
|
content_html: str
|
|
|
|
class Meta:
|
|
model = Announcement
|
|
fields = [
|
|
"id",
|
|
"title",
|
|
"content",
|
|
"announcement_type",
|
|
"priority",
|
|
"is_published",
|
|
"publish_date",
|
|
"created_at",
|
|
"updated_at",
|
|
]
|
|
|
|
@staticmethod
|
|
def resolve_content_html(obj):
|
|
return obj.content_html
|
|
|
|
class AnnouncementListSchema(Schema):
|
|
id: int
|
|
title: str
|
|
content: str
|
|
announcement_type: str
|
|
priority: str
|
|
author: AuthorSchema
|
|
is_published: bool
|
|
publish_date: Optional[datetime] = None
|
|
created_at: datetime
|
|
|
|
|
|
class AnnouncementCreateSchema(Schema):
|
|
title: str
|
|
content: str
|
|
announcement_type: Literal["general", "event", "academic", "urgent"] = "general"
|
|
priority: Literal["low", "normal", "high", "urgent"] = "normal"
|
|
is_published: bool = False
|
|
publish_date: Optional[datetime] = None
|
|
|
|
|
|
class AnnouncementUpdateSchema(Schema):
|
|
title: Optional[str] = None
|
|
content: Optional[str] = None
|
|
announcement_type: Optional[Literal["general", "event", "academic", "urgent"]] = None
|
|
priority: Optional[Literal["low", "normal", "high", "urgent"]] = None
|
|
is_published: Optional[bool] = None
|
|
publish_date: Optional[datetime] = None
|
|
|
|
|
|
class PushDeviceSchema(ModelSchema):
|
|
user: AuthorSchema
|
|
|
|
class Meta:
|
|
model = PushNotificationDevice
|
|
fields = ["id", "device_token", "device_type", "is_active", "created_at"]
|
|
|
|
|
|
class PushDeviceCreateSchema(Schema):
|
|
device_token: str
|
|
device_type: str = "web"
|
|
|
|
|
|
class PushDeviceUpdateSchema(Schema):
|
|
is_active: bool
|
|
|
|
|
|
class MessageResponseSchema(Schema):
|
|
message: str
|
|
success: bool = True
|
|
|
|
|
|
class AnnouncementStatsSchema(Schema):
|
|
total_announcements: int
|
|
published_announcements: int
|
|
draft_announcements: int
|
|
urgent_announcements: int
|