Пример #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())
Пример #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])
Пример #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})
Пример #4
0
    def test_entry_file_import_fileds_entry_content_form_label(self):
        """test form label"""

        # get object
        form = EntryFileImportFields([])
        # compare
        self.assertEqual(form.fields['entry_content'].widget.attrs['class'],
                         'form-select')
Пример #5
0
    def test_entry_file_import_fileds_empty_choices(self):
        """ " test dynamic choices"""

        # get object
        form = EntryFileImportFields([])

        self.assertEqual(form.fields['entry_time'].choices, [(-1, '--')])
        self.assertEqual(form.fields['entry_type'].choices, [(-1, '--')])
        self.assertEqual(form.fields['entry_content'].choices, [(-1, '--')])
Пример #6
0
    def test_entry_file_import_fileds_mock_choices(self):
        """ " test dynamic choices"""

        # get object
        form = EntryFileImportFields(['c_0', 'c_1', 'c_2'])

        # expected choices
        result = [
            (-1, '--'),
            (0, 'c_0'),
            (1, 'c_1'),
            (2, 'c_2'),
        ]

        # check
        self.assertEqual(form.fields['entry_time'].choices, result)
        self.assertEqual(form.fields['entry_type'].choices, result)
        self.assertEqual(form.fields['entry_content'].choices, result)
        self.assertEqual(form.fields['entry_tag'].choices, result)