created apps/dashboard/list.html template (for now, mirrors home.html); changes ListViewTest() to DashViewTest() in apps.dashboard.tests; added new list template test to same; updated view_list() FBV in .views to accomodate this new template
This commit is contained in:
@@ -44,7 +44,11 @@ class ItemModelTest(TestCase):
|
||||
self.assertEqual(first_saved_item.text, "The first (ever) list item")
|
||||
self.assertEqual(second_saved_item.text, "A sequel somehow better than the first")
|
||||
|
||||
class ListViewTest(TestCase):
|
||||
class DashViewTest(TestCase):
|
||||
def test_uses_list_template(self):
|
||||
response = self.client.get('/apps/dashboard/the-only-list-in-the-world/')
|
||||
self.assertTemplateUsed(response, 'apps/dashboard/list.html')
|
||||
|
||||
def test_renders_input_form(self):
|
||||
response = self.client.get('/apps/dashboard/the-only-list-in-the-world/')
|
||||
self.assertContains(response, '<form method="POST"')
|
||||
|
||||
@@ -11,4 +11,4 @@ def home_page(request):
|
||||
|
||||
def view_list(request):
|
||||
items = Item.objects.all()
|
||||
return render(request, 'apps/dashboard/home.html', {'items': items})
|
||||
return render(request, 'apps/dashboard/list.html', {'items': items})
|
||||
17
templates/apps/dashboard/list.html
Normal file
17
templates/apps/dashboard/list.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>To-Do lists</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Your To-Do List</h1>
|
||||
<form method="POST" action="/">
|
||||
<input name="item_text" id="id-new-item" placeholder="Enter a to-do item">
|
||||
{% csrf_token %}
|
||||
</form>
|
||||
<table id="id-list-table">
|
||||
{% for item in items %}
|
||||
<tr><td>{{ forloop.counter }}. {{ item.text }}</td></tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user