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)
This commit is contained in:
@@ -5,6 +5,7 @@ from django.contrib.staticfiles.testing import StaticLiveServerTestCase
|
|||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.common.exceptions import WebDriverException
|
from selenium.common.exceptions import WebDriverException
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
|
from selenium.webdriver.common.keys import Keys
|
||||||
|
|
||||||
from .container_commands import reset_database
|
from .container_commands import reset_database
|
||||||
|
|
||||||
@@ -48,6 +49,13 @@ class FunctionalTest(StaticLiveServerTestCase):
|
|||||||
def wait_for_row_in_list_table(self, row_text):
|
def wait_for_row_in_list_table(self, row_text):
|
||||||
rows = self.browser.find_elements(By.CSS_SELECTOR, "#id_list_table tr")
|
rows = self.browser.find_elements(By.CSS_SELECTOR, "#id_list_table tr")
|
||||||
self.assertIn(row_text, [row.text for row in rows])
|
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
|
@wait
|
||||||
def wait_to_be_logged_in(self, email):
|
def wait_to_be_logged_in(self, email):
|
||||||
|
|||||||
@@ -17,9 +17,7 @@ class LayoutAndStylingTest(FunctionalTest):
|
|||||||
delta=10,
|
delta=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
inputbox.send_keys('testing')
|
self.add_list_item("testing")
|
||||||
inputbox.send_keys(Keys.ENTER)
|
|
||||||
self.wait_for_row_in_list_table('1. testing')
|
|
||||||
inputbox = self.get_item_input_box()
|
inputbox = self.get_item_input_box()
|
||||||
self.assertAlmostEqual(
|
self.assertAlmostEqual(
|
||||||
inputbox.location['x'] + inputbox.size['width'] / 2,
|
inputbox.location['x'] + inputbox.size['width'] / 2,
|
||||||
|
|||||||
@@ -44,9 +44,7 @@ class ItemValidationTest(FunctionalTest):
|
|||||||
|
|
||||||
def test_cannot_add_duplicate_items(self):
|
def test_cannot_add_duplicate_items(self):
|
||||||
self.browser.get(self.live_server_url)
|
self.browser.get(self.live_server_url)
|
||||||
self.get_item_input_box().send_keys("Witness divinity")
|
self.add_list_item("Witness divinity")
|
||||||
self.get_item_input_box().send_keys(Keys.ENTER)
|
|
||||||
self.wait_for_row_in_list_table("1. Witness divinity")
|
|
||||||
|
|
||||||
self.get_item_input_box().send_keys("Witness divinity")
|
self.get_item_input_box().send_keys("Witness divinity")
|
||||||
self.get_item_input_box().send_keys(Keys.ENTER)
|
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):
|
def test_error_messages_are_cleared_on_input(self):
|
||||||
self.browser.get(self.live_server_url)
|
self.browser.get(self.live_server_url)
|
||||||
self.get_item_input_box().send_keys("Banter too thicc")
|
self.add_list_item("Gobbledygook")
|
||||||
self.get_item_input_box().send_keys(Keys.ENTER)
|
self.get_item_input_box().send_keys("Gobbledygook")
|
||||||
self.wait_for_row_in_list_table("1. Banter too thicc")
|
|
||||||
self.get_item_input_box().send_keys("Banter too thicc")
|
|
||||||
self.get_item_input_box().send_keys(Keys.ENTER)
|
self.get_item_input_box().send_keys(Keys.ENTER)
|
||||||
self.wait_for(
|
self.wait_for(
|
||||||
lambda: self.assertTrue(self.get_error_element().is_displayed())
|
lambda: self.assertTrue(self.get_error_element().is_displayed())
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth import BACKEND_SESSION_KEY, SESSION_KEY, get_user_model
|
from selenium.webdriver.common.by import By
|
||||||
from django.contrib.sessions.backends.db import SessionStore
|
|
||||||
from .base import FunctionalTest
|
from .base import FunctionalTest
|
||||||
from .container_commands import create_session_on_server
|
from .container_commands import create_session_on_server
|
||||||
from .management.commands.create_session import create_pre_authenticated_session
|
from .management.commands.create_session import create_pre_authenticated_session
|
||||||
|
|
||||||
User = get_user_model()
|
|
||||||
|
|
||||||
|
|
||||||
class MyListsTest(FunctionalTest):
|
class MyListsTest(FunctionalTest):
|
||||||
def create_pre_authenticated_session(self, email):
|
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):
|
def test_logged_in_users_lists_are_saved_as_my_lists(self):
|
||||||
email = "discoman@example.com"
|
self.create_pre_authenticated_session("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.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"),
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|||||||
@@ -22,19 +22,14 @@ class NewVisitorTest(FunctionalTest):
|
|||||||
inputbox.send_keys(Keys.ENTER)
|
inputbox.send_keys(Keys.ENTER)
|
||||||
self.wait_for_row_in_list_table('1. Buy peacock feathers')
|
self.wait_for_row_in_list_table('1. Buy peacock feathers')
|
||||||
|
|
||||||
inputbox = self.get_item_input_box()
|
self.add_list_item("Use peacock feathers to make a fly")
|
||||||
inputbox.send_keys('Use peacock feathers to make a fly')
|
|
||||||
inputbox.send_keys(Keys.ENTER)
|
|
||||||
|
|
||||||
self.wait_for_row_in_list_table('2. 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')
|
self.wait_for_row_in_list_table('1. Buy peacock feathers')
|
||||||
|
|
||||||
def test_multiple_users_can_start_lists_at_different_urls(self):
|
def test_multiple_users_can_start_lists_at_different_urls(self):
|
||||||
self.browser.get(self.live_server_url)
|
self.browser.get(self.live_server_url)
|
||||||
inputbox = self.get_item_input_box()
|
self.add_list_item("Buy peacock feathers")
|
||||||
inputbox.send_keys('Buy peacock feathers')
|
|
||||||
inputbox.send_keys(Keys.ENTER)
|
|
||||||
self.wait_for_row_in_list_table('1. Buy peacock feathers')
|
|
||||||
|
|
||||||
edith_dash_url = self.browser.current_url
|
edith_dash_url = self.browser.current_url
|
||||||
self.assertRegex(edith_dash_url, '/apps/dashboard/.+')
|
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
|
page_text = self.browser.find_element(By.TAG_NAME, 'body').text
|
||||||
self.assertNotIn('Buy peacock feathers', page_text)
|
self.assertNotIn('Buy peacock feathers', page_text)
|
||||||
|
|
||||||
inputbox = self.get_item_input_box()
|
self.add_list_item("Buy milk")
|
||||||
inputbox.send_keys('Buy milk')
|
|
||||||
inputbox.send_keys(Keys.ENTER)
|
|
||||||
self.wait_for_row_in_list_table('1. Buy milk')
|
|
||||||
|
|
||||||
francis_dash_url = self.browser.current_url
|
francis_dash_url = self.browser.current_url
|
||||||
self.assertRegex(francis_dash_url, '/apps/dashboard/.+')
|
self.assertRegex(francis_dash_url, '/apps/dashboard/.+')
|
||||||
|
|||||||
Reference in New Issue
Block a user