diff --git a/functional_tests.py b/functional_tests.py index 80415eb3bbb5d076b998ec61bae5fa0ebf28b887..f3702400be8f04d11874fe7f7ce96992eedcf8bf 100644 --- a/functional_tests.py +++ b/functional_tests.py @@ -1,4 +1,5 @@ from selenium import webdriver +from selenium.webdriver.common.keys import Keys import unittest @@ -8,15 +9,45 @@ class NewVisitorTest(unittest.TestCase): self.browser.implicitly_wait(3) def tearDown(self): - self.browser.close() + self.browser.quit() def test_can_start_a_list_and_retrieve_it_later(self): self.browser.get('http://localhost:8000') - self.assertIn('Rumah', self.browser.title) - h = self.browser.page_source - self.assertIn('Jordan Muhammad Andrianda', h) - self.assertIn('1506722765', h) + # She notices the page title and header mention to-do lists + self.assertIn('To-Do', self.browser.title) + header_text = self.browser.find_element_by_tag_name('h1').text + self.assertIn('To-Do', header_text) + + # She is invited to enter a to-do item straight away + inputbox = self.browser.find_element_by_id('id_new_item') + self.assertEqual( + inputbox.get_attribute('placeholder'), + 'Enter a to-do item' + ) + # She types "Buy peacock feathers" into a text box (Edith's hobby + # is tying fly-fishing lures) + inputbox.send_keys('Buy peacock feathers') + + # When she hits enter, the page updates, and now the page lists + # "1: Buy peacock feathers" as an item in a to-do list table + inputbox.send_keys(Keys.ENTER) + + table = self.browser.find_element_by_id('id_list_table') + rows = table.find_elements_by_tag_name('tr') + self.assertTrue( + + any(row.text == '1: Buy peacock feathers' for row in rows), + "New to-do item did not appear in table" + ) + # 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) + self.fail('Finish the test!') + + #h = self.browser.page_source + #self.assertIn('Jordan Muhammad Andrianda', h) + #self.assertIn('1506722765', h) diff --git a/lists/templates/home.html b/lists/templates/home.html new file mode 100644 index 0000000000000000000000000000000000000000..5474b018681f18bf147d180d35b6a439c58a84ea --- /dev/null +++ b/lists/templates/home.html @@ -0,0 +1,10 @@ + + + To-Do lists + + +

Your To-Do list

+ + + + diff --git a/lists/tests.py b/lists/tests.py index 4a7e493da495ae6ae046c25b338fd5b24674662a..b02f54c9934326334b518e5e35d70ed9c2052797 100644 --- a/lists/tests.py +++ b/lists/tests.py @@ -2,6 +2,7 @@ from django.test import TestCase from django.urls import resolve from django.http import HttpRequest from lists.views import home_page +from django.template.loader import render_to_string # Create your tests here. class HomePageTest(TestCase): @@ -12,11 +13,20 @@ class HomePageTest(TestCase): def test_home_page_returns_correct_html(self): request = HttpRequest() # response = home_page(request) # - self.assertTrue(response.content.startswith(b'')) # - self.assertIn(b'Rumah', response.content) # - self.assertIn(b'

Jordan Muhammad Andrianda

', response.content) # - self.assertIn(b'

1506722765

', response.content) # - self.assertTrue(response.content.endswith(b'')) # + expected_html = render_to_string('home.html') + self.assertEqual(response.content.decode(), expected_html) + + #self.assertTrue(response.content.startswith(b'')) # + + #self.assertTrue(response.content.strip().endswith(b'')) # + #def test_home_page_returns_correct_html(self): + # request = HttpRequest() # + # response = home_page(request) # + # self.assertTrue(response.content.startswith(b'')) # + # self.assertIn(b'Rumah', response.content) # + # self.assertIn(b'

Jordan Muhammad Andrianda

', response.content) # + # self.assertIn(b'

1506722765

', response.content) # + # self.assertTrue(response.content.endswith(b'')) # diff --git a/lists/views.py b/lists/views.py index f7fb6da5ec24fba20c02e6241e432b85c995b8e5..8410f5b25f2e3a777b30098a3f3f69718b6fb11f 100644 --- a/lists/views.py +++ b/lists/views.py @@ -2,4 +2,5 @@ from django.shortcuts import render from django.http import HttpResponse def home_page(request): - return HttpResponse('Rumah

Jordan Muhammad Andrianda

1506722765

') + #return HttpResponse('Rumah

Jordan Muhammad Andrianda

1506722765

') + return render(request,'home.html') diff --git a/superlists/settings.py b/superlists/settings.py index 22e2cbd943341a926f598d7a316dd14ca8a30e81..973d1caca745379f3324ebf0725c72c7964ce8bf 100644 --- a/superlists/settings.py +++ b/superlists/settings.py @@ -37,6 +37,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'lists', ] MIDDLEWARE = [