From 58b526f4349645c4498f8917d6325b290e45b64e Mon Sep 17 00:00:00 2001 From: Disco DeDisco Date: Sat, 7 Feb 2026 19:44:47 -0500 Subject: [PATCH] add_list_item() helper added to functional_tests.base; further propagated into .test_layout_and_styling, .test_list_item_validation, .test_my_lists & .test_simple_list_creation; all FTs passing locally (tho js-dependent FT still require nginx to serve scripts properly in docker or on server) --- src/functional_tests/base.py | 8 +++ .../test_layout_and_styling.py | 4 +- .../test_list_item_validation.py | 10 ++-- src/functional_tests/test_my_lists.py | 54 +++++++++++++++---- .../test_simple_list_creation.py | 14 ++--- 5 files changed, 59 insertions(+), 31 deletions(-) diff --git a/src/functional_tests/base.py b/src/functional_tests/base.py index a3e5577..e222181 100644 --- a/src/functional_tests/base.py +++ b/src/functional_tests/base.py @@ -5,6 +5,7 @@ from django.contrib.staticfiles.testing import StaticLiveServerTestCase from selenium import webdriver from selenium.common.exceptions import WebDriverException from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys from .container_commands import reset_database @@ -48,6 +49,13 @@ class FunctionalTest(StaticLiveServerTestCase): def wait_for_row_in_list_table(self, row_text): rows = self.browser.find_elements(By.CSS_SELECTOR, "#id_list_table tr") self.assertIn(row_text, [row.text for row in rows]) + + def add_list_item(self, item_text): + num_rows = len(self.browser.find_elements(By.CSS_SELECTOR, "#id_list_table tr")) + self.get_item_input_box().send_keys(item_text) + self.get_item_input_box().send_keys(Keys.ENTER) + item_number = num_rows + 1 + self.wait_for_row_in_list_table(f"{item_number}. {item_text}") @wait def wait_to_be_logged_in(self, email): diff --git a/src/functional_tests/test_layout_and_styling.py b/src/functional_tests/test_layout_and_styling.py index bc863a9..a341abb 100644 --- a/src/functional_tests/test_layout_and_styling.py +++ b/src/functional_tests/test_layout_and_styling.py @@ -17,9 +17,7 @@ class LayoutAndStylingTest(FunctionalTest): delta=10, ) - inputbox.send_keys('testing') - inputbox.send_keys(Keys.ENTER) - self.wait_for_row_in_list_table('1. testing') + self.add_list_item("testing") inputbox = self.get_item_input_box() self.assertAlmostEqual( inputbox.location['x'] + inputbox.size['width'] / 2, diff --git a/src/functional_tests/test_list_item_validation.py b/src/functional_tests/test_list_item_validation.py index 9935fa2..70be6f6 100644 --- a/src/functional_tests/test_list_item_validation.py +++ b/src/functional_tests/test_list_item_validation.py @@ -44,9 +44,7 @@ class ItemValidationTest(FunctionalTest): def test_cannot_add_duplicate_items(self): self.browser.get(self.live_server_url) - self.get_item_input_box().send_keys("Witness divinity") - self.get_item_input_box().send_keys(Keys.ENTER) - self.wait_for_row_in_list_table("1. Witness divinity") + self.add_list_item("Witness divinity") self.get_item_input_box().send_keys("Witness divinity") self.get_item_input_box().send_keys(Keys.ENTER) @@ -60,10 +58,8 @@ class ItemValidationTest(FunctionalTest): def test_error_messages_are_cleared_on_input(self): self.browser.get(self.live_server_url) - self.get_item_input_box().send_keys("Banter too thicc") - self.get_item_input_box().send_keys(Keys.ENTER) - self.wait_for_row_in_list_table("1. Banter too thicc") - self.get_item_input_box().send_keys("Banter too thicc") + self.add_list_item("Gobbledygook") + self.get_item_input_box().send_keys("Gobbledygook") self.get_item_input_box().send_keys(Keys.ENTER) self.wait_for( lambda: self.assertTrue(self.get_error_element().is_displayed()) diff --git a/src/functional_tests/test_my_lists.py b/src/functional_tests/test_my_lists.py index 11f7288..716f726 100644 --- a/src/functional_tests/test_my_lists.py +++ b/src/functional_tests/test_my_lists.py @@ -1,12 +1,9 @@ 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 selenium.webdriver.common.by import By from .base import FunctionalTest from .container_commands import create_session_on_server from .management.commands.create_session import create_pre_authenticated_session -User = get_user_model() - class MyListsTest(FunctionalTest): def create_pre_authenticated_session(self, email): @@ -25,11 +22,48 @@ class MyListsTest(FunctionalTest): ) ) - 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) + def test_logged_in_users_lists_are_saved_as_my_lists(self): + self.create_pre_authenticated_session("discoman@example.com") - self.create_pre_authenticated_session(email) self.browser.get(self.live_server_url) - self.wait_to_be_logged_in(email) + 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) + ) + + self.browser.get(self.live_server_url) + 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"), + [], + ) + ) diff --git a/src/functional_tests/test_simple_list_creation.py b/src/functional_tests/test_simple_list_creation.py index dc562c2..340a7da 100644 --- a/src/functional_tests/test_simple_list_creation.py +++ b/src/functional_tests/test_simple_list_creation.py @@ -22,19 +22,14 @@ class NewVisitorTest(FunctionalTest): inputbox.send_keys(Keys.ENTER) self.wait_for_row_in_list_table('1. Buy peacock feathers') - inputbox = self.get_item_input_box() - inputbox.send_keys('Use peacock feathers to make a fly') - inputbox.send_keys(Keys.ENTER) + self.add_list_item("Use peacock feathers to make a fly") self.wait_for_row_in_list_table('2. Use peacock feathers to make a fly') self.wait_for_row_in_list_table('1. Buy peacock feathers') def test_multiple_users_can_start_lists_at_different_urls(self): self.browser.get(self.live_server_url) - inputbox = self.get_item_input_box() - inputbox.send_keys('Buy peacock feathers') - inputbox.send_keys(Keys.ENTER) - self.wait_for_row_in_list_table('1. Buy peacock feathers') + self.add_list_item("Buy peacock feathers") edith_dash_url = self.browser.current_url self.assertRegex(edith_dash_url, '/apps/dashboard/.+') @@ -45,10 +40,7 @@ class NewVisitorTest(FunctionalTest): page_text = self.browser.find_element(By.TAG_NAME, 'body').text self.assertNotIn('Buy peacock feathers', page_text) - inputbox = self.get_item_input_box() - inputbox.send_keys('Buy milk') - inputbox.send_keys(Keys.ENTER) - self.wait_for_row_in_list_table('1. Buy milk') + self.add_list_item("Buy milk") francis_dash_url = self.browser.current_url self.assertRegex(francis_dash_url, '/apps/dashboard/.+')