feat: Add preset shift templates, admin SMTP settings, test email dispatch, and email verification opt-out option
This commit is contained in:
@@ -2,7 +2,7 @@ from django.test import TestCase
|
||||
from django.contrib.auth import get_user_model
|
||||
from rest_framework.test import APIClient
|
||||
from rest_framework import status
|
||||
from .models import RegistrationDomainRule, RegistrationRestrictionSetting, EmailVerificationToken
|
||||
from .models import RegistrationDomainRule, RegistrationRestrictionSetting, EmailVerificationToken, SMTPSetting
|
||||
from apps.events.models import Event, TaskArea, Shift, ShiftSignup
|
||||
|
||||
User = get_user_model()
|
||||
@@ -74,6 +74,30 @@ class UserRegistrationTests(TestCase):
|
||||
self.assertEqual(res_login_ok.status_code, status.HTTP_200_OK)
|
||||
self.assertIn('token', res_login_ok.data)
|
||||
|
||||
def test_email_verification_opt_out(self):
|
||||
# Set require_email_verification to False (Opt-Out)
|
||||
setting = RegistrationRestrictionSetting.get_solo()
|
||||
setting.require_email_verification = False
|
||||
setting.save()
|
||||
|
||||
# Register user with Opt-Out
|
||||
res_reg = self.client.post('/api/users/register/', {
|
||||
'username': 'optout_user',
|
||||
'email': 'optout@example.com',
|
||||
'password': 'password123',
|
||||
'display_name': 'Opt-Out User'
|
||||
})
|
||||
self.assertEqual(res_reg.status_code, status.HTTP_201_CREATED)
|
||||
self.assertIn('token', res_reg.data)
|
||||
self.assertFalse(res_reg.data.get('requires_verification'))
|
||||
|
||||
# Immediate login works
|
||||
res_login = self.client.post('/api/users/login/', {
|
||||
'username': 'optout_user',
|
||||
'password': 'password123'
|
||||
})
|
||||
self.assertEqual(res_login.status_code, status.HTTP_200_OK)
|
||||
|
||||
def test_guest_shift_claiming_on_registration(self):
|
||||
# Create event, task area, shift
|
||||
event = Event.objects.create(title="Test Event", start_date="2026-08-01", end_date="2026-08-02")
|
||||
@@ -169,3 +193,25 @@ class UserRegistrationTests(TestCase):
|
||||
self.assertIsNotNone(signup.user)
|
||||
self.assertEqual(signup.user.username, 'erika_muster')
|
||||
self.assertIsNone(signup.guest_name)
|
||||
|
||||
def test_smtp_settings_configuration(self):
|
||||
admin = User.objects.create_superuser(username='smtp_admin', email='smtp@test.com', password='password123')
|
||||
self.client.force_authenticate(user=admin)
|
||||
|
||||
# GET SMTP setting
|
||||
res_get = self.client.get('/api/users/smtp-setting/')
|
||||
self.assertEqual(res_get.status_code, status.HTTP_200_OK)
|
||||
self.assertFalse(res_get.data['is_active'])
|
||||
|
||||
# UPDATE SMTP setting
|
||||
res_post = self.client.post('/api/users/smtp-setting/', {
|
||||
'is_active': True,
|
||||
'host': 'smtp.mailtrap.io',
|
||||
'port': 2525,
|
||||
'username': 'test_user',
|
||||
'password': 'test_password',
|
||||
'from_email': 'noreply@test.de'
|
||||
}, format='json')
|
||||
self.assertEqual(res_post.status_code, status.HTTP_200_OK)
|
||||
self.assertTrue(res_post.data['is_active'])
|
||||
self.assertEqual(res_post.data['host'], 'smtp.mailtrap.io')
|
||||
|
||||
Reference in New Issue
Block a user