Spaces:
Sleeping
Sleeping
Commit ·
7ecf4d9
1
Parent(s): aa068af
Implement new unit_test
Browse files- lists/templates/home.html +3 -1
- lists/templates/list.html +3 -1
- lists/tests.py +15 -5
lists/templates/home.html
CHANGED
|
@@ -8,7 +8,9 @@
|
|
| 8 |
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
|
| 9 |
<b>Priority =</b>
|
| 10 |
<input name="priority_text" id="id_new_priority" placeholder="Enter a to-do priority" />
|
| 11 |
-
<
|
|
|
|
|
|
|
| 12 |
{% csrf_token %}
|
| 13 |
</form>
|
| 14 |
</body>
|
|
|
|
| 8 |
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
|
| 9 |
<b>Priority =</b>
|
| 10 |
<input name="priority_text" id="id_new_priority" placeholder="Enter a to-do priority" />
|
| 11 |
+
<p>
|
| 12 |
+
<input type="submit"value="Summit">
|
| 13 |
+
</p>
|
| 14 |
{% csrf_token %}
|
| 15 |
</form>
|
| 16 |
</body>
|
lists/templates/list.html
CHANGED
|
@@ -8,7 +8,9 @@
|
|
| 8 |
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
|
| 9 |
|
| 10 |
<input name="priority_text" id="id_new_priority" placeholder="Enter a to-do priority" />
|
| 11 |
-
<
|
|
|
|
|
|
|
| 12 |
{% csrf_token %}
|
| 13 |
</form>
|
| 14 |
<table id="id_list_table">
|
|
|
|
| 8 |
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
|
| 9 |
|
| 10 |
<input name="priority_text" id="id_new_priority" placeholder="Enter a to-do priority" />
|
| 11 |
+
<p>
|
| 12 |
+
<input type="submit"value="Summit">
|
| 13 |
+
</p>
|
| 14 |
{% csrf_token %}
|
| 15 |
</form>
|
| 16 |
<table id="id_list_table">
|
lists/tests.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from django.test import TestCase
|
| 2 |
-
from lists.models import Item, List
|
| 3 |
|
| 4 |
class HomePageTest(TestCase):
|
| 5 |
def test_uses_home_template(self):
|
|
@@ -18,7 +18,9 @@ class NewItemTest(TestCase):
|
|
| 18 |
|
| 19 |
self.client.post(
|
| 20 |
f"/lists/{correct_list.id}/add_item",
|
| 21 |
-
data={"item_text": "A new item for an existing list"
|
|
|
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
self.assertEqual(Item.objects.count(), 1)
|
|
@@ -32,20 +34,23 @@ class NewItemTest(TestCase):
|
|
| 32 |
|
| 33 |
response = self.client.post(
|
| 34 |
f"/lists/{correct_list.id}/add_item",
|
| 35 |
-
data={"item_text": "A new item for an existing list"
|
|
|
|
| 36 |
)
|
| 37 |
|
| 38 |
self.assertRedirects(response, f"/lists/{correct_list.id}/")
|
| 39 |
|
| 40 |
class NewListTest(TestCase):
|
| 41 |
def test_can_save_a_POST_request(self):
|
| 42 |
-
self.client.post('/lists/new', data={'item_text': 'A new list item'
|
|
|
|
| 43 |
self.assertEqual(Item.objects.count(), 1)
|
| 44 |
new_item = Item.objects.first()
|
| 45 |
self.assertEqual(new_item.text, 'A new list item')
|
| 46 |
|
| 47 |
def test_redirects_after_POST(self):
|
| 48 |
-
response = self.client.post('/lists/new', data={'item_text': 'A new list item'
|
|
|
|
| 49 |
new_list = List.objects.first()
|
| 50 |
self.assertRedirects(response, f'/lists/{new_list.id}/')
|
| 51 |
|
|
@@ -67,9 +72,14 @@ class ListViewTest(TestCase):
|
|
| 67 |
def test_displays_only_items_for_that_list(self):
|
| 68 |
correct_list = List.objects.create()
|
| 69 |
Item.objects.create(text="itemey 1", list=correct_list)
|
|
|
|
|
|
|
| 70 |
Item.objects.create(text="itemey 2", list=correct_list)
|
|
|
|
|
|
|
| 71 |
other_list = List.objects.create()
|
| 72 |
Item.objects.create(text="other list item", list=other_list)
|
|
|
|
| 73 |
|
| 74 |
response = self.client.get(f"/lists/{correct_list.id}/")
|
| 75 |
|
|
|
|
| 1 |
from django.test import TestCase
|
| 2 |
+
from lists.models import Item, List, Priority
|
| 3 |
|
| 4 |
class HomePageTest(TestCase):
|
| 5 |
def test_uses_home_template(self):
|
|
|
|
| 18 |
|
| 19 |
self.client.post(
|
| 20 |
f"/lists/{correct_list.id}/add_item",
|
| 21 |
+
data={"item_text": "A new item for an existing list",
|
| 22 |
+
"priority_text": "Low"
|
| 23 |
+
},
|
| 24 |
)
|
| 25 |
|
| 26 |
self.assertEqual(Item.objects.count(), 1)
|
|
|
|
| 34 |
|
| 35 |
response = self.client.post(
|
| 36 |
f"/lists/{correct_list.id}/add_item",
|
| 37 |
+
data={"item_text": "A new item for an existing list",
|
| 38 |
+
"priority_text": "Low"},
|
| 39 |
)
|
| 40 |
|
| 41 |
self.assertRedirects(response, f"/lists/{correct_list.id}/")
|
| 42 |
|
| 43 |
class NewListTest(TestCase):
|
| 44 |
def test_can_save_a_POST_request(self):
|
| 45 |
+
self.client.post('/lists/new', data={'item_text': 'A new list item'
|
| 46 |
+
,'priority_text': 'Medium'})
|
| 47 |
self.assertEqual(Item.objects.count(), 1)
|
| 48 |
new_item = Item.objects.first()
|
| 49 |
self.assertEqual(new_item.text, 'A new list item')
|
| 50 |
|
| 51 |
def test_redirects_after_POST(self):
|
| 52 |
+
response = self.client.post('/lists/new', data={'item_text': 'A new list item'
|
| 53 |
+
,'priority_text': 'Medium'})
|
| 54 |
new_list = List.objects.first()
|
| 55 |
self.assertRedirects(response, f'/lists/{new_list.id}/')
|
| 56 |
|
|
|
|
| 72 |
def test_displays_only_items_for_that_list(self):
|
| 73 |
correct_list = List.objects.create()
|
| 74 |
Item.objects.create(text="itemey 1", list=correct_list)
|
| 75 |
+
Priority.objects.create(text="P1", list=correct_list)
|
| 76 |
+
|
| 77 |
Item.objects.create(text="itemey 2", list=correct_list)
|
| 78 |
+
Priority.objects.create(text="P2", list=correct_list)
|
| 79 |
+
|
| 80 |
other_list = List.objects.create()
|
| 81 |
Item.objects.create(text="other list item", list=other_list)
|
| 82 |
+
Priority.objects.create(text="otherP", list=other_list)
|
| 83 |
|
| 84 |
response = self.client.get(f"/lists/{correct_list.id}/")
|
| 85 |
|