Skip to content

Commit

Permalink
rewrite test for create_model_path
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 22, 2024
1 parent 6fbceea commit 0df1e73
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tests-unit/prompt_server_test/download_models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,21 @@ async def test_download_model_invalid_folder_path():
assert result.status == 'error'
assert result.already_existed is False

# For create_model_path function
def test_create_model_path(tmp_path, monkeypatch):
mock_models_dir = tmp_path / "models"
monkeypatch.setattr('folder_paths.models_dir', str(mock_models_dir))
model_name = "model.safetensors"
folder_path = os.path.join(tmp_path, "mock_dir")

model_name = "test_model.sft"
model_directory = "test_dir"
file_path = create_model_path(model_name, folder_path)

file_path = create_model_path(model_name, model_directory, mock_models_dir)

assert file_path == str(mock_models_dir / model_directory / model_name)
assert file_path == os.path.join(folder_path, "model.safetensors")
assert os.path.exists(os.path.dirname(file_path))

with pytest.raises(Exception, match="Invalid model directory"):
create_model_path("../path_traversal.safetensors", folder_path)

with pytest.raises(Exception, match="Invalid model directory"):
create_model_path("/etc/some_root_path", folder_path)


@pytest.mark.asyncio
async def test_check_file_exists_when_file_exists(tmp_path):
Expand Down

0 comments on commit 0df1e73

Please sign in to comment.