def test_system_importer_file_csv_config_based_config_form_empty(self):
        """ test minimum form requirements / INVALID """

        # get object
        form = SystemImporterFileCsvConfigbasedConfigForm(data={
            'csv_column_system': 1,
            'csv_column_ip': 2,
        })
        # compare
        self.assertFalse(form.is_valid())
Exemple #2
0
def system_importer_file_csv_config_based_config_view(request):

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

        # get config model
        model = SystemImporterFileCsvConfigbasedConfigModel.objects.get(
            system_importer_file_csv_configbased_config_name=
            'SystemImporterFileCsvConfigbasedConfig')
        # get form
        form = SystemImporterFileCsvConfigbasedConfigForm(request.POST,
                                                          instance=model)

        if form.is_valid():

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

            # create message
            messages.success(
                request,
                'System importer file CSV config based config changed')

            # call logger
            info_logger(
                str(request.user),
                " SYSTEM_IMPORTER_FILE_CSV_CONFIG_BASED_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_importer_file_csv_config_based_config_popup.html',
                {
                    'form': form,
                })

    else:

        # get config model
        model = SystemImporterFileCsvConfigbasedConfigModel.objects.get(
            system_importer_file_csv_configbased_config_name=
            'SystemImporterFileCsvConfigbasedConfig')
        # get form
        form = SystemImporterFileCsvConfigbasedConfigForm(instance=model)

    # show form page
    return render(
        request,
        'dfirtrack_config/system/system_importer_file_csv_config_based_config_popup.html',
        {
            'form': form,
        })
    def test_system_importer_file_csv_config_based_config_form_analysisstatus_filled(
            self):
        """ test minimum form requirements / INVALID """

        # get object (does not work the usual way because form with available choices is build before model instance is created during the test)
        analysisstatus_id = Analysisstatus.objects.get(
            analysisstatus_name='Needs analysis').analysisstatus_id
        # get object
        form = SystemImporterFileCsvConfigbasedConfigForm(
            data={
                'csv_default_analysisstatus': analysisstatus_id,
                'csv_column_system': 1,
                'csv_column_ip': 2,
            })
        # compare
        self.assertFalse(form.is_valid())
    def test_system_importer_file_csv_config_based_config_csv_default_tag_form_label(
            self):
        """ test form label """

        # get object
        form = SystemImporterFileCsvConfigbasedConfigForm()
        # compare
        self.assertEqual(form.fields['csv_default_tag'].label, 'Set tags')
    def test_system_importer_file_csv_config_based_config_csv_skip_existing_system_form_label(
            self):
        """ test form label """

        # get object
        form = SystemImporterFileCsvConfigbasedConfigForm()
        # compare
        self.assertEqual(form.fields['csv_skip_existing_system'].label,
                         'Skip existing systems')
    def test_system_importer_file_csv_config_based_config_csv_choice_ip_form_label(
            self):
        """ test form label """

        # get object
        form = SystemImporterFileCsvConfigbasedConfigForm()
        # compare
        self.assertEqual(form.fields['csv_choice_ip'].label,
                         'CSV file contains IP addresses')
    def test_system_importer_file_csv_config_based_config_csv_headline_form_label(
            self):
        """ test form label """

        # get object
        form = SystemImporterFileCsvConfigbasedConfigForm()
        # compare
        self.assertEqual(form.fields['csv_headline'].label,
                         'CSV file contains a headline row')
    def test_system_importer_file_csv_config_based_config_csv_remove_tag_form_label(
            self):
        """ test form label """

        # get object
        form = SystemImporterFileCsvConfigbasedConfigForm()
        # compare
        self.assertEqual(
            form.fields['csv_remove_tag'].label,
            'Remove / overwrite existing tags for already existing systems')
    def test_system_importer_file_csv_config_based_config_csv_column_ip_form_label(
            self):
        """ test form label """

        # get object
        form = SystemImporterFileCsvConfigbasedConfigForm()
        # compare
        self.assertEqual(
            form.fields['csv_column_ip'].label,
            'Number of the column in the CSV file that contains the IP addresses'
        )
    def test_system_importer_file_csv_config_based_config_form_same_columns(
            self):
        """ test field validation / INVALID """

        # get object (does not work the usual way because form with available choices is build before model instance is created during the test)
        systemstatus_id = Systemstatus.objects.get(
            systemstatus_name='systemstatus_1').systemstatus_id
        # get object (does not work the usual way because form with available choices is build before model instance is created during the test)
        analysisstatus_id = Analysisstatus.objects.get(
            analysisstatus_name='analysisstatus_1').analysisstatus_id
        # get object
        form = SystemImporterFileCsvConfigbasedConfigForm(
            data={
                'csv_default_systemstatus': systemstatus_id,
                'csv_default_analysisstatus': analysisstatus_id,
                'csv_column_system': 1,
                'csv_column_ip': 1,
            })
        # compare
        self.assertFalse(form.is_valid())