Modified home page template. Added more FT and UT
This commit is contained in:
parent
ceb22cdf90
commit
5cedbfe9ce
@ -36,16 +36,26 @@ class NewVisitorTest(unittest.TestCase):
|
||||
|
||||
table = self.browser.find_element(By.ID, "id_list_table")
|
||||
rows = table.find_elements(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.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)
|
||||
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 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
|
||||
|
||||
|
@ -4,9 +4,12 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Your To-Do list</h1>
|
||||
<input id="id_new_item" placeholder="Enter a to-do item" />
|
||||
<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>
|
@ -6,4 +6,9 @@ from lists.views import home_page
|
||||
class HomePageTest(TestCase):
|
||||
def test_uses_home_page_template(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")
|
@ -1,5 +1,10 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
|
||||
# Create your views here.
|
||||
def home_page(request):
|
||||
return render(request, "home.html")
|
||||
return render(
|
||||
request,
|
||||
"home.html",
|
||||
{"new_item_text": request.POST.get("item_text", "")},
|
||||
)
|
Loading…
Reference in New Issue
Block a user