From 291025c13fe6ea0a23fc425dfb9f807460e40664 Mon Sep 17 00:00:00 2001 From: Disco DeDisco Date: Wed, 14 Jan 2026 13:23:31 -0500 Subject: [PATCH] FTs now exist in own test files, ea. reliant on base.py to execute --- src/functional_tests/base.py | 33 +++++++++++ .../test_layout_and_styling.py | 28 ++++++++++ .../test_list_item_validation.py | 8 +++ ...{tests.py => test_simple_list_creation.py} | 55 +------------------ 4 files changed, 72 insertions(+), 52 deletions(-) create mode 100644 src/functional_tests/base.py create mode 100644 src/functional_tests/test_layout_and_styling.py create mode 100644 src/functional_tests/test_list_item_validation.py rename src/functional_tests/{tests.py => test_simple_list_creation.py} (55%) diff --git a/src/functional_tests/base.py b/src/functional_tests/base.py new file mode 100644 index 0000000..d05a5a7 --- /dev/null +++ b/src/functional_tests/base.py @@ -0,0 +1,33 @@ +import os +import time + +from django.contrib.staticfiles.testing import StaticLiveServerTestCase +from selenium import webdriver +from selenium.common.exceptions import WebDriverException +from selenium.webdriver.common.by import By + +MAX_WAIT = 5 + +class FunctionalTest(StaticLiveServerTestCase): + # Helper methods + def setUp(self): + self.browser = webdriver.Firefox() + if test_server := os.environ.get('TEST_SERVER'): + self.live_server_url = 'http://' + test_server + + def tearDown(self): + self.browser.quit() + + def wait_for_row_in_list_table(self, row_text): + start_time = time.time() + while True: + try: + table = self.browser.find_element(By.ID, 'id-list-table') + rows = table.find_elements(By.TAG_NAME, 'tr') + self.assertIn(row_text, [row.text for row in rows]) + return + except (AssertionError, WebDriverException): + if time.time() - start_time > MAX_WAIT: + raise + time.sleep(0.5) + \ No newline at end of file diff --git a/src/functional_tests/test_layout_and_styling.py b/src/functional_tests/test_layout_and_styling.py new file mode 100644 index 0000000..a0a01d3 --- /dev/null +++ b/src/functional_tests/test_layout_and_styling.py @@ -0,0 +1,28 @@ +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys + +from .base import FunctionalTest + +class LayoutAndStylingTest(FunctionalTest): + def test_layout_and_styling(self): + self.browser.get(self.live_server_url) + + self.browser.set_window_size(1024, 768) + print("Viewport width:", self.browser.execute_script("return window.innerWidth")) + + inputbox = self.browser.find_element(By.ID, 'id-new-item') + self.assertAlmostEqual( + inputbox.location['x'] + inputbox.size['width'] / 2, + 512, + delta=10, + ) + + inputbox.send_keys('testing') + inputbox.send_keys(Keys.ENTER) + self.wait_for_row_in_list_table('1. testing') + inputbox = self.browser.find_element(By.ID, 'id-new-item') + self.assertAlmostEqual( + inputbox.location['x'] + inputbox.size['width'] / 2, + 512, + delta=10, + ) diff --git a/src/functional_tests/test_list_item_validation.py b/src/functional_tests/test_list_item_validation.py new file mode 100644 index 0000000..b75ed5d --- /dev/null +++ b/src/functional_tests/test_list_item_validation.py @@ -0,0 +1,8 @@ +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys + +from .base import FunctionalTest + +class ItemValidationTest(FunctionalTest): + def test_cannot_add_empty_list_items(self): + self.fail("write me!") diff --git a/src/functional_tests/tests.py b/src/functional_tests/test_simple_list_creation.py similarity index 55% rename from src/functional_tests/tests.py rename to src/functional_tests/test_simple_list_creation.py index ae64237..fee7259 100644 --- a/src/functional_tests/tests.py +++ b/src/functional_tests/test_simple_list_creation.py @@ -1,37 +1,11 @@ -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 -import os -import time -import unittest + +from .base import FunctionalTest MAX_WAIT = 5 -class NewVisitorTest(StaticLiveServerTestCase): - # Helper methods - def setUp(self): - self.browser = webdriver.Firefox() - if test_server := os.environ.get('TEST_SERVER'): - self.live_server_url = 'http://' + test_server - - def tearDown(self): - self.browser.quit() - - def wait_for_row_in_list_table(self, row_text): - start_time = time.time() - while True: - try: - table = self.browser.find_element(By.ID, 'id-list-table') - rows = table.find_elements(By.TAG_NAME, 'tr') - self.assertIn(row_text, [row.text for row in rows]) - return - except (AssertionError, WebDriverException): - if time.time() - start_time > MAX_WAIT: - raise - time.sleep(0.5) - +class NewVisitorTest(FunctionalTest): # Test methods def test_can_start_a_todo_list(self): self.browser.get(self.live_server_url) @@ -83,26 +57,3 @@ class NewVisitorTest(StaticLiveServerTestCase): page_text = self.browser.find_element(By.TAG_NAME, 'body').text self.assertNotIn('Buy peacock feathers', page_text) self.assertIn('Buy milk', page_text) - - def test_layout_and_styling(self): - self.browser.get(self.live_server_url) - - self.browser.set_window_size(1200, 768) # may have to switch back to 1024 - print("Viewport width:", self.browser.execute_script("return window.innerWidth")) - - inputbox = self.browser.find_element(By.ID, 'id-new-item') - self.assertAlmostEqual( - inputbox.location['x'] + inputbox.size['width'] / 2, - 512, - delta=10, - ) - - inputbox.send_keys('testing') - inputbox.send_keys(Keys.ENTER) - self.wait_for_row_in_list_table('1. testing') - inputbox = self.browser.find_element(By.ID, 'id-new-item') - self.assertAlmostEqual( - inputbox.location['x'] + inputbox.size['width'] / 2, - 512, - delta=10, - )