def test_form_save_handles_saving_to_a_list(self): list_ = List.objects.create() form = ItemForm(data={"text": "do me"}) new_item = form.save(for_list=list_) self.assertEqual(new_item, Item.objects.first()) self.assertEqual(new_item.text, "do me") self.assertEqual(new_item.list, list_)
def new_list(request): form = ItemForm(data=request.POST) if form.is_valid(): list_ = List.objects.create() form.save(for_list=list_) return redirect(list_) else: return render_to_response('index.html', locals(), context_instance=RequestContext(request))
def test_form_validation_for_blank_items(self): form = ItemForm(data={"text": ""}) self.assertFalse(form.is_valid()) self.assertEqual(form.errors["text"], [EMPTY_LIST_ERROR])
def test_form_item_input_has_placeholder_and_css_classes(self): form = ItemForm() self.assertIn('placeholder="Enter a to-do item"', form.as_p()) self.assertIn('class="form-control input-lg', form.as_p())
def home_page(request): form = ItemForm() return render_to_response('index.html', locals(), context_instance=RequestContext(request))