Compare commits

..

No commits in common. "5cedbfe9ce424939bfd08f14331a3952dac97697" and "1e2cc408deaf85b2d722bd7f9ca6eb027637fec4" have entirely different histories.

5 changed files with 6 additions and 57 deletions

View File

@ -1,8 +1,5 @@
import unittest
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
class NewVisitorTest(unittest.TestCase):
def setUp(self):
@ -15,47 +12,22 @@ class NewVisitorTest(unittest.TestCase):
# Ig has heard about a cool new online to-do app.
# He goes to check out its homepage
self.browser.get("http://localhost:8000")
# He notices the page title and header mention to-do lists
self.assertIn("To-Do", self.browser.title)
header_text = self.browser.find_element(By.TAG_NAME, "h1").text
self.assertIn("To-Do", header_text)
# He is invited to enter a to-do item straight away
inputbox = self.browser.find_element(By.ID, "id_new_item")
self.assertEqual(inputbox.get_attribute("placeholder"), "Enter a to-do item")
self.fail("Finish the test!")
# He types "Buy peacock feathers" into a text box
# (Ig's hobby is tying fly-fishing lures)
inputbox.send_keys("Buy peacock feathers")
# When he hits enter, the page updates, and now the page lists
# "1: Buy peacock feathers" as an item in a to-do list
inputbox.send_keys(Keys.ENTER)
time.sleep(1)
table = self.browser.find_element(By.ID, "id_list_table")
rows = table.find_elements(By.TAG_NAME, "tr")
self.assertIn("1: Buy peacock feathers", [row.text for row in rows])
# There is still a text box inviting him to add another item.
# He enters "Use peacock feathers to make a fly" (Ig is very methodical)
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 his list
table = self.browser.find_element(By.ID, "id_list_table")
rows = table.find_elements(By.TAG_NAME, "tr")
self.assertIn(
"1: Buy peacock feathers",
[row.text for row in rows],
)
self.assertIn(
"2: Use peacock feather sto make a fly",
[row.text for row in rows],
)
# Satisfied, he goes back to sleep

View File

@ -1,15 +0,0 @@
<html>
<head>
<title>To-Do lists</title>
</head>
<body>
<h1>Your To-Do list</h1>
<form method="POST">
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
{% csrf_token %}
</form>
<table id="id_list_table">
<tr><td>1: {{ new_item_text }}</td></tr>
</table>
</body>
</html>

View File

@ -4,11 +4,8 @@ from lists.views import home_page
# Create your tests here.
class HomePageTest(TestCase):
def test_uses_home_page_template(self):
def test_home_page_returns_correct_html(self):
response = self.client.get("/")
self.assertTemplateUsed(response, "home.html")
def test_can_save_a_POST_request(self):
response = self.client.post("/", data={"item_text": "A new list item"})
self.assertContains(response, "A new list item")
self.assertTemplateUsed(response, "home.html")
self.assertContains(response, "<title>To-Do lists</title>")
self.assertContains(response, "<html>")
self.assertContains(response, "</html>")

View File

@ -3,8 +3,4 @@ from django.http import HttpResponse
# Create your views here.
def home_page(request):
return render(
request,
"home.html",
{"new_item_text": request.POST.get("item_text", "")},
)
return HttpResponse("<html><title>To-Do lists</title></html>")

View File

@ -37,7 +37,6 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'lists',
]
MIDDLEWARE = [