Example #1
0
    def test_entry_file_import_fileds_form_filled(self):
        """ test filled form """

        # get object
        form = EntryFileImportFields(['c_0', 'c_1', 'c_2'],
                                     data={
                                         'entry_time': 0,
                                         'entry_type': 1,
                                         'entry_content': 2,
                                     })
        # compare
        self.assertTrue(form.is_valid())
Example #2
0
    def test_entry_file_import_fileds_form_error_entry_content(self):
        """ test filled form """

        # get object
        form = EntryFileImportFields(['c_0', 'c_1'],
                                     data={
                                         'entry_time': 0,
                                         'entry_type': 1,
                                         'entry_content': -1,
                                     })
        # compare
        self.assertFalse(form.is_valid())
        self.assertInHTML('Please select an entry content value.',
                          form.errors['__all__'][0])
Example #3
0
def import_csv_step2(request):
    # check if step1 was successful
    if 'entry_csv_import' not in request.session:
        return redirect(reverse('entry_import_step1'))

    # POST request
    if request.method == "POST":
        # get form with dynamic fields
        form = EntryFileImportFields(
            request.session['entry_csv_import']['fields'], request.POST)
        if form.is_valid():
            # get field mappings
            field_mapping = {
                'entry_time': int(form.cleaned_data['entry_time']),
                'entry_type': int(form.cleaned_data['entry_type']),
                'entry_content': int(form.cleaned_data['entry_content']),
                'entry_tag': int(form.cleaned_data['entry_tag']),
            }

            # run async task
            async_task(
                "dfirtrack_main.importer.file.csv_entry_import.csv_entry_import_async",
                request.session['entry_csv_import']['system'],
                request.session['entry_csv_import']['file_name'],
                field_mapping,
                request.user,
                request.session['entry_csv_import']['case'],
            )
            # delete session information
            del (request.session['entry_csv_import'])

            messages.success(request, 'Entry csv importer started')

            return redirect(reverse('entry_list'))
        else:
            return render(request,
                          'dfirtrack_main/entry/entry_import_step2.html',
                          {'form': form})
    else:
        # GET request
        debug_logger(str(request.user), ' ENTRY_CSV_IMPORTER_STEP2_ENTERED')
        # prepare dynamic form with csv field information
        form = EntryFileImportFields(
            request.session['entry_csv_import']['fields'])
        return render(request, 'dfirtrack_main/entry/entry_import_step2.html',
                      {'form': form})