diff --git a/functional_tests.py b/functional_tests.py index f3702400be8f04d11874fe7f7ce96992eedcf8bf..bafd537d9da29657620f7059bb66e7d5746292a4 100644 --- a/functional_tests.py +++ b/functional_tests.py @@ -11,6 +11,11 @@ class NewVisitorTest(unittest.TestCase): def tearDown(self): 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): self.browser.get('http://localhost:8000') @@ -32,17 +37,23 @@ class NewVisitorTest(unittest.TestCase): # 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) + 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( - - 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) + inputbox = self.browser.find_element_by_id('id_new_item') + inputbox.send_keys('Use peacock feathers to make a fly') + inputbox.send_keys(Keys.ENTER) + + # The page updates again, and now shows both items on her list + self.check_for_row_in_list_table('1: Buy peacock feathers') + self.check_for_row_in_list_table('2: Use peacock feathers to make a fly') + + + # 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 + # explanatory text to that effect. self.fail('Finish the test!') #h = self.browser.page_source diff --git a/lists/migrations/0001_initial.py b/lists/migrations/0001_initial.py new file mode 100644 index 0000000000000000000000000000000000000000..ac2a7928f77332d363ef15b5f960a944f69981da --- /dev/null +++ b/lists/migrations/0001_initial.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.5 on 2019-09-25 15:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Item', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ], + ), + ] diff --git a/lists/migrations/0002_item_text.py b/lists/migrations/0002_item_text.py new file mode 100644 index 0000000000000000000000000000000000000000..468321c16e3dc0b33c8b2107183b9da1c36330aa --- /dev/null +++ b/lists/migrations/0002_item_text.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.5 on 2019-09-25 15:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lists', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='item', + name='text', + field=models.TextField(default=''), + ), + ] diff --git a/lists/models.py b/lists/models.py index 71a836239075aa6e6e4ecb700e9c42c95c022d91..59abf095c1c4c75e88f61335ce39f3671c4a8ea8 100644 --- a/lists/models.py +++ b/lists/models.py @@ -1,3 +1,5 @@ from django.db import models # Create your models here. +class Item(models.Model): + text = models.TextField(default='') diff --git a/lists/templates/home.html b/lists/templates/home.html index 5474b018681f18bf147d180d35b6a439c58a84ea..e6b05e363e84153190d5a3d0e16e95326dba5b5b 100644 --- a/lists/templates/home.html +++ b/lists/templates/home.html @@ -4,7 +4,15 @@
{{ forloop.counter }}: {{ item.text }} |