2026-02-01 20:06:01 -05:00
|
|
|
from django.conf import settings
|
2026-02-07 19:44:47 -05:00
|
|
|
from selenium.webdriver.common.by import By
|
2026-02-01 20:06:01 -05:00
|
|
|
from .base import FunctionalTest
|
2026-02-03 22:14:55 -05:00
|
|
|
from .container_commands import create_session_on_server
|
|
|
|
|
from .management.commands.create_session import create_pre_authenticated_session
|
2026-02-01 20:06:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class MyListsTest(FunctionalTest):
|
|
|
|
|
def create_pre_authenticated_session(self, email):
|
2026-02-03 22:14:55 -05:00
|
|
|
if self.test_server:
|
|
|
|
|
session_key = create_session_on_server(self.test_server, email)
|
|
|
|
|
else:
|
|
|
|
|
session_key = create_pre_authenticated_session(email)
|
2026-02-01 20:06:01 -05:00
|
|
|
## 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,
|
2026-02-03 22:14:55 -05:00
|
|
|
value=session_key,
|
2026-02-01 20:06:01 -05:00
|
|
|
path="/",
|
|
|
|
|
)
|
|
|
|
|
)
|
2026-02-01 20:18:42 -05:00
|
|
|
|
2026-02-07 19:44:47 -05:00
|
|
|
def test_logged_in_users_lists_are_saved_as_my_lists(self):
|
|
|
|
|
self.create_pre_authenticated_session("discoman@example.com")
|
|
|
|
|
|
2026-02-01 20:18:42 -05:00
|
|
|
self.browser.get(self.live_server_url)
|
2026-02-07 19:44:47 -05:00
|
|
|
self.add_list_item("Reticulate splines")
|
|
|
|
|
self.add_list_item("Regurgitate spines")
|
|
|
|
|
first_list_url = self.browser.current_url
|
|
|
|
|
|
|
|
|
|
self.browser.find_element(By.LINK_TEXT, "My lists").click()
|
|
|
|
|
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertIn(
|
|
|
|
|
"discoman@example.com",
|
|
|
|
|
self.browser.find_element(By.CSS_SELECTOR, "h1").text,
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.browser.find_element(By.LINK_TEXT, "Reticulate splines")
|
|
|
|
|
)
|
|
|
|
|
self.browser.find_element(By.LINK_TEXT, "Reticulate splines").click()
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertEqual(self.browser.current_url, first_list_url)
|
|
|
|
|
)
|
2026-02-01 20:18:42 -05:00
|
|
|
|
|
|
|
|
self.browser.get(self.live_server_url)
|
2026-02-07 19:44:47 -05:00
|
|
|
self.add_list_item("Ribbon of death")
|
|
|
|
|
second_list_url = self.browser.current_url
|
|
|
|
|
|
|
|
|
|
self.browser.find_element(By.LINK_TEXT, "My lists").click()
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.browser.find_element(By.LINK_TEXT, "Ribbon of death")
|
|
|
|
|
)
|
|
|
|
|
self.browser.find_element(By.LINK_TEXT, "Ribbon of death").click()
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertEqual(self.browser.current_url, second_list_url)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.browser.find_element(By.CSS_SELECTOR, "#id_logout").click()
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertEqual(
|
|
|
|
|
self.browser.find_elements(By.LINK_TEXT, "My lists"),
|
|
|
|
|
[],
|
|
|
|
|
)
|
|
|
|
|
)
|