示例#1
0
    def test_reason_name_too_many_chars(self):
        """ test for max length """

        # get object
        form = ReasonForm(data = {'reason_name': 'rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr'})
        # compare
        self.assertFalse(form.is_valid())
示例#2
0
    def test_reason_name_form_filled(self):
        """ test minimum form requirements / VALID """

        # get object
        form = ReasonForm(data = {'reason_name': 'reason_1'})
        # compare
        self.assertTrue(form.is_valid())
示例#3
0
    def test_reason_form_empty(self):
        """ test minimum form requirements / INVALID """

        # get object
        form = ReasonForm(data = {})
        # compare
        self.assertFalse(form.is_valid())
示例#4
0
    def test_reason_name_proper_chars(self):
        """test for max length"""

        # get object
        form = ReasonForm(data={'reason_name': 'r' * 30})
        # compare
        self.assertTrue(form.is_valid())
示例#5
0
    def test_reason_note_form_filled(self):
        """ test additional form content """

        # get object
        form = ReasonForm(data = {
            'reason_name': 'reason_1',
            'reason_note': 'lorem ipsum',
        })
        # compare
        self.assertTrue(form.is_valid())
示例#6
0
    def test_reason_name_form_label(self):
        """ test form label """

        # get object
        form = ReasonForm()
        # compare
        self.assertEqual(form.fields['reason_name'].label, 'Reason name (*)')
示例#7
0
def reasons_add(request):
    if request.method == 'POST':
        form = ReasonForm(request.POST)
        if form.is_valid():
            reason = form.save(commit=False)
            reason.save()
            reason.logger(str(request.user), " REASON_ADD_EXECUTED")
            messages.success(request, 'Reason added')
            return redirect('/reasons')
    else:
        form = ReasonForm()
        debug_logger(str(request.user), " REASON_ADD_ENTERED")
    return render(request, 'dfirtrack_main/reason/reasons_add.html',
                  {'form': form})
示例#8
0
def reasons_edit(request, pk):
    reason = get_object_or_404(Reason, pk=pk)
    if request.method == 'POST':
        form = ReasonForm(request.POST, instance=reason)
        if form.is_valid():
            reason = form.save(commit=False)
            reason.save()
            reason.logger(str(request.user), " REASON_EDIT_EXECUTED")
            messages.success(request, 'Reason edited')
            return redirect('/reasons')
    else:
        form = ReasonForm(instance=reason)
        reason.logger(str(request.user), " REASON_EDIT_ENTERED")
    return render(request, 'dfirtrack_main/reason/reasons_edit.html',
                  {'form': form})
示例#9
0
def reasons_add_popup(request):
    if request.method == 'POST':
        form = ReasonForm(request.POST)
        if form.is_valid():
            reason = form.save(commit=False)
            reason.save()
            reason.logger(str(request.user), " REASON_ADD_POPUP_EXECUTED")
            messages.success(request, 'Reason added')
            return HttpResponse(
                '<script type="text/javascript">window.close();</script>')
    else:
        form = ReasonForm()
        debug_logger(str(request.user), " REASON_ADD_POPUP_ENTERED")
    return render(request, 'dfirtrack_main/reason/reasons_add_popup.html',
                  {'form': form})