Skip to content

create_file

Scope: function | Returns: callable

The create_file fixture returns a callable that creates a file in the test file storage and returns the resulting File object.

Signature

create_file(
    lime_application: LimeApplication = lime_app,
    *,
    name: str,
    file_type: FileType = FileType.FIELD_FILE,
    locked: bool = False,
    data: str = "",
    storage_type: str = "sql",
    status: FileStatus | None = None,
    created_by: int | None = None,
    attribute_data: dict[str, str] | None = None,
) -> File

name is required and keyword-only. All other parameters are optional. lime_application defaults to the lime_app fixture.

Basic usage

def test_something(create_file):
    file = create_file(name="report.pdf", data="file contents")

Using a specific application

Pass a different application instance as the first positional argument when the file should be created under a different user context:

def test_something(lime_app_non_admin, create_file):
    file = create_file(lime_app_non_admin, name="report.pdf")

Creating a locked file

def test_something(lime_app, create_file):
    file = create_file(name="report.pdf", locked=True)

Specifying file type and status

from lime_file import FileStatus, FileType

def test_something(create_file):
    file = create_file(
        name="report.pdf",
        file_type=FileType.FIELD_FILE,
        status=FileStatus.SAVED,
    )

Adding attribute data

def test_something(lime_app, create_file):
    file = create_file(
        name="report.pdf",
        attribute_data={"source": "import", "version": "1"},
    )