Spaces:
Sleeping
Sleeping
Commit ·
54a2a59
1
Parent(s): e689392
Funtcionnal Test, Model, Views, Templates Intial Editing
Browse files- functional_tests/tests.py +41 -24
- lists/models.py +3 -0
- lists/templates/home.html +1 -0
- lists/templates/list.html +2 -0
- lists/views.py +5 -2
functional_tests/tests.py
CHANGED
|
@@ -31,54 +31,71 @@ class NewVisitorTest(LiveServerTestCase):
|
|
| 31 |
time.sleep(0.5)
|
| 32 |
|
| 33 |
def test_can_start_a_todo_list(self):
|
| 34 |
-
#
|
| 35 |
-
#
|
| 36 |
self.browser.get(self.live_server_url)
|
| 37 |
|
| 38 |
-
#
|
| 39 |
self.assertIn("To-Do", self.browser.title)
|
| 40 |
header_text = self.browser.find_element(By.TAG_NAME, "h1").text
|
| 41 |
self.assertIn("To-Do", header_text)
|
| 42 |
|
| 43 |
-
#
|
| 44 |
inputbox = self.browser.find_element(By.ID, "id_new_item")
|
| 45 |
self.assertEqual(inputbox.get_attribute("placeholder"), "Enter a to-do item")
|
| 46 |
|
| 47 |
-
#
|
| 48 |
-
|
| 49 |
-
inputbox.send_keys("Buy peacock feathers")
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
# "1: Buy peacock feathers" as an item in a to-do list table
|
| 53 |
inputbox.send_keys(Keys.ENTER)
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
inputbox = self.browser.find_element(By.ID, "id_new_item")
|
| 61 |
-
inputbox.send_keys("Use
|
| 62 |
inputbox.send_keys(Keys.ENTER)
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
#
|
| 66 |
-
self.
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
# Satisfied, she goes back to sleep
|
| 70 |
|
| 71 |
def test_multiple_users_can_start_lists_at_different_urls(self):
|
| 72 |
-
#
|
| 73 |
self.browser.get(self.live_server_url)
|
| 74 |
inputbox = self.browser.find_element(By.ID, "id_new_item")
|
| 75 |
-
inputbox.send_keys("Buy
|
| 76 |
inputbox.send_keys(Keys.ENTER)
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
|
| 81 |
-
self.assertRegex(
|
| 82 |
|
| 83 |
# Now a new user, Francis, comes along to the site.
|
| 84 |
|
|
|
|
| 31 |
time.sleep(0.5)
|
| 32 |
|
| 33 |
def test_can_start_a_todo_list(self):
|
| 34 |
+
# Jack has heard about a cool new online to-do app.
|
| 35 |
+
# He goes to check out its homepage
|
| 36 |
self.browser.get(self.live_server_url)
|
| 37 |
|
| 38 |
+
# He notices the page title and header mention to-do lists
|
| 39 |
self.assertIn("To-Do", self.browser.title)
|
| 40 |
header_text = self.browser.find_element(By.TAG_NAME, "h1").text
|
| 41 |
self.assertIn("To-Do", header_text)
|
| 42 |
|
| 43 |
+
# He is invited to enter a to-do item straight away
|
| 44 |
inputbox = self.browser.find_element(By.ID, "id_new_item")
|
| 45 |
self.assertEqual(inputbox.get_attribute("placeholder"), "Enter a to-do item")
|
| 46 |
|
| 47 |
+
# He types "Buy Gearboxes" into a text box
|
| 48 |
+
inputbox.send_keys("Buy Gearboxes")
|
|
|
|
| 49 |
|
| 50 |
+
# Then he hits enter,
|
|
|
|
| 51 |
inputbox.send_keys(Keys.ENTER)
|
| 52 |
+
|
| 53 |
+
# He check for Priority
|
| 54 |
+
prioritybox = self.browser.find_element(By.ID, "id_new_priority")
|
| 55 |
+
self.assertEqual(prioritybox.get_attribute("placeholder"), "Enter a to-do priority")
|
| 56 |
|
| 57 |
+
# He types "High" into a priority's text box
|
| 58 |
+
prioritybox.send_keys("High")
|
| 59 |
|
| 60 |
+
# When he hits enter, the page updates, and now the page lists
|
| 61 |
+
prioritybox.send_keys(Keys.ENTER)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
# There is still a text box inviting him to add another item.
|
| 66 |
+
# He enters "Use Gearboxes to make a Machine"
|
| 67 |
inputbox = self.browser.find_element(By.ID, "id_new_item")
|
| 68 |
+
inputbox.send_keys("Use Gearboxes to make a Machine")
|
| 69 |
inputbox.send_keys(Keys.ENTER)
|
| 70 |
|
| 71 |
+
# There is also a priority box waiting for him to add.
|
| 72 |
+
# He enters "Medium"
|
| 73 |
+
prioritybox = self.browser.find_element(By.ID, "id_new_priority")
|
| 74 |
+
prioritybox.send_keys("Medium")
|
| 75 |
+
prioritybox.send_keys(Keys.ENTER)
|
| 76 |
+
|
| 77 |
+
# The page updates again, and now shows both items on him list
|
| 78 |
+
self.wait_for_row_in_list_table("2: Use Gearboxes to make a Machine")
|
| 79 |
+
self.wait_for_row_in_list_table("1: Buy Gearboxes")
|
| 80 |
|
| 81 |
# Satisfied, she goes back to sleep
|
| 82 |
|
| 83 |
def test_multiple_users_can_start_lists_at_different_urls(self):
|
| 84 |
+
# Jack starts a new to-do list
|
| 85 |
self.browser.get(self.live_server_url)
|
| 86 |
inputbox = self.browser.find_element(By.ID, "id_new_item")
|
| 87 |
+
inputbox.send_keys("Buy Gearboxes")
|
| 88 |
inputbox.send_keys(Keys.ENTER)
|
| 89 |
+
# He check for Priority
|
| 90 |
+
prioritybox = self.browser.find_element(By.ID, "id_new_priority")
|
| 91 |
+
prioritybox.send_keys("High")
|
| 92 |
+
prioritybox.send_keys(Keys.ENTER)
|
| 93 |
+
|
| 94 |
+
self.wait_for_row_in_list_table("1: Buy Gearboxes")
|
| 95 |
|
| 96 |
+
# He notices that his list has a unique URL
|
| 97 |
+
jack_list_url = self.browser.current_url
|
| 98 |
+
self.assertRegex(jack_list_url, "/lists/.+")
|
| 99 |
|
| 100 |
# Now a new user, Francis, comes along to the site.
|
| 101 |
|
lists/models.py
CHANGED
|
@@ -4,6 +4,9 @@ from django.db import models
|
|
| 4 |
class List(models.Model):
|
| 5 |
pass
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
class Item(models.Model):
|
| 9 |
text = models.TextField(default="")
|
|
|
|
| 4 |
class List(models.Model):
|
| 5 |
pass
|
| 6 |
|
| 7 |
+
class Priority(models.Model):
|
| 8 |
+
text = models.TextField(default="")
|
| 9 |
+
list = models.ForeignKey(List, default=None, on_delete=models.CASCADE)
|
| 10 |
|
| 11 |
class Item(models.Model):
|
| 12 |
text = models.TextField(default="")
|
lists/templates/home.html
CHANGED
|
@@ -6,6 +6,7 @@
|
|
| 6 |
<h1>Start a new To-Do list</h1>
|
| 7 |
<form method="POST" action="/lists/new">
|
| 8 |
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
|
|
|
|
| 9 |
{% csrf_token %}
|
| 10 |
</form>
|
| 11 |
</body>
|
|
|
|
| 6 |
<h1>Start a new To-Do list</h1>
|
| 7 |
<form method="POST" action="/lists/new">
|
| 8 |
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
|
| 9 |
+
<input name="priority_text" id="id_new_priority" placeholder="Enter a to-do priority" />
|
| 10 |
{% csrf_token %}
|
| 11 |
</form>
|
| 12 |
</body>
|
lists/templates/list.html
CHANGED
|
@@ -6,6 +6,8 @@
|
|
| 6 |
<h1>Your To-Do list</h1>
|
| 7 |
<form method="POST" action="/lists/{{ list.id }}/add_item">
|
| 8 |
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
|
|
|
|
|
|
|
| 9 |
{% csrf_token %}
|
| 10 |
</form>
|
| 11 |
<table id="id_list_table">
|
|
|
|
| 6 |
<h1>Your To-Do list</h1>
|
| 7 |
<form method="POST" action="/lists/{{ list.id }}/add_item">
|
| 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 |
{% csrf_token %}
|
| 12 |
</form>
|
| 13 |
<table id="id_list_table">
|
lists/views.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from django.shortcuts import redirect, render
|
| 2 |
-
from lists.models import Item, List
|
| 3 |
|
| 4 |
def home_page(request):
|
| 5 |
return render(request, "home.html")
|
|
@@ -11,9 +11,12 @@ def view_list(request, list_id):
|
|
| 11 |
def new_list(request):
|
| 12 |
nulist = List.objects.create()
|
| 13 |
Item.objects.create(text=request.POST["item_text"], list=nulist)
|
|
|
|
| 14 |
return redirect(f"/lists/{nulist.id}/")
|
| 15 |
|
| 16 |
def add_item(request, list_id):
|
| 17 |
our_list = List.objects.get(id=list_id)
|
| 18 |
Item.objects.create(text=request.POST["item_text"], list=our_list)
|
| 19 |
-
|
|
|
|
|
|
|
|
|
| 1 |
from django.shortcuts import redirect, render
|
| 2 |
+
from lists.models import Item, List, Priority
|
| 3 |
|
| 4 |
def home_page(request):
|
| 5 |
return render(request, "home.html")
|
|
|
|
| 11 |
def new_list(request):
|
| 12 |
nulist = List.objects.create()
|
| 13 |
Item.objects.create(text=request.POST["item_text"], list=nulist)
|
| 14 |
+
Priority.objects.create(text=request.POST["priority_text"], list=nulist)
|
| 15 |
return redirect(f"/lists/{nulist.id}/")
|
| 16 |
|
| 17 |
def add_item(request, list_id):
|
| 18 |
our_list = List.objects.get(id=list_id)
|
| 19 |
Item.objects.create(text=request.POST["item_text"], list=our_list)
|
| 20 |
+
Priority.objects.create(text=request.POST["priority_text"], list=our_list)
|
| 21 |
+
return redirect(f"/lists/{our_list.id}/")
|
| 22 |
+
|