snapshot: preserve role-aware notification preferences and operational alerts
This commit is contained in:
@@ -3,6 +3,7 @@ from django.test import Client, TestCase
|
||||
from django.utils import timezone
|
||||
|
||||
from workflows.models import UserProfile
|
||||
from workflows.roles import ROLE_PLATFORM_OWNER, assign_user_role
|
||||
from workflows.totp import generate_totp_token
|
||||
|
||||
|
||||
@@ -32,6 +33,55 @@ class AccountUISmokeTests(TestCase):
|
||||
def test_user_profile_is_created_automatically(self):
|
||||
self.assertTrue(UserProfile.objects.filter(user=self.user).exists())
|
||||
|
||||
def test_notification_preferences_can_be_updated(self):
|
||||
response = self.client.post(
|
||||
'/account/',
|
||||
{
|
||||
'account_form': 'notification_preferences',
|
||||
'onboarding_success': 'on',
|
||||
'onboarding_failure': '',
|
||||
'offboarding_success': '',
|
||||
'offboarding_failure': 'on',
|
||||
},
|
||||
HTTP_HOST='localhost',
|
||||
follow=True,
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
profile = UserProfile.objects.get(user=self.user)
|
||||
self.assertEqual(
|
||||
profile.notification_preferences,
|
||||
{
|
||||
'onboarding_success': True,
|
||||
'onboarding_failure': False,
|
||||
'offboarding_success': False,
|
||||
'offboarding_failure': True,
|
||||
'backup_success': True,
|
||||
'backup_failure': True,
|
||||
'welcome_email_success': False,
|
||||
'welcome_email_failure': False,
|
||||
'trial_alerts': True,
|
||||
'system_alerts': True,
|
||||
},
|
||||
)
|
||||
|
||||
def test_staff_account_notifications_hide_admin_only_categories(self):
|
||||
response = self.client.get('/account/', HTTP_HOST='localhost')
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotContains(response, 'Backup erfolgreich')
|
||||
self.assertNotContains(response, 'Trial-Hinweise')
|
||||
self.assertNotContains(response, 'System-Hinweise')
|
||||
self.assertContains(response, 'Welcome E-Mail erfolgreich')
|
||||
|
||||
def test_platform_owner_sees_all_notification_categories(self):
|
||||
assign_user_role(self.user, ROLE_PLATFORM_OWNER)
|
||||
response = self.client.get('/account/', HTTP_HOST='localhost')
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, 'Backup erfolgreich')
|
||||
self.assertContains(response, 'Trial-Hinweise')
|
||||
self.assertContains(response, 'System-Hinweise')
|
||||
|
||||
def test_account_profile_details_can_be_updated(self):
|
||||
response = self.client.post(
|
||||
'/account/',
|
||||
@@ -106,23 +156,26 @@ class AccountUISmokeTests(TestCase):
|
||||
{'username': 'profile-user', 'password': 'secret-12345'},
|
||||
HTTP_HOST='localhost',
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(response['Location'], '/accounts/login/totp/')
|
||||
|
||||
response = client.get('/accounts/login/totp/', HTTP_HOST='localhost')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, 'TOTP-Code')
|
||||
self.assertContains(response, 'Recovery-Code verwenden')
|
||||
|
||||
token = generate_totp_token(profile.totp_secret, int(timezone.now().timestamp()))
|
||||
response = client.post(
|
||||
'/accounts/login/',
|
||||
{'username': 'profile-user', 'password': 'secret-12345', 'otp_code': token},
|
||||
'/accounts/login/totp/',
|
||||
{'otp_code': token},
|
||||
HTTP_HOST='localhost',
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
client = Client()
|
||||
response = client.post(
|
||||
'/accounts/login/',
|
||||
{'username': 'profile-user', 'password': 'secret-12345', 'recovery_code': 'ABCDE-12345'},
|
||||
HTTP_HOST='localhost',
|
||||
)
|
||||
first_step = client.post('/accounts/login/', {'username': 'profile-user', 'password': 'secret-12345'}, HTTP_HOST='localhost')
|
||||
self.assertEqual(first_step.status_code, 302)
|
||||
response = client.post('/accounts/login/totp/', {'recovery_code': 'ABCDE-12345'}, HTTP_HOST='localhost')
|
||||
self.assertEqual(response.status_code, 302)
|
||||
profile.refresh_from_db()
|
||||
self.assertEqual(profile.totp_recovery_codes, [])
|
||||
|
||||
Reference in New Issue
Block a user