|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import threading |
4 | | -from pathlib import Path |
| 4 | +from pathlib import Path, PureWindowsPath |
5 | 5 |
|
6 | 6 | import pyarrow as pa # type: ignore |
7 | 7 | import pytest |
@@ -75,6 +75,32 @@ def test_get_file(client: TestClient, project_tmp_path: Path) -> None: |
75 | 75 | } |
76 | 76 |
|
77 | 77 |
|
| 78 | +def test_get_file_nested_path_matches_directory_listing( |
| 79 | + client: TestClient, project_tmp_path: Path |
| 80 | +) -> None: |
| 81 | + models_dir = project_tmp_path / "models" |
| 82 | + models_dir.mkdir() |
| 83 | + (models_dir / "mymodel.sql").write_text("SELECT 1") |
| 84 | + |
| 85 | + response = client.get("/api/files/models/mymodel.sql") |
| 86 | + assert response.status_code == 200 |
| 87 | + assert response.json()["path"] == "models/mymodel.sql" |
| 88 | + |
| 89 | + |
| 90 | +def test_get_file_relative_path_uses_posix_separators(tmp_path: Path) -> None: |
| 91 | + file_path = tmp_path / "models" / "mymodel.sql" |
| 92 | + file_path.parent.mkdir(parents=True) |
| 93 | + file_path.write_text("SELECT 1") |
| 94 | + |
| 95 | + windows_relative = PureWindowsPath("models/mymodel.sql") |
| 96 | + assert windows_relative.as_posix() == "models/mymodel.sql" |
| 97 | + assert str(windows_relative) == "models\\mymodel.sql" |
| 98 | + |
| 99 | + file = _get_file_with_content(file_path, windows_relative.as_posix()) |
| 100 | + assert file.path == "models/mymodel.sql" |
| 101 | + assert file.path != str(windows_relative) |
| 102 | + |
| 103 | + |
78 | 104 | def test_get_file_not_found(client: TestClient) -> None: |
79 | 105 | response = client.get("/api/files/not_found.txt") |
80 | 106 | assert response.status_code == 404 |
|
0 commit comments