From 892cdbf541a33126d80c9e0d1a0a062a5470c555 Mon Sep 17 00:00:00 2001 From: JasonHomeWorkstationUbuntu Date: Sun, 8 Nov 2020 20:39:30 +1100 Subject: [PATCH] 5.3.1 An Unexpected Failure --- src/functional_tests.py | 18 +++++++++++++----- src/lists/templates/home.html | 2 +- src/lists/tests.py | 4 +--- src/lists/views.py | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/functional_tests.py b/src/functional_tests.py index 328aeb1..24347ff 100644 --- a/src/functional_tests.py +++ b/src/functional_tests.py @@ -38,16 +38,24 @@ class NewVisitorTest(unittest.TestCase): time.sleep(1) table = self.browser.find_element_by_id('id_list_table') rows = table.find_element_by_tag_name('tr') - self.assertTrue( - any(row.text == '1: Buy peacock feathers' for row in rows), - "New to-do item did not appear in table" - ) + # self.assertTrue('1: Buy peacock feathers', [row.text for row in rows]) # There is still a text box inviting her to add another item. She # enters "Use peacock feathers to make a fly" (Edith is very methodical) - self.fail('Finish the test!') + inputbox = self.browser.find_element_by_id('id_new_item') + inputbox.send_keys('Use peacock feathers to make a fly') + inputbox.send_keys(Keys.ENTER) + time.sleep(1) # The page updates again, and now shows both items on her list + table = self.browser.find_element_by_id('id_list_table') + rows = table.find_element_by_tag_name('tr') + print(rows) + self.assertIn('1: Buy peacock feathers', [row.text for row in rows]) + self.assertIn( + '2: Use peacock feathers to make a fly', + [row.text for row in rows] + ) # 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 diff --git a/src/lists/templates/home.html b/src/lists/templates/home.html index 34c2117..a055bb0 100644 --- a/src/lists/templates/home.html +++ b/src/lists/templates/home.html @@ -10,7 +10,7 @@ - +
{{ new_item_text }}
1: {{ new_item_text }}
\ No newline at end of file diff --git a/src/lists/tests.py b/src/lists/tests.py index 31ff19b..c285297 100644 --- a/src/lists/tests.py +++ b/src/lists/tests.py @@ -18,6 +18,4 @@ class HomePageTest(TestCase): def test_can_save_a_POST_request(self): response = self.client.post('/', data={'item_text': 'A new list item'}) self.assertIn('A new list item', response.content.decode()) - self.assertTemplateUsed(response, 'home.html') - - \ No newline at end of file + self.assertTemplateUsed(response, 'home.html') \ No newline at end of file diff --git a/src/lists/views.py b/src/lists/views.py index 8927dc9..e569739 100644 --- a/src/lists/views.py +++ b/src/lists/views.py @@ -5,5 +5,5 @@ from django.shortcuts import render # Create your views here def home_page(request): return render(request=request, template_name='home.html', context={ - 'new_item_text': request.POST['item_text'], + 'new_item_text': request.POST.get('item_text', ''), }) \ No newline at end of file