def test_home_page_can_save_a_POST_request(self): request = HttpRequest() request.method = 'POST' request.POST['itemText'] = '新的項目' homePage(request) self.assertEqual(Item.objects.count(), 1) newItem = Item.objects.first() self.assertEqual(newItem.text, '新的項目')
def test_home_page_redirect_after_POST(self): request = HttpRequest() request.method = 'POST' request.POST['itemText'] = '新的項目' response = homePage(request) self.assertEqual(response.status_code, 302) self.assertEqual(response['location'], '/lists/the-only-list-in-the-world/')
def testHomePageRedirectsAfterPost(self): """test home page redirects after post""" request = HttpRequest() request.method = 'POST' request.POST['item_text'] = NEW_ITEM response = homePage(request) self.assertEqual(response.status_code, 302) self.assertEqual(response['location'], "/lists/only-list")
def testHomePageCanSaveAPostRequest(self): """test home page can save a post request""" request = HttpRequest() request.method = 'POST' request.POST['item_text'] = NEW_ITEM response = homePage(request) self.assertEqual(Item.objects.count(), 1) new_item = Item.objects.first() self.assertEqual(new_item.text, NEW_ITEM)
def test_homePage_only_saves_items_when_necessary(self): request = HttpRequest() homePage(request) self.assertEqual(Item.objects.count(), 0)
def testHomePageOnlySavesItemsWhenNecessary(self): """test home page only saves items when necessary""" request = HttpRequest() homePage(request) self.assertEqual(Item.objects.count(), 0)
def testHomePageReturnsCorrectHtml(self): """test home page returns correct html""" request = HttpRequest() response = homePage(request) expectedHtml = render_to_string('home.html') self.assertEqual(response.content.decode(), expectedHtml)
def test_home_page_returns_correct_html(self): request = HttpRequest() response = homePage(request) expected_html = render_to_string("index.html") self.assertEqual(response.content.decode(), expected_html)