5.3.1 An Unexpected Failure
parent
c0661056cf
commit
892cdbf541
|
@ -38,16 +38,24 @@ class NewVisitorTest(unittest.TestCase):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
table = self.browser.find_element_by_id('id_list_table')
|
table = self.browser.find_element_by_id('id_list_table')
|
||||||
rows = table.find_element_by_tag_name('tr')
|
rows = table.find_element_by_tag_name('tr')
|
||||||
self.assertTrue(
|
# self.assertTrue('1: Buy peacock feathers', [row.text for row in rows])
|
||||||
any(row.text == '1: Buy peacock feathers' for row in rows),
|
|
||||||
"New to-do item did not appear in table"
|
|
||||||
)
|
|
||||||
|
|
||||||
# There is still a text box inviting her to add another item. She
|
# 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)
|
# 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
|
# 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
|
# 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
|
# that the site has generated a unique URL for her -- there is some
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<table id="id_list_table">
|
<table id="id_list_table">
|
||||||
<tr><td>{{ new_item_text }}</td></tr>
|
<tr><td>1: {{ new_item_text }}</td></tr>
|
||||||
</table>
|
</table>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -19,5 +19,3 @@ class HomePageTest(TestCase):
|
||||||
response = self.client.post('/', data={'item_text': 'A new list item'})
|
response = self.client.post('/', data={'item_text': 'A new list item'})
|
||||||
self.assertIn('A new list item', response.content.decode())
|
self.assertIn('A new list item', response.content.decode())
|
||||||
self.assertTemplateUsed(response, 'home.html')
|
self.assertTemplateUsed(response, 'home.html')
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,5 @@ from django.shortcuts import render
|
||||||
# Create your views here
|
# Create your views here
|
||||||
def home_page(request):
|
def home_page(request):
|
||||||
return render(request=request, template_name='home.html', context={
|
return render(request=request, template_name='home.html', context={
|
||||||
'new_item_text': request.POST['item_text'],
|
'new_item_text': request.POST.get('item_text', ''),
|
||||||
})
|
})
|
Loading…
Reference in New Issue