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

        # get user
        testuser = User.objects.get(
            username='******').id
        # get objects
        analysisstatus_1 = Analysisstatus.objects.get(
            analysisstatus_name='analysisstatus_1').analysisstatus_id
        systemstatus_1 = Systemstatus.objects.get(
            systemstatus_name='systemstatus_1').systemstatus_id
        # get form
        form = SystemImporterFileCsvConfigForm(
            data={
                'csv_column_system': '1',
                'csv_import_path': '/tmp',
                'csv_import_filename': 'systems.csv',
                'csv_import_username': str(testuser),
                'csv_default_systemstatus': str(systemstatus_1),
                'csv_default_analysisstatus': str(analysisstatus_1),
                'csv_default_tagfree_systemstatus': str(systemstatus_1),
                'csv_default_tagfree_analysisstatus': str(analysisstatus_1),
                'csv_tag_lock_systemstatus': 'LOCK_SYSTEMSTATUS',
                'csv_tag_lock_analysisstatus': 'LOCK_ANALYSISSTATUS',
                'csv_remove_tag': 'tag_remove_prefix',
                'csv_field_delimiter': 'field_comma',
                'csv_text_quote': 'text_double_quotation_marks',
                'csv_ip_delimiter': 'ip_semicolon',
                'csv_tag_delimiter': 'tag_space',
            })
        # compare
        self.assertTrue(form.is_valid())
    def test_system_importer_file_csv_config_form_tag_choice_only(self):
        """ test field validation """

        # get user
        testuser = User.objects.get(
            username='******').id
        # get objects
        analysisstatus_1 = Analysisstatus.objects.get(
            analysisstatus_name='analysisstatus_1').analysisstatus_id
        systemstatus_1 = Systemstatus.objects.get(
            systemstatus_name='systemstatus_1').systemstatus_id
        # get form
        form = SystemImporterFileCsvConfigForm(
            data={
                'csv_column_system': '1',
                'csv_import_path': '/tmp',
                'csv_import_filename': 'systems.csv',
                'csv_import_username': str(testuser),
                'csv_default_systemstatus': str(systemstatus_1),
                'csv_default_analysisstatus': str(analysisstatus_1),
                'csv_default_tagfree_systemstatus': str(systemstatus_1),
                'csv_default_tagfree_analysisstatus': str(analysisstatus_1),
                'csv_tag_lock_systemstatus': 'LOCK_SYSTEMSTATUS',
                'csv_tag_lock_analysisstatus': 'LOCK_ANALYSISSTATUS',
                'csv_remove_tag': 'tag_remove_prefix',
                'csv_field_delimiter': 'field_comma',
                'csv_text_quote': 'text_double_quotation_marks',
                'csv_ip_delimiter': 'ip_semicolon',
                'csv_tag_delimiter': 'tag_space',
                'csv_choice_tag': True,
                'csv_column_tag': None,
            })
        # compare
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['csv_choice_tag'], ['Add CSV column.'])
    def test_system_importer_file_csv_config_form_file_no_read_permission(
            self):
        """test field validation"""

        # get user
        testuser = User.objects.get(
            username='******').id
        # get objects
        analysisstatus_1 = Analysisstatus.objects.get(
            analysisstatus_name='analysisstatus_1').analysisstatus_id
        systemstatus_1 = Systemstatus.objects.get(
            systemstatus_name='systemstatus_1').systemstatus_id
        # get timestamp string
        t1 = timezone.now().strftime('%Y%m%d_%H%M%S')
        # build csv file path
        csv_import_path = '/tmp'
        csv_import_filename = f'{t1}_system_importer_file_csv_no_read_permission.csv'
        csv_path = f'{csv_import_path}/{csv_import_filename}'
        # create file
        csv_file = open(csv_path, 'w')
        # close file
        csv_file.close()
        # remove all permissions
        os.chmod(csv_path, 0000)
        # get form
        form = SystemImporterFileCsvConfigForm(
            data={
                'csv_column_system': '1',
                'csv_import_path': csv_import_path,
                'csv_import_filename': csv_import_filename,
                'csv_import_username': str(testuser),
                'csv_default_systemstatus': str(systemstatus_1),
                'csv_default_analysisstatus': str(analysisstatus_1),
                'csv_default_tagfree_systemstatus': str(systemstatus_1),
                'csv_default_tagfree_analysisstatus': str(analysisstatus_1),
                'csv_tag_lock_systemstatus': 'LOCK_SYSTEMSTATUS',
                'csv_tag_lock_analysisstatus': 'LOCK_ANALYSISSTATUS',
                'csv_remove_tag': 'tag_remove_prefix',
                'csv_field_delimiter': 'field_comma',
                'csv_text_quote': 'text_double_quotation_marks',
                'csv_ip_delimiter': 'ip_semicolon',
                'csv_tag_delimiter': 'tag_space',
            })
        # compare
        self.assertFalse(form.is_valid())
        self.assertEqual(
            form.errors['csv_import_filename'],
            ['No read permission for CSV import file.'],
        )
    def test_system_importer_file_csv_config_form_tag_from_db_and_tagfree_analysisstatus(
        self, ):
        """test field validation"""

        # get user
        testuser = User.objects.get(
            username='******').id
        # get objects
        analysisstatus_1 = Analysisstatus.objects.get(
            analysisstatus_name='analysisstatus_1').analysisstatus_id
        tag_1 = Tag.objects.get(tag_name='tag_1').tag_id
        systemstatus_1 = Systemstatus.objects.get(
            systemstatus_name='systemstatus_1').systemstatus_id
        # create object
        analysisstatus_2 = Analysisstatus.objects.create(
            analysisstatus_name='analysisstatus_2').analysisstatus_id
        # get form
        form = SystemImporterFileCsvConfigForm(
            data={
                'csv_column_system': '1',
                'csv_import_path': '/tmp',
                'csv_import_filename': 'systems.csv',
                'csv_import_username': str(testuser),
                'csv_default_systemstatus': str(systemstatus_1),
                'csv_default_analysisstatus': str(analysisstatus_1),
                'csv_choice_tagfree_analysisstatus': True,
                'csv_default_tagfree_systemstatus': str(systemstatus_1),
                'csv_default_tagfree_analysisstatus': str(analysisstatus_2),
                'csv_tag_lock_systemstatus': 'LOCK_SYSTEMSTATUS',
                'csv_tag_lock_analysisstatus': 'LOCK_ANALYSISSTATUS',
                'csv_remove_tag': 'tag_remove_all',
                'csv_field_delimiter': 'field_comma',
                'csv_text_quote': 'text_double_quotation_marks',
                'csv_ip_delimiter': 'ip_semicolon',
                'csv_tag_delimiter': 'tag_space',
                'csv_default_tag': [
                    str(tag_1),
                ],
            })
        # compare
        self.assertFalse(form.is_valid())
        self.assertEqual(
            form.errors['csv_choice_tagfree_analysisstatus'],
            ['Alternative analysisstatus only available with tags from CSV.'],
        )
    def test_system_importer_file_csv_config_form_tag_from_db_prefix_and_prefix_delimiter(
        self, ):
        """test field validation"""

        # get user
        testuser = User.objects.get(
            username='******').id
        # get objects
        analysisstatus_1 = Analysisstatus.objects.get(
            analysisstatus_name='analysisstatus_1').analysisstatus_id
        tag_1 = Tag.objects.get(tag_name='tag_1').tag_id
        systemstatus_1 = Systemstatus.objects.get(
            systemstatus_name='systemstatus_1').systemstatus_id
        # get form
        form = SystemImporterFileCsvConfigForm(
            data={
                'csv_column_system': '1',
                'csv_import_path': '/tmp',
                'csv_import_filename': 'systems.csv',
                'csv_import_username': str(testuser),
                'csv_default_systemstatus': str(systemstatus_1),
                'csv_default_analysisstatus': str(analysisstatus_1),
                'csv_default_tagfree_systemstatus': str(systemstatus_1),
                'csv_default_tagfree_analysisstatus': str(analysisstatus_1),
                'csv_tag_lock_systemstatus': 'LOCK_SYSTEMSTATUS',
                'csv_tag_lock_analysisstatus': 'LOCK_ANALYSISSTATUS',
                'csv_remove_tag': 'tag_remove_all',
                'csv_field_delimiter': 'field_comma',
                'csv_text_quote': 'text_double_quotation_marks',
                'csv_ip_delimiter': 'ip_semicolon',
                'csv_tag_delimiter': 'tag_space',
                'csv_default_tag': [
                    str(tag_1),
                ],
                'csv_tag_prefix': 'AUTO',
                'csv_tag_prefix_delimiter': 'tag_prefix_underscore',
            })
        # compare
        self.assertFalse(form.is_valid())
        self.assertEqual(
            form.errors['csv_tag_prefix'],
            [
                'Prefix and delimiter are not available when setting tags from database.'
            ],
        )
    def test_system_importer_file_csv_config_form_equal_columns(self):
        """ test minimum form requirements / VALID """

        # get user
        testuser = User.objects.get(username='******').id
        # get objects
        analysisstatus_1 = Analysisstatus.objects.get(analysisstatus_name = 'analysisstatus_1').analysisstatus_id
        systemstatus_1 = Systemstatus.objects.get(systemstatus_name = 'systemstatus_1').systemstatus_id
        # create string
        unique_string = 'The column has to be unique.'
        # get form
        form = SystemImporterFileCsvConfigForm(data = {
            'csv_column_system': '1',
            'csv_import_path': '/tmp',
            'csv_import_filename': 'systems.csv',
            'csv_import_username': str(testuser),
            'csv_default_systemstatus': str(systemstatus_1),
            'csv_default_analysisstatus': str(analysisstatus_1),
            'csv_default_tagfree_systemstatus': str(systemstatus_1),
            'csv_default_tagfree_analysisstatus': str(analysisstatus_1),
            'csv_tag_lock_systemstatus': 'LOCK_SYSTEMSTATUS',
            'csv_tag_lock_analysisstatus': 'LOCK_ANALYSISSTATUS',
            'csv_choice_ip': True,
            'csv_column_ip': '1',
            'csv_choice_dnsname': True,
            'csv_column_dnsname': '1',
            'csv_choice_domain': True,
            'csv_column_domain': '1',
            'csv_choice_location': True,
            'csv_column_location': '1',
            'csv_choice_os': True,
            'csv_column_os': '1',
            'csv_choice_reason': True,
            'csv_column_reason': '1',
            'csv_choice_recommendation': True,
            'csv_column_recommendation': '1',
            'csv_choice_serviceprovider': True,
            'csv_column_serviceprovider': '1',
            'csv_choice_systemtype': True,
            'csv_column_systemtype': '1',
            'csv_choice_case': True,
            'csv_column_case': '1',
            'csv_choice_company': True,
            'csv_column_company': '1',
            'csv_choice_tag': True,
            'csv_column_tag': '1',
            'csv_remove_tag': 'tag_remove_prefix',
            'csv_tag_prefix': 'AUTO',
            'csv_tag_prefix_delimiter': 'tag_prefix_underscore',
            'csv_field_delimiter': 'field_comma',
            'csv_text_quote': 'text_double_quotation_marks',
            'csv_ip_delimiter': 'ip_semicolon',
            'csv_tag_delimiter': 'tag_space',
        })
        # compare
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['csv_column_ip'], [unique_string])
        self.assertEqual(form.errors['csv_column_dnsname'], [unique_string])
        self.assertEqual(form.errors['csv_column_domain'], [unique_string])
        self.assertEqual(form.errors['csv_column_location'], [unique_string])
        self.assertEqual(form.errors['csv_column_os'], [unique_string])
        self.assertEqual(form.errors['csv_column_reason'], [unique_string])
        self.assertEqual(form.errors['csv_column_recommendation'], [unique_string])
        self.assertEqual(form.errors['csv_column_serviceprovider'], [unique_string])
        self.assertEqual(form.errors['csv_column_systemtype'], [unique_string])
        self.assertEqual(form.errors['csv_column_case'], [unique_string])
        self.assertEqual(form.errors['csv_column_company'], [unique_string])
        self.assertEqual(form.errors['csv_column_tag'], [unique_string])
    def test_system_importer_file_csv_config_labels(self):
        """test form labels"""

        # get form
        form = SystemImporterFileCsvConfigForm()
        # compare
        self.assertEqual(form.fields['csv_import_username'].label,
                         'Use this user for the import (*)')
        self.assertEqual(form.fields['csv_default_systemstatus'].label,
                         'Set from database (*)')
        self.assertEqual(form.fields['csv_default_analysisstatus'].label,
                         'Set from database (*)')
        self.assertEqual(
            form.fields['csv_default_tagfree_systemstatus'].label,
            'Set from database (no tags assigned)',
        )
        self.assertEqual(
            form.fields['csv_default_tagfree_analysisstatus'].label,
            'Set from database (no tags assigned)',
        )
        self.assertEqual(form.fields['csv_default_dnsname'].label,
                         'Set from database')
        self.assertEqual(form.fields['csv_default_domain'].label,
                         'Set from database')
        self.assertEqual(form.fields['csv_default_location'].label,
                         'Set from database')
        self.assertEqual(form.fields['csv_default_os'].label,
                         'Set from database')
        self.assertEqual(form.fields['csv_default_reason'].label,
                         'Set from database')
        self.assertEqual(form.fields['csv_default_recommendation'].label,
                         'Set from database')
        self.assertEqual(form.fields['csv_default_serviceprovider'].label,
                         'Set from database')
        self.assertEqual(form.fields['csv_default_systemtype'].label,
                         'Set from database')
        self.assertEqual(form.fields['csv_default_case'].label,
                         'Set from database')
        self.assertEqual(form.fields['csv_default_company'].label,
                         'Set from database')
        self.assertEqual(form.fields['csv_default_tag'].label,
                         'Set from database')
        self.assertEqual(form.fields['csv_column_system'].label,
                         'CSV column (*)')
        self.assertEqual(form.fields['csv_skip_existing_system'].label,
                         'Skip existing systems')
        self.assertEqual(form.fields['csv_headline'].label,
                         'CSV file contains a headline row')
        self.assertEqual(form.fields['csv_import_path'].label,
                         'Path to CSV file (*)')
        self.assertEqual(form.fields['csv_import_filename'].label,
                         'File name of CSV file (*)')
        self.assertEqual(
            form.fields['csv_remove_systemstatus'].label,
            'Overwrite for existing systems',
        )
        self.assertEqual(
            form.fields['csv_remove_analysisstatus'].label,
            'Overwrite for existing systems',
        )
        self.assertEqual(
            form.fields['csv_choice_tagfree_systemstatus'].label,
            'Set alternative (no tags assigned)',
        )
        self.assertEqual(
            form.fields['csv_choice_tagfree_analysisstatus'].label,
            'Set alternative (no tags assigned)',
        )
        self.assertEqual(
            form.fields['csv_tag_lock_systemstatus'].label,
            'Tag that preserves systemstatus (*)',
        )
        self.assertEqual(
            form.fields['csv_tag_lock_analysisstatus'].label,
            'Tag that preserves analysisstatus (*)',
        )
        self.assertEqual(form.fields['csv_choice_ip'].label, 'Set from CSV')
        self.assertEqual(form.fields['csv_column_ip'].label, 'CSV column')
        self.assertEqual(form.fields['csv_remove_ip'].label,
                         'Overwrite for existing systems')
        self.assertEqual(form.fields['csv_choice_dnsname'].label,
                         'Set from CSV')
        self.assertEqual(form.fields['csv_column_dnsname'].label, 'CSV column')
        self.assertEqual(form.fields['csv_remove_dnsname'].label,
                         'Overwrite for existing systems')
        self.assertEqual(form.fields['csv_choice_domain'].label,
                         'Set from CSV')
        self.assertEqual(form.fields['csv_column_domain'].label, 'CSV column')
        self.assertEqual(form.fields['csv_remove_domain'].label,
                         'Overwrite for existing systems')
        self.assertEqual(form.fields['csv_choice_location'].label,
                         'Set from CSV')
        self.assertEqual(form.fields['csv_column_location'].label,
                         'CSV column')
        self.assertEqual(form.fields['csv_remove_location'].label,
                         'Overwrite for existing systems')
        self.assertEqual(form.fields['csv_choice_os'].label, 'Set from CSV')
        self.assertEqual(form.fields['csv_column_os'].label, 'CSV column')
        self.assertEqual(form.fields['csv_remove_os'].label,
                         'Overwrite for existing systems')
        self.assertEqual(form.fields['csv_choice_reason'].label,
                         'Set from CSV')
        self.assertEqual(form.fields['csv_column_reason'].label, 'CSV column')
        self.assertEqual(form.fields['csv_remove_reason'].label,
                         'Overwrite for existing systems')
        self.assertEqual(form.fields['csv_choice_recommendation'].label,
                         'Set from CSV')
        self.assertEqual(form.fields['csv_column_recommendation'].label,
                         'CSV column')
        self.assertEqual(
            form.fields['csv_remove_recommendation'].label,
            'Overwrite for existing systems',
        )
        self.assertEqual(form.fields['csv_choice_serviceprovider'].label,
                         'Set from CSV')
        self.assertEqual(form.fields['csv_column_serviceprovider'].label,
                         'CSV column')
        self.assertEqual(
            form.fields['csv_remove_serviceprovider'].label,
            'Overwrite for existing systems',
        )
        self.assertEqual(form.fields['csv_choice_systemtype'].label,
                         'Set from CSV')
        self.assertEqual(form.fields['csv_column_systemtype'].label,
                         'CSV column')
        self.assertEqual(form.fields['csv_remove_systemtype'].label,
                         'Overwrite for existing systems')
        self.assertEqual(form.fields['csv_choice_case'].label, 'Set from CSV')
        self.assertEqual(form.fields['csv_column_case'].label, 'CSV column')
        self.assertEqual(form.fields['csv_remove_case'].label,
                         'Overwrite for existing systems')
        self.assertEqual(form.fields['csv_choice_company'].label,
                         'Set from CSV')
        self.assertEqual(form.fields['csv_column_company'].label, 'CSV column')
        self.assertEqual(form.fields['csv_remove_company'].label,
                         'Overwrite for existing systems')
        self.assertEqual(form.fields['csv_choice_tag'].label, 'Set from CSV')
        self.assertEqual(form.fields['csv_column_tag'].label, 'CSV column')
        self.assertEqual(form.fields['csv_remove_tag'].label,
                         'Overwrite for existing systems')
        self.assertEqual(form.fields['csv_tag_prefix'].label,
                         'Prefix for tags imported via CSV')
        self.assertEqual(
            form.fields['csv_tag_prefix_delimiter'].label,
            'Delimiter to separate prefix from tag',
        )
        self.assertEqual(form.fields['csv_field_delimiter'].label,
                         'CSV field delimiter')
        self.assertEqual(form.fields['csv_text_quote'].label,
                         'CSV text quotation mark')
        self.assertEqual(
            form.fields['csv_ip_delimiter'].label,
            'IP address delimiter (within CSV field)',
        )
        self.assertEqual(form.fields['csv_tag_delimiter'].label,
                         'Tag delimiter (within CSV field)')
コード例 #8
0
def system_importer_file_csv_config_view(request):

    # POST request
    if request.method == "POST":

        # get config model
        model = SystemImporterFileCsvConfigModel.objects.get(
            system_importer_file_csv_config_name='SystemImporterFileCsvConfig')
        # get form
        form = SystemImporterFileCsvConfigForm(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 changed')

            # call logger
            info_logger(str(request.user),
                        " SYSTEM_IMPORTER_FILE_CSV_CONFIG_CHANGED")
            """ check file system """

            # build csv file path
            csv_path = model.csv_import_path + '/' + model.csv_import_filename
            """
            CSV import path does not exist - handled in dfirtrack_config.form
            CSV import path is not readable - handled in dfirtrack_config.form
            CSV import file does exist but is not readable - handled in dfirtrack_config.form
            """

            # CSV import file does not exist - show warning
            if not os.path.isfile(csv_path):
                # create message
                messages.warning(
                    request,
                    'CSV import file does not exist at the moment. Make sure the file is available during import.'
                )
            # CSV import file is empty - show warning
            if os.path.isfile(csv_path):
                if os.path.getsize(csv_path) == 0:
                    # create message
                    messages.warning(
                        request,
                        'CSV import file is empty. Make sure the file contains systems during import.'
                    )

            # show warning if existing systems will be updated
            if not model.csv_skip_existing_system:
                # call message
                messages.warning(request,
                                 'WARNING: Existing systems will be updated!')

            # 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_popup.html',
                {
                    'form': form,
                })

    # GET request
    else:

        # get config model
        model = SystemImporterFileCsvConfigModel.objects.get(
            system_importer_file_csv_config_name='SystemImporterFileCsvConfig')
        # get form
        form = SystemImporterFileCsvConfigForm(instance=model)

    # show form page
    return render(
        request,
        'dfirtrack_config/system/system_importer_file_csv_config_popup.html', {
            'form': form,
        })
    def test_system_importer_file_csv_config_form_remove_skip_systems(self):
        """ test field validation """

        # get user
        testuser = User.objects.get(
            username='******').id
        # get objects
        analysisstatus_1 = Analysisstatus.objects.get(
            analysisstatus_name='analysisstatus_1').analysisstatus_id
        systemstatus_1 = Systemstatus.objects.get(
            systemstatus_name='systemstatus_1').systemstatus_id
        # create string
        either_skip_or_remove_string = 'This choice is only valid if existing systems are not skipped. Either disable this option or disable skipping existing systems.'
        # get form
        form = SystemImporterFileCsvConfigForm(
            data={
                'csv_column_system': '1',
                'csv_skip_existing_system': True,
                'csv_import_path': '/tmp',
                'csv_import_filename': 'systems.csv',
                'csv_import_username': str(testuser),
                'csv_default_systemstatus': str(systemstatus_1),
                'csv_remove_systemstatus': True,
                'csv_default_analysisstatus': str(analysisstatus_1),
                'csv_remove_analysisstatus': True,
                'csv_default_tagfree_systemstatus': str(systemstatus_1),
                'csv_default_tagfree_analysisstatus': str(analysisstatus_1),
                'csv_tag_lock_systemstatus': 'LOCK_SYSTEMSTATUS',
                'csv_tag_lock_analysisstatus': 'LOCK_ANALYSISSTATUS',
                'csv_choice_ip': True,
                'csv_column_ip': '2',
                'csv_remove_ip': True,
                'csv_choice_dnsname': True,
                'csv_column_dnsname': '3',
                'csv_remove_dnsname': True,
                'csv_choice_domain': True,
                'csv_column_domain': '4',
                'csv_remove_domain': True,
                'csv_choice_location': True,
                'csv_column_location': '5',
                'csv_remove_location': True,
                'csv_choice_os': True,
                'csv_column_os': '6',
                'csv_remove_os': True,
                'csv_choice_reason': True,
                'csv_column_reason': '7',
                'csv_remove_reason': True,
                'csv_choice_recommendation': True,
                'csv_column_recommendation': '8',
                'csv_remove_recommendation': True,
                'csv_choice_serviceprovider': True,
                'csv_column_serviceprovider': '9',
                'csv_remove_serviceprovider': True,
                'csv_choice_systemtype': True,
                'csv_column_systemtype': '10',
                'csv_remove_systemtype': True,
                'csv_choice_case': True,
                'csv_column_case': '11',
                'csv_remove_case': True,
                'csv_choice_company': True,
                'csv_column_company': '12',
                'csv_remove_company': True,
                'csv_remove_tag': 'tag_remove_prefix',
                'csv_field_delimiter': 'field_comma',
                'csv_text_quote': 'text_double_quotation_marks',
                'csv_ip_delimiter': 'ip_semicolon',
                'csv_tag_delimiter': 'tag_space',
            })
        # compare
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['csv_remove_systemstatus'],
                         [either_skip_or_remove_string])
        self.assertEqual(form.errors['csv_remove_analysisstatus'],
                         [either_skip_or_remove_string])
        self.assertEqual(form.errors['csv_remove_ip'],
                         [either_skip_or_remove_string])
        self.assertEqual(form.errors['csv_remove_dnsname'],
                         [either_skip_or_remove_string])
        self.assertEqual(form.errors['csv_remove_domain'],
                         [either_skip_or_remove_string])
        self.assertEqual(form.errors['csv_remove_location'],
                         [either_skip_or_remove_string])
        self.assertEqual(form.errors['csv_remove_os'],
                         [either_skip_or_remove_string])
        self.assertEqual(form.errors['csv_remove_reason'],
                         [either_skip_or_remove_string])
        self.assertEqual(form.errors['csv_remove_recommendation'],
                         [either_skip_or_remove_string])
        self.assertEqual(form.errors['csv_remove_serviceprovider'],
                         [either_skip_or_remove_string])
        self.assertEqual(form.errors['csv_remove_systemtype'],
                         [either_skip_or_remove_string])
        self.assertEqual(form.errors['csv_remove_case'],
                         [either_skip_or_remove_string])
        self.assertEqual(form.errors['csv_remove_company'],
                         [either_skip_or_remove_string])
    def test_system_importer_file_csv_config_form_remove_db_valid(self):
        """ test field validation """

        # get user
        testuser = User.objects.get(
            username='******')
        # get objects
        analysisstatus_1 = Analysisstatus.objects.get(
            analysisstatus_name='analysisstatus_1').analysisstatus_id
        systemstatus_1 = Systemstatus.objects.get(
            systemstatus_name='systemstatus_1').systemstatus_id
        # create objects
        case_1 = Case.objects.create(
            case_name='case_1',
            case_is_incident=False,
            case_created_by_user_id=testuser,
        ).case_id
        company_1 = Company.objects.create(company_name='company_1').company_id
        dnsname_1 = Dnsname.objects.create(dnsname_name='dnsname_1').dnsname_id
        domain_1 = Domain.objects.create(domain_name='domain_1').domain_id
        location_1 = Location.objects.create(
            location_name='location_1').location_id
        os_1 = Os.objects.create(os_name='os_1').os_id
        reason_1 = Reason.objects.create(reason_name='reason_1').reason_id
        recommendation_1 = Recommendation.objects.create(
            recommendation_name='recommendation_1').recommendation_id
        serviceprovider_1 = Serviceprovider.objects.create(
            serviceprovider_name='serviceprovider_1').serviceprovider_id
        systemtype_1 = Systemtype.objects.create(
            systemtype_name='systemtype_1').systemtype_id
        # get form
        form = SystemImporterFileCsvConfigForm(
            data={
                'csv_column_system': '1',
                'csv_skip_existing_system': False,
                'csv_import_path': '/tmp',
                'csv_import_filename': 'systems.csv',
                'csv_import_username': str(testuser.id),
                'csv_default_systemstatus': str(systemstatus_1),
                'csv_remove_systemstatus': True,
                'csv_default_analysisstatus': str(analysisstatus_1),
                'csv_remove_analysisstatus': True,
                'csv_default_tagfree_systemstatus': str(systemstatus_1),
                'csv_default_tagfree_analysisstatus': str(analysisstatus_1),
                'csv_tag_lock_systemstatus': 'LOCK_SYSTEMSTATUS',
                'csv_tag_lock_analysisstatus': 'LOCK_ANALYSISSTATUS',
                'csv_default_dnsname': str(dnsname_1),
                'csv_remove_dnsname': True,
                'csv_default_domain': str(domain_1),
                'csv_remove_domain': True,
                'csv_default_location': str(location_1),
                'csv_remove_location': True,
                'csv_default_os': str(os_1),
                'csv_remove_os': True,
                'csv_default_reason': str(reason_1),
                'csv_remove_reason': True,
                'csv_default_recommendation': str(recommendation_1),
                'csv_remove_recommendation': True,
                'csv_default_serviceprovider': str(serviceprovider_1),
                'csv_remove_serviceprovider': True,
                'csv_default_systemtype': str(systemtype_1),
                'csv_remove_systemtype': True,
                'csv_default_case': [str(case_1)],
                'csv_remove_case': True,
                'csv_default_company': [str(company_1)],
                'csv_remove_company': True,
                'csv_remove_tag': 'tag_remove_prefix',
                'csv_field_delimiter': 'field_comma',
                'csv_text_quote': 'text_double_quotation_marks',
                'csv_ip_delimiter': 'ip_semicolon',
                'csv_tag_delimiter': 'tag_space',
            })
        # compare
        self.assertTrue(form.is_valid())