def test_system_exporter_spreadsheet_csv_config_form_empty(self):
        """ test minimum form requirements / VALID """

        # get object
        form = SystemExporterSpreadsheetCsvConfigForm(data={})
        # compare
        self.assertTrue(form.is_valid())
Ejemplo n.º 2
0
    def test_system_exporter_spreadsheet_csv_config_spread_csv_os_form_label(self):
        """test form label"""

        # get object
        form = SystemExporterSpreadsheetCsvConfigForm()
        # compare
        self.assertEqual(form.fields['spread_csv_os'].label, 'Export OS')
Ejemplo n.º 3
0
    def test_system_exporter_spreadsheet_csv_config_spread_csv_system_modify_time_form_label(
        self,
    ):
        """test form label"""

        # get object
        form = SystemExporterSpreadsheetCsvConfigForm()
        # compare
        self.assertEqual(
            form.fields['spread_csv_system_modify_time'].label,
            'Export system modify time',
        )
def system_exporter_spreadsheet_csv_config_view(request):

    # form was valid to post
    if request.method == "POST":

        # get config model
        model = SystemExporterSpreadsheetCsvConfigModel.objects.get(
            system_exporter_spreadsheet_csv_config_name=
            'SystemExporterSpreadsheetCsvConfig')
        # get form
        form = SystemExporterSpreadsheetCsvConfigForm(request.POST,
                                                      instance=model)

        if form.is_valid():

            # save settings
            model = form.save(commit=False)
            model.save()

            # create message
            messages.success(request,
                             'System exporter spreadsheet CSV config changed')

            # call logger
            info_logger(str(request.user),
                        " SYSTEM_EXPORTER_SPREADSHEET_CSV_CONFIG_CHANGED")

            # close popup
            return HttpResponse(
                '<script type="text/javascript">window.close();</script>')

        # TODO: with only non-mandatory model attributes, it is not possible to get an invalid form
        # TODO: finish prepared tests in 'dfirtrack_config.tests.system.test_system_exporter_spreadsheet_csv_config_views'
        # TODO: remove the coverage limitation with further mandatory model attributes
        else:  # coverage: ignore branch
            # show form page again
            return render(
                request,
                'dfirtrack_config/system/system_exporter_spreadsheet_csv_config_popup.html',
                {
                    'form': form,
                })

    else:

        # get config model
        model = SystemExporterSpreadsheetCsvConfigModel.objects.get(
            system_exporter_spreadsheet_csv_config_name=
            'SystemExporterSpreadsheetCsvConfig')
        # get form
        form = SystemExporterSpreadsheetCsvConfigForm(instance=model)

    # show form page
    return render(
        request,
        'dfirtrack_config/system/system_exporter_spreadsheet_csv_config_popup.html',
        {
            'form': form,
        })
Ejemplo n.º 5
0
def system_exporter_spreadsheet_csv_config_view(request):

    # form was valid to post
    if request.method == "POST":

        # get config model
        model = SystemExporterSpreadsheetCsvConfigModel.objects.get(
            system_exporter_spreadsheet_csv_config_name=
            'SystemExporterSpreadsheetCsvConfig')
        # get form
        form = SystemExporterSpreadsheetCsvConfigForm(request.POST,
                                                      instance=model)

        if form.is_valid():

            # save settings
            model = form.save(commit=False)
            model.save()

            # call logger
            info_logger(str(request.user),
                        " SYSTEM_EXPORTER_SPREADSHEET_CSV_CONFIG_CHANGED")

            # close popup
            return HttpResponse(
                '<script type="text/javascript">window.close();</script>')

        else:
            # show form page again
            return render(
                request,
                'dfirtrack_config/system/system_exporter_spreadsheet_csv_config_popup.html',
                {
                    'form': form,
                })

    else:

        # get config model
        model = SystemExporterSpreadsheetCsvConfigModel.objects.get(
            system_exporter_spreadsheet_csv_config_name=
            'SystemExporterSpreadsheetCsvConfig')
        # get form
        form = SystemExporterSpreadsheetCsvConfigForm(instance=model)

    # show form page
    return render(
        request,
        'dfirtrack_config/system/system_exporter_spreadsheet_csv_config_popup.html',
        {
            'form': form,
        })