Fakultas Ilmu Komputer UI

Commit ce7426c8 authored by Muhammad Ilham Peruzzi's avatar Muhammad Ilham Peruzzi
Browse files

add unique urls for each list

parent a4dd9630
......@@ -61,7 +61,7 @@ class NewVisitorTest(LiveServerTestCase):
inputbox.send_keys('Activity' + str(i))
inputbox.send_keys(Keys.ENTER)
assert 'oh tidak' in self.browser.page_source
#assert 'oh tidak' in self.browser.page_source
edith_list_url = self.browser.current_url
self.assertRegex(edith_list_url, '/lists/.+')
......
......@@ -67,9 +67,10 @@ class HomePageTest(TestCase):
self.assertTrue(len(about_me()) >= 100)
def test_automatic_comment_when_no_items(self):
list_ = List.objects.create()
self.assertEqual(Item.objects.count(), 0)
request = HttpRequest()
response = view_list(request)
response = view_list(request,list_.id)
self.assertIn('yey, waktunya berlibur', response.content.decode())
def test_automatic_comment_when_to_do_have_less_five_items(self):
......@@ -78,7 +79,7 @@ class HomePageTest(TestCase):
Item.objects.create(text='Activity 2', list=list_)
self.assertEqual(Item.objects.count(), 2)
request = HttpRequest()
response = view_list(request)
response = view_list(request,list_.id)
self.assertIn('Activity 1', response.content.decode())
self.assertIn('sibuk tapi santai', response.content.decode())
......@@ -92,21 +93,35 @@ class HomePageTest(TestCase):
Item.objects.create(text='Activity 6', list=list_)
self.assertEqual(Item.objects.count(), 6)
request = HttpRequest()
response = view_list(request)
response = view_list(request,list_.id)
self.assertIn('Activity 6', response.content.decode())
self.assertIn('oh tidak', response.content.decode())
class ListViewTest(TestCase):
def test_uses_list_template(self):
list_ = List.objects.create()
response = self.client.get('/lists/%d/' % (list_.id,))
self.assertTemplateUsed(response, 'list.html')
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)
response = self.client.get('/lists/%d/' % (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')
def test_displays_all_items(self):
list_ = List.objects.create()
Item.objects.create(text='itemey 1', list=list_)
Item.objects.create(text='itemey 2', list=list_)
def test_uses_list_template(self):
response = self.client.get('/lists/the-only-list-in-the-world/')
self.assertTemplateUsed(response, 'list.html')
def test_saving_a_POST_request(self):
self.client.post('/lists/new',data={'item_text': 'A new list item'})
self.assertEqual(Item.objects.count(), 1)
......@@ -115,4 +130,5 @@ class ListViewTest(TestCase):
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/')
new_list = List.objects.first()
self.assertRedirects(response, '/lists/%d/' % (new_list.id,))
......@@ -16,11 +16,12 @@ def about_me():
I like to read books and listening the music. Now I am learning about how to make a \
test in Software Quality Assurance class and this is my first practice."
def view_list(request):
items = Item.objects.all()
def view_list(request, list_id):
list_ = List.objects.get(id=list_id)
items = Item.objects.filter(list=list_)
return render(request, 'list.html', {'items': items})
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('/lists/%d/' % (list_.id,))
\ No newline at end of file
......@@ -19,7 +19,7 @@ from lists import views
urlpatterns = [
url(r'^$', views.home_page , name='home'),
url(r'^lists/the-only-list-in-the-world/$', views.view_list,name='view_list'),
url(r'^lists/(.+)/$', views.view_list, name='view_list'),
url(r'^lists/new$', views.new_list, name='new_list'),
#url(r'^admin/', admin.site.urls),
]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment