diff --git a/app_homepage/__pycache__/tests.cpython-37.pyc b/app_homepage/__pycache__/tests.cpython-37.pyc index b697218bc8188e54c688ed4d1882d24a1cd74186..4d5fe2af049d9e2d99cc55bcb038334c56159cd3 100644 Binary files a/app_homepage/__pycache__/tests.cpython-37.pyc and b/app_homepage/__pycache__/tests.cpython-37.pyc differ diff --git a/app_homepage/__pycache__/views.cpython-37.pyc b/app_homepage/__pycache__/views.cpython-37.pyc index 97f8d89704adc73e03d6ae56ddb2132615dc18fa..76ff7a27c0e748580a2237424a196a5e59f79a3f 100644 Binary files a/app_homepage/__pycache__/views.cpython-37.pyc and b/app_homepage/__pycache__/views.cpython-37.pyc differ diff --git a/app_homepage/migrations/0004_item_list.py b/app_homepage/migrations/0004_item_list.py index ad00e65f1c53b44aca0c0b915141962a5421b280..db796b19c109fea12d2f1c967b933d2a55ff5760 100644 --- a/app_homepage/migrations/0004_item_list.py +++ b/app_homepage/migrations/0004_item_list.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.1 on 2019-10-10 03:40 +# Generated by Django 2.2.1 on 2019-10-10 04:09 from django.db import migrations, models import django.db.models.deletion diff --git a/app_homepage/migrations/__pycache__/0004_item_list.cpython-37.pyc b/app_homepage/migrations/__pycache__/0004_item_list.cpython-37.pyc index e3b6d39860a2c896a045878d5a8723638fed8e78..4ed41b13cc410769850d31cb6ff9747b5956b307 100644 Binary files a/app_homepage/migrations/__pycache__/0004_item_list.cpython-37.pyc and b/app_homepage/migrations/__pycache__/0004_item_list.cpython-37.pyc differ diff --git a/app_homepage/templates/app/list.html b/app_homepage/templates/app/list.html index 14030bd304a0651d4ca1f56752f478851220cfc9..1b1a290a890592707f4e0d5ae97dacaa051926fc 100644 --- a/app_homepage/templates/app/list.html +++ b/app_homepage/templates/app/list.html @@ -5,7 +5,7 @@ </head> <body> <h1>Your To-Do list</h1> - <form method="POST" action="/lists/new">> + <form method="POST" action="/lists/{{ list.id }}/add_item"> <input name="item_text" id="id_new_item" placeholder="Enter a to-do item" /> {% csrf_token %} </form> diff --git a/app_homepage/tests.py b/app_homepage/tests.py index ecf5428a91aad67a18a9643d1878f05d05583d78..9b56312d0b369ee3920078b603f565e086f349d8 100644 --- a/app_homepage/tests.py +++ b/app_homepage/tests.py @@ -18,9 +18,9 @@ class HomePageTest(TestCase): new_item = Item.objects.first() self.assertEqual(new_item.text, 'A new list item') - def test_redirects_after_POST(self): - response = self.client.post('/lists/new', data={'item_text': 'A new list item'}) - self.assertRedirects(response, '/lists/the-only-list-in-the-world/') + # def test_redirects_after_POST(self): + # response = self.client.post('/lists/new', data={'item_text': 'A new list item'}) + # self.assertRedirects(response, '/lists/the-only-list-in-the-world/') # def test_if_item_smaller_than_5(self): # response = self.client.get('/') @@ -75,19 +75,25 @@ class ListAndItemModelTest(TestCase): class ListViewTest(TestCase): def test_uses_list_template(self): - response = self.client.get('/lists/the-only-list-in-the-world/') + list_ = List.objects.create() + response = self.client.get(f'/lists/{list_.id}/') self.assertTemplateUsed(response, 'app/list.html') - def test_displays_all_items(self): - list_ = List.objects.create() - Item.objects.create(text='itemey 1', list = list_) + def test_displays_only_items_for_that_list(self): + correct_list = List.objects.create() + Item.objects.create(text='itemey 1', list=correct_list) + Item.objects.create(text='itemey 2', list=correct_list) + other_list = List.objects.create() + Item.objects.create(text='other list item 1', list=other_list) + Item.objects.create(text='other list item 2', list=other_list) - Item.objects.create(text='itemey 2', list = list_) - response = self.client.get('/lists/the-only-list-in-the-world/') - self.assertContains(response, 'itemey 1') + response = self.client.get(f'/lists/{correct_list.id}/') + self.assertContains(response, 'itemey 1') self.assertContains(response, 'itemey 2') + self.assertNotContains(response, 'other list item 1') + self.assertNotContains(response, 'other list item 2') class NewListTest(TestCase): @@ -100,6 +106,38 @@ class NewListTest(TestCase): def test_redirects_after_POST(self): response = self.client.post('/lists/new', data={'item_text': 'A new list item'}) - self.assertEqual(response.status_code, 302) - self.assertEqual(response['location'], '/lists/the-only-list-in-the-world/') - self.assertRedirects(response, '/lists/the-only-list-in-the-world/') \ No newline at end of file + new_list = List.objects.first() + self.assertRedirects(response, f'/lists/{new_list.id}/') + +class NewItemTest(TestCase): + def test_can_save_a_POST_request_to_an_existing_list(self): + other_list = List.objects.create() + correct_list = List.objects.create() + + self.client.post( + f'/lists/{correct_list.id}/add_item', + data={'item_text': 'A new item for an existing list'} + ) + + self.assertEqual(Item.objects.count(), 1) + new_item = Item.objects.first() + self.assertEqual(new_item.text, 'A new item for an existing list') + self.assertEqual(new_item.list, correct_list) + + + def test_redirects_to_list_view(self): + other_list = List.objects.create() + correct_list = List.objects.create() + + response = self.client.post( + f'/lists/{correct_list.id}/add_item', + data={'item_text': 'A new item for an existing list'} + ) + + self.assertRedirects(response, f'/lists/{correct_list.id}/') + + def test_passes_correct_list_to_template(self): + other_list = List.objects.create() + correct_list = List.objects.create() + response = self.client.get(f'/lists/{correct_list.id}/') + self.assertEqual(response.context['list'], correct_list) \ No newline at end of file diff --git a/app_homepage/views.py b/app_homepage/views.py index 48700c65d6c61f5811ad009d72622c031c53ae2f..001913718f3cf0be9ead3d8d350fbe0130d984e6 100644 --- a/app_homepage/views.py +++ b/app_homepage/views.py @@ -14,11 +14,17 @@ def home_page(request): # state = "oh tidak" # return render(request, 'app/home.html', {'items':items, 'state':state}) -def view_list(request): - items = Item.objects.all() - return render(request, 'app/list.html', {'items': items}) +def view_list(request, list_id): + list_ = List.objects.get(id=list_id) + items = Item.objects.filter(list=list_) + return render(request, 'app/list.html', {'items': items, 'list':list_}) def new_list(request): list_ = List.objects.create() Item.objects.create(text=request.POST['item_text'], list=list_) - return redirect('/lists/the-only-list-in-the-world/') \ No newline at end of file + return redirect(f'/lists/{list_.id}/') + +def add_item(request, list_id): + list_ = List.objects.get(id=list_id) + Item.objects.create(text=request.POST['item_text'], list=list_) + return redirect(f'/lists/{list_.id}/') \ No newline at end of file diff --git a/functional_tests/__pycache__/tests.cpython-37.pyc b/functional_tests/__pycache__/tests.cpython-37.pyc index ae0aaba1b80fc62affa13bcbe32f59a8bc87a4e1..650151a25090dc6f8da8f083aa2f2b2e25fb95dd 100644 Binary files a/functional_tests/__pycache__/tests.cpython-37.pyc and b/functional_tests/__pycache__/tests.cpython-37.pyc differ diff --git a/functional_tests/tests.py b/functional_tests/tests.py index 8c86c01a1a25cac08ea9a74b3b6ba8a7fd6aeffa..d776e35802a5eb4440fd879e6f553f6e8f9bf9ed 100644 --- a/functional_tests/tests.py +++ b/functional_tests/tests.py @@ -56,8 +56,8 @@ class NewVisitorTest(LiveServerTestCase): time.sleep(5) # The page updates again, and now shows both items on her list - self.wait_for_row_in_list_table('1: Buy peacock feathers') self.wait_for_row_in_list_table('2: Use peacock feathers to make a fly') + self.wait_for_row_in_list_table('1: Buy peacock feathers') # 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 diff --git a/geckodriver.log b/geckodriver.log index 98b186dc3ced85eac9c702bc66aab8a1ea7102c3..f8e578a1a1fd0a3e53065cec5b35fc60e408a185 100644 --- a/geckodriver.log +++ b/geckodriver.log @@ -4831,3 +4831,117 @@ JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't fin 6 ###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv +1570680953447 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\YUMNAP~1\\AppData\\Local\\Temp\\rust_mozprofile2sj63h" +1570680957710 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons +1570680957711 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry +1570680957712 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/ +1570680957712 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader* +JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +1570680965628 Marionette INFO Listening on port 50095 +1570680966067 Marionette WARN TLS certificate errors will be ignored for this session +1570680988651 Marionette INFO Stopped listening on port 50095 +[Parent 6476, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 18492, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 18492,[Child 9576, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 9576, +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +[GPU 4048, Ch +###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv + +1570680996433 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\YUMNAP~1\\AppData\\Local\\Temp\\rust_mozprofileJqCKGB" +1570680998460 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons +1570680998460 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry +1570680998460 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/ +1570680998460 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader* +JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +1570681003834 Marionette INFO Listening on port 50165 +1570681004262 Marionette WARN TLS certificate errors will be ignored for this session +1570681010331 Marionette INFO Stopped listening on port 50165 +[Parent 20284, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 20376, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 20376, Chrome_Chi[Parent 20284, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 11108, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 11108, Chro +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +[GPU 6716, +###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv + +1570681018840 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\YUMNAP~1\\AppData\\Local\\Temp\\rust_mozprofile9HaGDI" +1570681021190 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons +1570681021190 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry +1570681021190 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/ +1570681021190 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader* +JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +1570681025213 Marionette INFO Listening on port 50203 +1570681025676 Marionette WARN TLS certificate errors will be ignored for this session +1570681031904 Marionette INFO Stopped listening on port 50203 +[Child 12128, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 121[Parent 10540, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 + +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +[GPU 1 +###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv + +1570681170438 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\YUMNAP~1\\AppData\\Local\\Temp\\rust_mozprofilejCLcnh" +1570681171681 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons +1570681171682 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry +1570681171682 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/ +1570681171682 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader* +JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +1570681176071 Marionette INFO Listening on port 50254 +1570681176162 Marionette WARN TLS certificate errors will be ignored for this session +1570681197882 Marionette INFO Stopped listening on port 50254 +[Parent 1416, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 10660, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 10660, Chrome_ChildThread] WA[Parent 1416, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 9844, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 9844, +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +[GPU 2296, Ch +###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv + +1570681204347 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\YUMNAP~1\\AppData\\Local\\Temp\\rust_mozprofileoXTyMX" +1570681205488 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons +1570681205488 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry +1570681205488 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/ +1570681205489 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader* +JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +1570681209343 Marionette INFO Listening on port 50289 +1570681209572 Marionette WARN TLS certificate errors will be ignored for this session +1570681215583 Marionette INFO Stopped listening on port 50289 +[Parent 15428, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 14112, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 14112[Parent 15428, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 3184, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 3184, C[Parent 15428, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 16724, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 16724, +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +[GPU 1804, +###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv + +1570681225628 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\YUMNAP~1\\AppData\\Local\\Temp\\rust_mozprofileBZPSx1" +1570681226820 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons +1570681226820 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry +1570681226820 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/ +1570681226820 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader* +JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +1570681231112 Marionette INFO Listening on port 50323 +1570681231356 Marionette WARN TLS certificate errors will be ignored for this session +1570681237366 Marionette INFO Stopped listening on port 50323 +[Child 13752, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 137[Parent 1088, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 5428, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 5428, Ch[Parent 1088, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 8876, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566861941/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341 +[Child 887 +###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost + +[GPU 1674 +###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv + diff --git a/project01_homepage/__pycache__/urls.cpython-37.pyc b/project01_homepage/__pycache__/urls.cpython-37.pyc index dae107b0cb9e64a41b395c1c8cfadfa65bde1d50..7aba03183603740e917f464a7d5effdf2053fb9a 100644 Binary files a/project01_homepage/__pycache__/urls.cpython-37.pyc and b/project01_homepage/__pycache__/urls.cpython-37.pyc differ diff --git a/project01_homepage/urls.py b/project01_homepage/urls.py index 9e7d4f80de75b2087435c95f623a9d85823776d3..2cfaa0e3ad8ba0890567acd7ddffd85bcca24158 100644 --- a/project01_homepage/urls.py +++ b/project01_homepage/urls.py @@ -16,10 +16,11 @@ Including another URLconf from django.contrib import admin from django.urls import path from django.conf.urls import url -from app_homepage import views +from app_homepage import views urlpatterns = [ url(r'^$', views.home_page, name='home'), url(r'^lists/new$', views.new_list, name='new_list'), - url(r'^lists/the-only-list-in-the-world/$', views.view_list, name='view_list'), + url(r'^lists/(\d+)/$', views.view_list, name='view_list'), + url(r'^lists/(\d+)/add_item$', views.add_item, name='add_item'), ] \ No newline at end of file