Compare commits
No commits in common. "ac7a1a70e12c174635e8c0df256a87c7b730069b" and "9bacbfef4cc06e13b015e975003563d943a7998d" have entirely different histories.
ac7a1a70e1
...
9bacbfef4c
|
@ -11,11 +11,6 @@ class NewVisitorTest(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.browser.quit()
|
self.browser.quit()
|
||||||
|
|
||||||
def check_for_row_in_list_table(self, row_text):
|
|
||||||
table = self.browser.find_element_by_id('id_list_table')
|
|
||||||
rows = table.find_elements_by_tag_name('tr')
|
|
||||||
self.assertIn(row_text, [row.text for row in rows])
|
|
||||||
|
|
||||||
def test_can_start_a_list_and_retrieve_it_later(self):
|
def test_can_start_a_list_and_retrieve_it_later(self):
|
||||||
# Edith has heard about a cool new online to-do app. She goes
|
# Edith has heard about a cool new online to-do app. She goes
|
||||||
# to check out its homepage
|
# to check out its homepage
|
||||||
|
@ -41,7 +36,9 @@ class NewVisitorTest(unittest.TestCase):
|
||||||
# "1: Buy peacock feathers" as an item in a to-do list
|
# "1: Buy peacock feathers" as an item in a to-do list
|
||||||
inputbox.send_keys(Keys.ENTER)
|
inputbox.send_keys(Keys.ENTER)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
self.check_for_row_in_list_table('1: Buy peacock feathers')
|
table = self.browser.find_element_by_id('id_list_table')
|
||||||
|
rows = table.find_elements_by_tag_name('tr')
|
||||||
|
# self.assertTrue('1: Buy peacock feathers', [row.text for row in rows])
|
||||||
|
|
||||||
# There is still a text box inviting her to add another item. She
|
# There is still a text box inviting her to add another item. She
|
||||||
# enters "Use peacock feathers to make a fly" (Edith is very methodical)
|
# enters "Use peacock feathers to make a fly" (Edith is very methodical)
|
||||||
|
@ -51,8 +48,14 @@ class NewVisitorTest(unittest.TestCase):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# The page updates again, and now shows both items on her list
|
# The page updates again, and now shows both items on her list
|
||||||
self.check_for_row_in_list_table('1: Buy peacock feathers')
|
table = self.browser.find_element_by_id('id_list_table')
|
||||||
self.check_for_row_in_list_table('2: Use peacock feathers to make a fly')
|
rows = table.find_elements_by_tag_name('tr')
|
||||||
|
print(rows)
|
||||||
|
self.assertIn('1: Buy peacock feathers', [row.text for row in rows])
|
||||||
|
self.assertIn(
|
||||||
|
'2: Use peacock feathers to make a fly',
|
||||||
|
[row.text for row in rows]
|
||||||
|
)
|
||||||
|
|
||||||
# Edith wonders whether the site will remember her list. Then she sees
|
# Edith wonders whether the site will remember her list. Then she sees
|
||||||
# that the site has generated a unique URL for her -- there is some
|
# that the site has generated a unique URL for her -- there is some
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
class Item(models.Model):
|
# Create your models here.
|
||||||
text = models.TextField(default='')
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ from django.urls import resolve
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
|
|
||||||
from lists.views import home_page
|
from lists.views import home_page
|
||||||
from lists.models import Item
|
|
||||||
|
|
||||||
class HomePageTest(TestCase):
|
class HomePageTest(TestCase):
|
||||||
|
|
||||||
|
@ -19,23 +18,4 @@ class HomePageTest(TestCase):
|
||||||
def test_can_save_a_POST_request(self):
|
def test_can_save_a_POST_request(self):
|
||||||
response = self.client.post('/', data={'item_text': 'A new list item'})
|
response = self.client.post('/', data={'item_text': 'A new list item'})
|
||||||
self.assertIn('A new list item', response.content.decode())
|
self.assertIn('A new list item', response.content.decode())
|
||||||
self.assertTemplateUsed(response, 'home.html')
|
self.assertTemplateUsed(response, 'home.html')
|
||||||
|
|
||||||
class ItemModelTest(TestCase):
|
|
||||||
|
|
||||||
def test_saving_and_retrieving_items(self):
|
|
||||||
first_item = Item() # Create an object
|
|
||||||
first_item.text = 'The first (ever) list item' # Assign attributes
|
|
||||||
first_item.save() # Calling .save() function
|
|
||||||
|
|
||||||
second_item = Item()
|
|
||||||
second_item.text = 'Item the second'
|
|
||||||
second_item.save()
|
|
||||||
|
|
||||||
saved_items = Item.objects.all()
|
|
||||||
self.assertEqual(saved_items.count(), 2)
|
|
||||||
|
|
||||||
first_saved_item = saved_items[0]
|
|
||||||
second_saved_item = saved_items[1]
|
|
||||||
self.assertEqual(first_saved_item.text, 'The first (ever) list item')
|
|
||||||
self.assertEqual(second_saved_item.text, 'Item the second')
|
|
Loading…
Reference in New Issue