def test_headline_name_too_many_chars(self): """ test for max length """ # get object form = HeadlineForm(data = {'headline_name': 'hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh'}) # compare self.assertFalse(form.is_valid())
def test_headline_name_form_filled(self): """ test minimum form requirements / VALID """ # get object form = HeadlineForm(data = {'headline_name': 'headline_1'}) # compare self.assertTrue(form.is_valid())
def test_headline_form_empty(self): """ test minimum form requirements / INVALID """ # get object form = HeadlineForm(data = {}) # compare self.assertFalse(form.is_valid())
def test_headline_name_proper_chars(self): """test for max length""" # get object form = HeadlineForm(data={'headline_name': 'h' * 100}) # compare self.assertTrue(form.is_valid())
def headlines_add(request): if request.method == 'POST': form = HeadlineForm(request.POST) if form.is_valid(): headline = form.save(commit=False) headline.save() headline.logger(str(request.user), " HEADLINE_ADD_EXECUTED") messages.success(request, 'Headline added') return redirect('/headlines') else: form = HeadlineForm() debug_logger(str(request.user), " HEADLINE_ADD_ENTERED") return render(request, 'dfirtrack_main/headline/headlines_add.html', {'form': form})
def headlines_edit(request, pk): headline = get_object_or_404(Headline, pk=pk) if request.method == 'POST': form = HeadlineForm(request.POST, instance=headline) if form.is_valid(): headline = form.save(commit=False) headline.save() headline.logger(str(request.user), " HEADLINE_EDIT_EXECUTED") messages.success(request, 'Headline edited') return redirect('/headlines') else: form = HeadlineForm(instance=headline) headline.logger(str(request.user), " HEADLINE_EDIT_ENTERED") return render(request, 'dfirtrack_main/headline/headlines_edit.html', {'form': form})