-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handling path containing url unicode chars #312
Open
mateuszkuprowski
wants to merge
6
commits into
main
Choose a base branch
from
fix-dropbox-source-auth-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+113
−1
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
47a2ad5
Fixed handling paths wit whitespace
mateuszkuprowski 12ec8d8
Merge with main
mateuszkuprowski 7386002
Linter fix
mateuszkuprowski c76796b
Added unit test for url and space path styles in fsspec
mateuszkuprowski a6adbc5
Removed some excessive comments I made for myself
mateuszkuprowski ac578c5
Lint fix
mateuszkuprowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,93 @@ | ||
from unittest.mock import MagicMock, patch | ||
from urllib.parse import unquote | ||
|
||
import pytest | ||
|
||
from unstructured_ingest.v2.processes.connectors.fsspec.fsspec import ( | ||
FsspecAccessConfig, | ||
FsspecConnectionConfig, | ||
FsspecIndexer, | ||
FsspecIndexerConfig, | ||
Secret, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("remote_url", "expected_path"), | ||
[ | ||
("dropbox://da ta", "da ta"), | ||
("dropbox://da%20ta", "da ta"), | ||
], | ||
) | ||
def test_fsspec_indexer_path_decoding(remote_url, expected_path): | ||
index_config = FsspecIndexerConfig(remote_url=remote_url) | ||
connection_config = FsspecConnectionConfig(access_config=Secret(FsspecAccessConfig())) | ||
|
||
# After initialization, ensure path_without_protocol matches expected result | ||
assert ( | ||
index_config.path_without_protocol == expected_path | ||
), f"Expected {expected_path}, got {index_config.path_without_protocol}" | ||
|
||
indexer = FsspecIndexer(connection_config=connection_config, index_config=index_config) | ||
|
||
# Now index_config should have our expected path | ||
full_path = expected_path | ||
assert ( | ||
indexer.index_config.path_without_protocol == full_path | ||
), f"Expected path to be {full_path}, got {indexer.index_config.path_without_protocol}" | ||
|
||
# Mock fsspec filesystem class to verify it's called with the correct path | ||
with patch("fsspec.get_filesystem_class") as mock_fs_class: | ||
mock_fs_instance = MagicMock() | ||
mock_fs_class.return_value = lambda **kwargs: mock_fs_instance | ||
|
||
# Mock fs.ls to return a dummy file | ||
mock_fs_instance.ls.return_value = [ | ||
{"name": full_path + "/file.txt", "type": "file", "size": 123} | ||
] | ||
|
||
files = indexer.get_file_data() | ||
|
||
# Verify that fs.ls was called with the correct decoded path | ||
mock_fs_instance.ls.assert_called_once_with(full_path, detail=True) | ||
|
||
# Assert that we got the expected file and it has the correct name | ||
assert len(files) == 1 | ||
assert ( | ||
files[0]["name"] == full_path + "/file.txt" | ||
), "File name did not match expected output" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"remote_url", | ||
[ | ||
"dropbox://da ta", | ||
"dropbox://da%20ta", | ||
], | ||
) | ||
def test_fsspec_indexer_precheck(remote_url): | ||
# This test ensures that precheck doesn't raise errors and calls head appropriately | ||
index_config = FsspecIndexerConfig(remote_url=remote_url) | ||
connection_config = FsspecConnectionConfig(access_config=Secret(FsspecAccessConfig())) | ||
indexer = FsspecIndexer(connection_config=connection_config, index_config=index_config) | ||
|
||
with patch("fsspec.get_filesystem_class") as mock_fs_class: | ||
mock_fs_instance = MagicMock() | ||
mock_fs_class.return_value = lambda **kwargs: mock_fs_instance | ||
|
||
mock_fs_instance.ls.return_value = [ | ||
{ | ||
"name": "/" + unquote(remote_url.split("://", 1)[1]) + "/file.txt", | ||
"type": "file", | ||
"size": 123, | ||
} | ||
] | ||
|
||
# head should be called on that file | ||
mock_fs_instance.head.return_value = {"Content-Length": "123"} | ||
|
||
# If precheck does not raise SourceConnectionError, we consider it passed | ||
indexer.precheck() | ||
|
||
# Check that fs.head was called with the correct file path | ||
mock_fs_instance.head.assert_called_once() |
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.3.11-dev0" # pragma: no cover | ||
__version__ = "0.3.11-dev1" # pragma: no cover |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if my dropbox folder is named "a%20b" (literal name, not encoded)? Will it return
a%20b
ora b
?