def test_page_returns_correct_html(self): request=HttpRequest() response=pag_inicio(request) expected_html=render_to_string('tdd/pagina_inicio.html') self.assertEqual(response.content.decode(),expected_html)
def test_pagina_inicio_can_redirect_after_a_POST_request(self): request = HttpRequest() request.method = 'POST' request.POST['item_text'] = 'A new list item' response = pag_inicio(request) self.assertEqual(response.status_code,302) self.assertEqual(response['location'],'/tdd/pag_inicio/')
def test_pagina_inicio_displays_all_list_items(self): Item.objects.create(text='itemey 1') Item.objects.create(text='itemey 2') request = HttpRequest() response = pag_inicio(request) self.assertIn('itemey 1',response.content.decode()) self.assertIn('itemey 2',response.content.decode())
def test_pagina_inicio_can_save_a_POST_request(self): request = HttpRequest() request.method = 'POST' request.POST['item_text'] = 'A new list item' response = pag_inicio(request) self.assertEqual(Item.objects.count(),1) new_item=Item.objects.first() self.assertEqual(new_item.text,'A new list item')
def test_pagina_inicio_saves_only_when_needed(self): request=HttpRequest() response=pag_inicio(request) self.assertEqual(Item.objects.count(),0)