forked from langgenius/dify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(file_upload): correct validation method and add unit tests (langg…
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
api/tests/unit_tests/core/app/app_config/features/file_upload/test_manager.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from core.app.app_config.features.file_upload.manager import FileUploadConfigManager | ||
from core.file.models import FileTransferMethod, FileUploadConfig, ImageConfig | ||
from core.model_runtime.entities.message_entities import ImagePromptMessageContent | ||
|
||
|
||
def test_convert_with_vision(): | ||
config = { | ||
"file_upload": { | ||
"enabled": True, | ||
"number_limits": 5, | ||
"allowed_file_upload_methods": [FileTransferMethod.REMOTE_URL], | ||
"image": {"detail": "high"}, | ||
} | ||
} | ||
result = FileUploadConfigManager.convert(config, is_vision=True) | ||
expected = FileUploadConfig( | ||
image_config=ImageConfig( | ||
number_limits=5, | ||
transfer_methods=[FileTransferMethod.REMOTE_URL], | ||
detail=ImagePromptMessageContent.DETAIL.HIGH, | ||
) | ||
) | ||
assert result == expected | ||
|
||
|
||
def test_convert_without_vision(): | ||
config = { | ||
"file_upload": { | ||
"enabled": True, | ||
"number_limits": 5, | ||
"allowed_file_upload_methods": [FileTransferMethod.REMOTE_URL], | ||
} | ||
} | ||
result = FileUploadConfigManager.convert(config, is_vision=False) | ||
expected = FileUploadConfig( | ||
image_config=ImageConfig(number_limits=5, transfer_methods=[FileTransferMethod.REMOTE_URL]) | ||
) | ||
assert result == expected | ||
|
||
|
||
def test_validate_and_set_defaults(): | ||
config = {} | ||
result, keys = FileUploadConfigManager.validate_and_set_defaults(config) | ||
assert "file_upload" in result | ||
assert keys == ["file_upload"] | ||
|
||
|
||
def test_validate_and_set_defaults_with_existing_config(): | ||
config = { | ||
"file_upload": { | ||
"enabled": True, | ||
"number_limits": 5, | ||
"allowed_file_upload_methods": [FileTransferMethod.REMOTE_URL], | ||
} | ||
} | ||
result, keys = FileUploadConfigManager.validate_and_set_defaults(config) | ||
assert "file_upload" in result | ||
assert keys == ["file_upload"] | ||
assert result["file_upload"]["enabled"] is True | ||
assert result["file_upload"]["number_limits"] == 5 | ||
assert result["file_upload"]["allowed_file_upload_methods"] == [FileTransferMethod.REMOTE_URL] |