示例#1
0
    def test_home_displays_all_list_items(self):
        Item.objects.create(text='itemey 1')
        Item.objects.create(text='itemey 2')

        request = HttpRequest()
        response = home(request)

        self.assertIn('itemey 1', response.content.decode())
        self.assertIn('itemey 2', response.content.decode())
示例#2
0
    def test_home_can_save_post_data(self):
        res = HttpRequest()
        res.method = "POST"
        res.POST['new a item'] = "a new list item"

        resp = home(res)
        #print(resp.content.decode())

        self.assertEqual(Item.objects.count(), 1)
        new_item = Item.objects.first()
        self.assertEqual(new_item.text, 'a new list item')

        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp['location'], '/apptdd/the-only-list-in-world/')
示例#3
0
 def test_home_only_saves_items_when_nessary(self):
     request = HttpRequest()
     response = home(request)
     self.assertEqual(Item.objects.count(), 0)
示例#4
0
 def test_renderTOstring(self):
     req = HttpRequest()
     resp = home(req)
     expected_html = render_to_string('home.html')
     self.assertEqual(expected_html, resp.content.decode())
示例#5
0
 def test_homepage_response(self):
     req = HttpRequest()
     resp = home(req)
     self.assertTrue(resp.content.startswith(b'<html>'))
     self.assertIn('To-Do', resp.content.decode())
     self.assertTrue(resp.content.endswith(b'</html>'))