2026-02-18 15:24:55 -05:00
|
|
|
import os
|
|
|
|
|
|
2026-02-22 21:50:25 -05:00
|
|
|
from django.conf import settings
|
2026-02-17 21:19:24 -05:00
|
|
|
from selenium import webdriver
|
|
|
|
|
from selenium.webdriver.common.by import By
|
2026-02-17 23:07:12 -05:00
|
|
|
|
2026-02-17 21:19:24 -05:00
|
|
|
from .base import FunctionalTest
|
2026-02-17 23:07:12 -05:00
|
|
|
from .list_page import ListPage
|
2026-02-17 23:27:54 -05:00
|
|
|
from .my_lists_page import MyListsPage
|
2026-02-17 21:19:24 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Helper fns
|
|
|
|
|
def quit_if_possible(browser):
|
|
|
|
|
try:
|
|
|
|
|
browser.quit()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test mdls
|
|
|
|
|
class SharingTest(FunctionalTest):
|
|
|
|
|
def test_can_share_a_list_with_another_user(self):
|
|
|
|
|
self.create_pre_authenticated_session("discoman@example.com")
|
|
|
|
|
disco_browser = self.browser
|
|
|
|
|
self.addCleanup(lambda: quit_if_possible(disco_browser))
|
|
|
|
|
|
2026-02-18 15:24:55 -05:00
|
|
|
options = webdriver.FirefoxOptions()
|
|
|
|
|
if os.environ.get("HEADLESS"):
|
|
|
|
|
options.add_argument("--headless")
|
|
|
|
|
ali_browser = webdriver.Firefox(options=options)
|
2026-02-17 21:19:24 -05:00
|
|
|
self.addCleanup(lambda: quit_if_possible(ali_browser))
|
|
|
|
|
self.browser = ali_browser
|
|
|
|
|
self.create_pre_authenticated_session("alice@example.com")
|
|
|
|
|
|
|
|
|
|
self.browser = disco_browser
|
|
|
|
|
self.browser.get(self.live_server_url)
|
2026-02-17 23:07:12 -05:00
|
|
|
list_page = ListPage(self).add_list_item("Send help")
|
2026-02-17 21:19:24 -05:00
|
|
|
|
2026-02-17 23:07:12 -05:00
|
|
|
share_box = list_page.get_share_box()
|
2026-02-17 21:19:24 -05:00
|
|
|
self.assertEqual(
|
|
|
|
|
share_box.get_attribute("placeholder"),
|
|
|
|
|
"friend@example.com",
|
|
|
|
|
)
|
2026-02-17 23:07:12 -05:00
|
|
|
|
2026-02-18 13:53:05 -05:00
|
|
|
list_page.share_list_with("alice@example.com")
|
2026-02-17 23:27:54 -05:00
|
|
|
|
|
|
|
|
self.browser = ali_browser
|
|
|
|
|
MyListsPage(self).go_to_my_lists_page("alice@example.com")
|
|
|
|
|
|
|
|
|
|
self.browser.find_element(By.LINK_TEXT, "Send help").click()
|
|
|
|
|
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertEqual(list_page.get_list_owner(), "discoman@example.com")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
list_page.add_list_item("At your command, Disco King")
|
|
|
|
|
|
|
|
|
|
self.browser = disco_browser
|
|
|
|
|
self.browser.refresh()
|
|
|
|
|
list_page.wait_for_row_in_list_table("At your command, Disco King", 2)
|
2026-02-22 21:50:25 -05:00
|
|
|
|
|
|
|
|
class ListAccessTest(FunctionalTest):
|
|
|
|
|
def test_stranger_cannot_access_owned_list(self):
|
|
|
|
|
self.create_pre_authenticated_session("disco@example.com")
|
|
|
|
|
self.browser.get(self.live_server_url)
|
|
|
|
|
list_page = ListPage(self).add_list_item("private eye")
|
|
|
|
|
list_url = self.browser.current_url
|
|
|
|
|
|
|
|
|
|
self.browser.delete_cookie(settings.SESSION_COOKIE_NAME)
|
|
|
|
|
self.browser.get(list_url)
|
|
|
|
|
|
|
|
|
|
self.assertNotEqual(self.browser.current_url, list_url)
|
|
|
|
|
|