From 9c1cd344243422a1614f371fd92624596f992a45 Mon Sep 17 00:00:00 2001 From: JasonHomeWorkstationUbuntu Date: Mon, 9 Nov 2020 20:25:29 +1100 Subject: [PATCH] 7.3 Ensuring We Have a Regression Test --- src/functional_tests/tests.py | 45 ++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/functional_tests/tests.py b/src/functional_tests/tests.py index ec49aaf..377f4ba 100644 --- a/src/functional_tests/tests.py +++ b/src/functional_tests/tests.py @@ -71,4 +71,47 @@ class NewVisitorTest(LiveServerTestCase): # She visits that URL - her to-do list is still there. - # Satisfied, she goes back to sleep \ No newline at end of file + # Satisfied, she goes back to sleep + + def test_multiple_users_can_start_lists_at_different_urls(self): + # Edith starts a new to-do list + self.browser.get(self.live_server_url) + inputbox = self.browser.find_element_by_id('id_new_item') + inputbox.send_keys('Buy peacock feathers') + inputbox.send_keys(Keys.ENTER) + self.wait_for_row_in_list_table('1: Buy peacock feathers') + + # She notices that her list has a unique URL + edith_list_url = self.browser.current_url + self.assertRegex(edith_list_url, '/list/.+') # assertRegex is a helper func from unittest that checks whether a string maches a regular expression + + # Now a new user, Francis, comes along to the site. + + ## We use a new browser session to make sure that no information + ## of Edith's is coming through from cookies etc + self.browser.quit() + self.browser = webdriver.Firefox() + + # Francis visits the home page. There is no sing of Edith's list + self.browser.get(self.live_server_url) + page_text = self.browser.find_element_by_tag_name('body').text + self.assertNotIn('Buy peacock feathers', page_text) + self.assertNotIn('make a fly', page_text) + + # Francis starts a new list by entering a new item. He is less interesting than Edith + inputbox = self.browser.find_element_by_id('id_new_item') + inputbox.send_keys('Buy milk') + inputbox.send_keys(Keys.ENTER) + self.wait_for_row_in_list_table('1: Buy milk') + + # Francis gets his own unique URL + francis_list_url = self.browser.current_url + self.assertRegex(francis_list_url, '/lists/.+') + self.assertNotEqual(francis_list_url, edith_list_url) + + # Again, there is no trace of Edith's list + page_text = self.browser.find_element_by_tag_name('body').text + self.assertNotIn('Buy peacock feathers', page_text) + self.assertIn('Buy milk', page_text) + + # Satisfied, they both go back to sleep \ No newline at end of file