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_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())
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_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())