Is there a standard practice for storing flat data files that are used for testing in a Django project?

Viewed 36

I'm unit testing the way that my Django application loads and processes various flat files and I'm having trouble deciding where to store the files that contain the data for these tests. Is there a standard practice or location for this?

Would it make more sense to store these files in one of the STATICFILES_DIRS or in a subdirectory of MEDIA_ROOT, or some other directory? If some other directory, how might that be configured in the settings module?

For example:

from pathlib import Path 
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase

def simulate_uploaded_file(data_path: Path, filename: str)
    content_type = get_content_type(filename)
    filepath = data_path / filename
    content = open(filepath, 'rb').read()
    data_file = SimpleUploadedFile(data_file_path, content, content_type)

class TestFileHandler(TestCase):
    @classmethod
    def setUpTestData(cls):
        test_data_path: Path = settings.TEST_DATA_DIR # <- IS THERE A STANDARD LOCATION FOR THIS?
        cls.valid_csv: SimpleUploadedFile = simulate_uploaded_data(test_data_path, 'filename.csv')
0 Answers
Related