-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow configuring guest user profile (#809)
- Loading branch information
1 parent
79bf4b3
commit aad62f6
Showing
7 changed files
with
127 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
bookmarks/migrations/0038_globalsettings_guest_profile_user.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 5.0.8 on 2024-08-31 17:54 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("bookmarks", "0037_globalsettings"), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="globalsettings", | ||
name="guest_profile_user", | ||
field=models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.SET_NULL, | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from bookmarks.models import UserProfile, GlobalSettings | ||
from bookmarks.tests.helpers import BookmarkFactoryMixin | ||
from bookmarks.middlewares import standard_profile | ||
|
||
|
||
class UserProfileMiddlewareTestCase(TestCase, BookmarkFactoryMixin): | ||
def test_unauthenticated_user_should_use_standard_profile_by_default(self): | ||
response = self.client.get(reverse("login")) | ||
|
||
self.assertEqual(standard_profile, response.wsgi_request.user_profile) | ||
|
||
def test_unauthenticated_user_should_use_custom_configured_profile(self): | ||
guest_user = self.setup_user() | ||
guest_user_profile = guest_user.profile | ||
guest_user_profile.theme = UserProfile.THEME_DARK | ||
guest_user_profile.save() | ||
|
||
global_settings = GlobalSettings.get() | ||
global_settings.guest_profile_user = guest_user | ||
global_settings.save() | ||
|
||
response = self.client.get(reverse("login")) | ||
|
||
self.assertEqual(guest_user_profile, response.wsgi_request.user_profile) | ||
|
||
def test_authenticated_user_should_use_own_profile(self): | ||
guest_user = self.setup_user() | ||
guest_user_profile = guest_user.profile | ||
guest_user_profile.theme = UserProfile.THEME_DARK | ||
guest_user_profile.save() | ||
|
||
global_settings = GlobalSettings.get() | ||
global_settings.guest_profile_user = guest_user | ||
global_settings.save() | ||
|
||
user = self.get_or_create_test_user() | ||
user_profile = user.profile | ||
user_profile.theme = UserProfile.THEME_LIGHT | ||
user_profile.save() | ||
self.client.force_login(user) | ||
|
||
response = self.client.get(reverse("login"), follow=True) | ||
|
||
self.assertEqual(user_profile, response.wsgi_request.user_profile) |