Exemplo n.º 1
0
 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, '新的項目')
Exemplo n.º 2
0
 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/')
Exemplo n.º 3
0
    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")
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
 def test_homePage_only_saves_items_when_necessary(self):
     request = HttpRequest()
     homePage(request)
     self.assertEqual(Item.objects.count(), 0)
Exemplo n.º 6
0
 def testHomePageOnlySavesItemsWhenNecessary(self):
     """test home page only saves items when necessary"""
     request = HttpRequest()
     homePage(request)
     self.assertEqual(Item.objects.count(), 0)
Exemplo n.º 7
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)
Exemplo n.º 8
0
 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)