inital checkin
This commit is contained in:
30
users/tests.py
Normal file
30
users/tests.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from django.urls import reverse
|
||||
from .models import User
|
||||
|
||||
class ProfileThemeTest(TestCase):
|
||||
def setUp(self):
|
||||
self.user = User.objects.create_user(username='testuser', password='password')
|
||||
self.client.login(username='testuser', password='password')
|
||||
|
||||
def test_theme_preference_update(self):
|
||||
# Default should be dark
|
||||
self.assertEqual(self.user.profile.theme_preference, 'dark')
|
||||
|
||||
# Check if form is in context
|
||||
response = self.client.get(reverse('users:profile'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn('form', response.context)
|
||||
|
||||
# Update theme to light
|
||||
response = self.client.post(reverse('users:profile'), {
|
||||
'theme_preference': 'light'
|
||||
})
|
||||
|
||||
# Should redirect back to profile
|
||||
self.assertRedirects(response, reverse('users:profile'))
|
||||
|
||||
# Check if updated in DB
|
||||
self.user.profile.refresh_from_db()
|
||||
self.assertEqual(self.user.profile.theme_preference, 'light')
|
||||
Reference in New Issue
Block a user