mardi 5 décembre 2017

How do you handle files in a django test

I have a model that has a file field and I've been more or less testing the model like so:

def test_importing_file_and_processing(self):
    file_path = os.path.join(settings.BASE_DIR,
                             'myapp/tests/reports/test_input_file')
    report = IngestedFile(
        filename='test_file'
    )
    report.document.save('test_file', File(open(file_path)))
    report.save()
    report.do_stuff()
    self.assertStuf....

Is there a "better" way to test the file? The way I'm testing things does look a little hacky.

Aucun commentaire:

Enregistrer un commentaire