How to validate document(pdf) in the InlineFormSetFactory for the test case in Django

Viewed 131

forms.py

class TestDocumentInline(InlineFormSetFactory):

    model = TestDocument
    fields = ['document_test_type', 'test_notes', 'test_document']
    factory_kwargs = {'extra': 1, 'can_delete': True}

test_forms.py

@pytest.mark.django_db
class DocumentInlineTest(TestCase):

    def test_valid_testdocument(self):
        test_inline = TestDocumentInline(request=self.factory,
                                                          instance=self.test,
                                                          parent_model=Test)
        test_formset = test_inline.get_formset()
        formset = test_formset({
            'form-TOTAL_FORMS': '1',
            'form-INITIAL_FORMS': '0',
            'form-MAX_NUM_FORMS': '2',
            'form-0-document_test_type': "Test",
            'form-0-test_notes': "test_notes",
            'form-0-test_document': "dir/testDoc.pdf",
        }, prefix="form")
        self.assertTrue(formset.is_valid())

How to validate document(pdf) in the InlineFormSetFactory for the test case in Django

Currently, testcase getting falied in 'form-0-test_document': "dir/testDoc.pdf",

0 Answers
Related