diff --git a/src/functional_tests/tests.py b/src/functional_tests/tests.py index 7d99131..70c484c 100644 --- a/src/functional_tests/tests.py +++ b/src/functional_tests/tests.py @@ -29,7 +29,7 @@ class NewVisitorTest(LiveServerTestCase): raise e time.sleep(0.5) - def test_can_start_a_list_and_retrieve_it_later(self): + def test_can_start_a_list_for_one_user(self): # Edith has heard about a cool new online to-do app. She goes # to check out its homepage self.browser.get(self.live_server_url) @@ -62,8 +62,9 @@ class NewVisitorTest(LiveServerTestCase): inputbox.send_keys(Keys.ENTER) # The page updates again, and now shows both items on her list - self.wait_for_row_in_list_table('1: Buy peacock feathers') 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') + # Edith wonders whether the site will remember her list. Then she sees # that the site has generated a unique URL for her -- there is some @@ -72,4 +73,48 @@ 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, '/lists/.+') + + # 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 sign 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 + # 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