2026-02-01 20:06:01 -05:00
|
|
|
from django.conf import settings
|
|
|
|
|
from django.contrib.auth import BACKEND_SESSION_KEY, SESSION_KEY, get_user_model
|
|
|
|
|
from django.contrib.sessions.backends.db import SessionStore
|
|
|
|
|
from .base import FunctionalTest
|
|
|
|
|
|
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MyListsTest(FunctionalTest):
|
|
|
|
|
def create_pre_authenticated_session(self, email):
|
|
|
|
|
user = User.objects.create(email=email)
|
|
|
|
|
session = SessionStore()
|
|
|
|
|
session[SESSION_KEY] = user.pk
|
|
|
|
|
session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
|
|
|
|
|
session.save()
|
|
|
|
|
## to set a cookie we need to first visit the domain
|
|
|
|
|
## 404 pages load the quickest!
|
|
|
|
|
self.browser.get(self.live_server_url + "/404_no_such_url/")
|
|
|
|
|
self.browser.add_cookie(
|
|
|
|
|
dict(
|
|
|
|
|
name=settings.SESSION_COOKIE_NAME,
|
|
|
|
|
value=session.session_key,
|
|
|
|
|
path="/",
|
|
|
|
|
)
|
|
|
|
|
)
|
2026-02-01 20:18:42 -05:00
|
|
|
|
|
|
|
|
def test_logged_in_users_are_saved_as_my_lists(self):
|
|
|
|
|
email = "discoman@example.com"
|
|
|
|
|
self.browser.get(self.live_server_url)
|
|
|
|
|
self.wait_to_be_logged_out(email)
|
|
|
|
|
|
|
|
|
|
self.create_pre_authenticated_session(email)
|
|
|
|
|
self.browser.get(self.live_server_url)
|
|
|
|
|
self.wait_to_be_logged_in(email)
|