def test_form_renders_item_text_input(self): form = ItemForm()
def test_form_save_handles_saving_to_a_list(self): form = ItemForm(data={'text': 'do me'}) new_item = form.save()
def test_form_validation_for_blank_items(self): form = ItemForm(data='') self.assertFalse(form.is_valid()) self.assertEqual(form.errors['text'], [BLANK_ITEM_ERROR])
def test_fotm_item_input_has_placeholder_and_css_classes(self): """тест: поле ввода имеет атрибут placeholder и css слассы""" form = ItemForm() self.assertIn('placeholder="Enter a to-do item"', form.as_p()) self.assertIn('class="form-control input-lg"', form.as_p())
def test_form_renders_item_text_input(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 test_form_renders_item_input_text(self): form = ItemForm() # self.fail(form.as_p()) # renders the form as HTML. self.assertIn('placeholder="Enter a to-do item"', form.as_p()) self.assertIn('class="form-control input-lg"', form.as_p())
def test_form_validation_for_blank_items(self): form = ItemForm(data={'text': ''}) form.save()
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"', form.as_p())
def test_form_validation_for_duplicate_items(self): list_ = List.objects.create() Item.objects.create(list=list_, text='no twins!') form = ItemForm(for_list=list_, data={'text': 'no twins!'}) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['text'], [self.DUPLICATE_ITEM_ERROR])
def home_page(request): #if request.method == 'POST': # Item.objects.create(text=request.POST['text']) # return redirect('/lists/the-only-list-in-the-world/') # always re-direct a POST request, https://en.wikipedia.org/wiki/Post/Redirect/Get return render(request, 'home.html', {'form': ItemForm()})
def test_form_validation_for_blank_items(self): list_ = List.objects.create() form = ItemForm(for_list=list_, data={'text': ''}) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['text'], [self.EMPTY_ITEM_ERROR])
def test_form_renders_item_text_input(self): list_ = List.objects.create() form = ItemForm(for_list=list_) self.assertIn('placeholder="Enter a to-do item"', form.as_p())
def test_form_validation_for_blank_items(self): form = ItemForm(data={'text': ''}) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['text'], list(ItemForm.Meta.error_messages['text'].values()))
def test_form_renders_item_text_input(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): return render(request, "home.html", {"form": ItemForm()})
def test_form_validation_for_blank_items(self): '''тест валидаци формы для пустых элементов''' form = ItemForm(data={'text': ''}) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['text'], [EMPTY_ITEM_ERROR])
def test_form_validation_for_blank_items(self): form = ItemForm(data={'text': ''}) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['text'], ["You can't have an empty list item"])
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 home_page(request): """домашняя страница""" return render(request, 'home.html', {'form': ItemForm()})
def test_form_validation_for_blank_items(self): form = ItemForm(data={'text': ''}) self.assertFalse(form.is_valid( )) # checks form validation before we try to save any data self.assertEqual(form.errors['text'], [EMPTY_LIST_ERROR])
def test_form_renders_item_text_input(self): form = ItemForm() self.fail(form.as_p())
def home_page(request): return render(request, 'home.html', {'form': ItemForm()})
def test_form_item_input_has_placeholder_and_css_classes(self): form = ItemForm() self.assertIn('placeholder="輸入一個待辦事項"', form.as_p()) self.assertIn('class="form-control input-lg"', form.as_p())