Files
space-booking/backend/tests/test_email_service.py
Claude Agent df4031d99c feat: Space Booking System - MVP complet
Sistem web pentru rezervarea de birouri și săli de ședință
cu flux de aprobare administrativă.

Stack: FastAPI + Vue.js 3 + SQLite + TypeScript

Features implementate:
- Autentificare JWT + Self-registration cu email verification
- CRUD Spații, Utilizatori, Settings (Admin)
- Calendar interactiv (FullCalendar) cu drag-and-drop
- Creare rezervări cu validare (durată, program, overlap, max/zi)
- Rezervări recurente (săptămânal)
- Admin: aprobare/respingere/anulare cereri
- Admin: creare directă rezervări (bypass approval)
- Admin: editare orice rezervare
- User: editare/anulare rezervări proprii
- Notificări in-app (bell icon + dropdown)
- Notificări email (async SMTP cu BackgroundTasks)
- Jurnal acțiuni administrative (audit log)
- Rapoarte avansate (utilizare, top users, approval rate)
- Șabloane rezervări (booking templates)
- Atașamente fișiere (upload/download)
- Conflict warnings (verificare disponibilitate real-time)
- Integrare Google Calendar (OAuth2)
- Suport timezone (UTC storage + user preference)
- 225+ teste backend

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 17:51:29 +00:00

94 lines
3.0 KiB
Python

"""Tests for email service."""
from datetime import datetime, timedelta
from unittest.mock import AsyncMock, patch
import pytest
from app.services.email_service import (
generate_booking_email,
send_booking_notification,
send_email,
)
@pytest.mark.asyncio
async def test_send_email_disabled():
"""Test email sending when SMTP is disabled (default)."""
result = await send_email("test@example.com", "Test Subject", "Test Body")
assert result is True # Should succeed but only log
@pytest.mark.asyncio
async def test_send_email_with_smtp_mock():
"""Test email sending with mocked SMTP."""
with patch("app.services.email_service.settings.smtp_enabled", True):
with patch(
"app.services.email_service.aiosmtplib.send", new_callable=AsyncMock
) as mock_send:
result = await send_email("test@example.com", "Test", "Body")
assert result is True
mock_send.assert_called_once()
def test_generate_booking_email_approved(test_booking, test_space):
"""Test email generation for approved booking."""
test_booking.space = test_space
subject, body = generate_booking_email(
test_booking, "approved", "user@example.com", "John Doe"
)
assert subject == "Rezervare Aprobată"
assert "John Doe" in body
assert test_space.name in body
assert "aprobată" in body
def test_generate_booking_email_rejected(test_booking, test_space):
"""Test email generation for rejected booking with reason."""
test_booking.space = test_space
subject, body = generate_booking_email(
test_booking,
"rejected",
"user@example.com",
"John Doe",
extra_data={"rejection_reason": "Spațiul este în mentenanță"},
)
assert subject == "Rezervare Respinsă"
assert "respinsă" in body
assert "Spațiul este în mentenanță" in body
def test_generate_booking_email_canceled(test_booking, test_space):
"""Test email generation for canceled booking."""
test_booking.space = test_space
subject, body = generate_booking_email(
test_booking,
"canceled",
"user@example.com",
"John Doe",
extra_data={"cancellation_reason": "Eveniment anulat"},
)
assert subject == "Rezervare Anulată"
assert "anulată" in body
assert "Eveniment anulat" in body
def test_generate_booking_email_created(test_booking, test_space):
"""Test email generation for created booking (admin notification)."""
test_booking.space = test_space
subject, body = generate_booking_email(
test_booking, "created", "admin@example.com", "Admin User"
)
assert subject == "Cerere Nouă de Rezervare"
assert "cerere de rezervare" in body
assert test_space.name in body
@pytest.mark.asyncio
async def test_send_booking_notification(test_booking, test_space):
"""Test sending booking notification."""
test_booking.space = test_space
result = await send_booking_notification(
test_booking, "approved", "user@example.com", "John Doe"
)
assert result is True