VelogaWhite commited on
Commit
54a2a59
·
1 Parent(s): e689392

Funtcionnal Test, Model, Views, Templates Intial Editing

Browse files
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
- # Edith has heard about a cool new online to-do app.
35
- # She goes to check out its homepage
36
  self.browser.get(self.live_server_url)
37
 
38
- # She 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
- # She 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
- # She types "Buy peacock feathers" into a text box
48
- # (Edith's hobby is tying fly-fishing lures)
49
- inputbox.send_keys("Buy peacock feathers")
50
 
51
- # When she hits enter, the page updates, and now the page lists
52
- # "1: Buy peacock feathers" as an item in a to-do list table
53
  inputbox.send_keys(Keys.ENTER)
54
- self.wait_for_row_in_list_table("1: Buy peacock feathers")
 
 
 
55
 
 
 
56
 
57
- # There is still a text box inviting her to add another item.
58
- # She enters "Use peacock feathers to make a fly"
59
- # (Edith is very methodical)
 
 
 
 
60
  inputbox = self.browser.find_element(By.ID, "id_new_item")
61
- inputbox.send_keys("Use peacock feathers to make a fly")
62
  inputbox.send_keys(Keys.ENTER)
63
 
64
- # The page updates again, and now shows both items on her list
65
- # HERE IS THE CHANGE: We use the helper method twice
66
- self.wait_for_row_in_list_table("2: Use peacock feathers to make a fly")
67
- self.wait_for_row_in_list_table("1: Buy peacock feathers")
 
 
 
 
 
68
 
69
  # Satisfied, she goes back to sleep
70
 
71
  def test_multiple_users_can_start_lists_at_different_urls(self):
72
- # Edith starts a new to-do list
73
  self.browser.get(self.live_server_url)
74
  inputbox = self.browser.find_element(By.ID, "id_new_item")
75
- inputbox.send_keys("Buy peacock feathers")
76
  inputbox.send_keys(Keys.ENTER)
77
- self.wait_for_row_in_list_table("1: Buy peacock feathers")
 
 
 
 
 
78
 
79
- # She notices that her list has a unique URL
80
- edith_list_url = self.browser.current_url
81
- self.assertRegex(edith_list_url, "/lists/.+")
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
- return redirect(f"/lists/{our_list.id}/")
 
 
 
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
+