Refactor drag handling and update tests
- Renamed `initiate_drag` to `handle_drag` in MainWindow and updated related tests. - Improved drag handling logic to utilize a bridge for starting file drags. - Updated `_on_drag_started` and `_on_drag_failed` methods to match new signatures. - Modified test cases to reflect changes in drag handling and assertions. Enhance path validation and logging - Updated `PathValidator` to log warnings for nonexistent roots instead of raising errors. - Adjusted tests to verify the new behavior of skipping nonexistent roots. Update web application UI and functionality - Changed displayed text for drag items to reflect local paths and Azure Blob Storage URLs. - Added debug logging for drag operations in the web application. - Improved instructions for testing drag and drop functionality. Add configuration documentation and example files - Created `CONFIG_README.md` to provide detailed configuration instructions for WebDrop Bridge. - Added `config.example.json` and `config_test.json` for reference and testing purposes. Implement URL conversion logic - Introduced `URLConverter` class to handle conversion of Azure Blob Storage URLs to local paths. - Added unit tests for URL conversion to ensure correct functionality. Develop download interceptor script - Created `download_interceptor.js` to intercept download-related actions in the web application. - Implemented logging for fetch calls, XMLHttpRequests, and Blob URL creations. Add download test page and related tests - Created `test_download.html` for testing various download scenarios. - Implemented `test_download.py` to verify download path resolution and file construction. - Added `test_url_mappings.py` to ensure URL mappings are loaded correctly. Add unit tests for URL converter - Created `test_url_converter.py` to validate URL conversion logic and mapping behavior.
This commit is contained in:
parent
c9704efc8d
commit
88dc358894
21 changed files with 1870 additions and 432 deletions
144
tests/unit/test_url_converter.py
Normal file
144
tests/unit/test_url_converter.py
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
"""Unit tests for URL converter."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from webdrop_bridge.config import Config, URLMapping
|
||||
from webdrop_bridge.core.url_converter import URLConverter
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_config():
|
||||
"""Create test configuration with URL mappings."""
|
||||
return Config(
|
||||
app_name="Test App",
|
||||
app_version="1.0.0",
|
||||
log_level="INFO",
|
||||
log_file=None,
|
||||
allowed_roots=[],
|
||||
allowed_urls=[],
|
||||
webapp_url="https://wps.agravity.io/",
|
||||
url_mappings=[
|
||||
URLMapping(
|
||||
url_prefix="https://wpsagravitystg.file.core.windows.net/wpsagravitysync/",
|
||||
local_path="Z:"
|
||||
),
|
||||
URLMapping(
|
||||
url_prefix="https://other.blob.core.windows.net/container/",
|
||||
local_path="Y:\\shared"
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def converter(test_config):
|
||||
"""Create URL converter with test config."""
|
||||
return URLConverter(test_config)
|
||||
|
||||
|
||||
def test_convert_simple_url(converter):
|
||||
"""Test converting a simple Azure URL to local path."""
|
||||
url = "https://wpsagravitystg.file.core.windows.net/wpsagravitysync/test/file.png"
|
||||
result = converter.convert_url_to_path(url)
|
||||
|
||||
assert result is not None
|
||||
assert str(result).endswith("test\\file.png") # Windows path separator
|
||||
|
||||
|
||||
def test_convert_url_with_special_characters(converter):
|
||||
"""Test URL with special characters (URL encoded)."""
|
||||
url = "https://wpsagravitystg.file.core.windows.net/wpsagravitysync/folder/file%20with%20spaces.png"
|
||||
result = converter.convert_url_to_path(url)
|
||||
|
||||
assert result is not None
|
||||
assert "file with spaces.png" in str(result)
|
||||
|
||||
|
||||
def test_convert_url_with_subdirectories(converter):
|
||||
"""Test URL with deep directory structure."""
|
||||
url = "https://wpsagravitystg.file.core.windows.net/wpsagravitysync/aN5PysnXIuRECzcRbvHkjL7g0/subfolder/file.png"
|
||||
result = converter.convert_url_to_path(url)
|
||||
|
||||
assert result is not None
|
||||
assert "aN5PysnXIuRECzcRbvHkjL7g0" in str(result)
|
||||
assert "subfolder" in str(result)
|
||||
|
||||
|
||||
def test_convert_unmapped_url(converter):
|
||||
"""Test URL that doesn't match any mapping."""
|
||||
url = "https://unknown.blob.core.windows.net/container/file.png"
|
||||
result = converter.convert_url_to_path(url)
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_convert_empty_url(converter):
|
||||
"""Test empty URL."""
|
||||
result = converter.convert_url_to_path("")
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_convert_none_url(converter):
|
||||
"""Test None URL."""
|
||||
result = converter.convert_url_to_path(None)
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_is_azure_url_positive(converter):
|
||||
"""Test recognizing valid Azure URLs."""
|
||||
url = "https://wpsagravitystg.file.core.windows.net/wpsagravitysync/file.png"
|
||||
assert converter.is_azure_url(url) is True
|
||||
|
||||
|
||||
def test_is_azure_url_negative(converter):
|
||||
"""Test rejecting non-Azure URLs."""
|
||||
assert converter.is_azure_url("https://example.com/file.png") is False
|
||||
assert converter.is_azure_url("Z:\\file.png") is False
|
||||
assert converter.is_azure_url("") is False
|
||||
|
||||
|
||||
def test_multiple_mappings(converter):
|
||||
"""Test that correct mapping is used for URL."""
|
||||
url1 = "https://wpsagravitystg.file.core.windows.net/wpsagravitysync/file.png"
|
||||
url2 = "https://other.blob.core.windows.net/container/file.png"
|
||||
|
||||
result1 = converter.convert_url_to_path(url1)
|
||||
result2 = converter.convert_url_to_path(url2)
|
||||
|
||||
assert result1 is not None
|
||||
assert result2 is not None
|
||||
assert str(result1).startswith("Z:")
|
||||
assert str(result2).startswith("Y:")
|
||||
|
||||
|
||||
def test_url_mapping_validation_http():
|
||||
"""Test that URL mapping requires http:// or https://."""
|
||||
with pytest.raises(Exception): # ConfigurationError
|
||||
URLMapping(
|
||||
url_prefix="ftp://server/path/",
|
||||
local_path="Z:"
|
||||
)
|
||||
|
||||
|
||||
def test_url_mapping_adds_trailing_slash():
|
||||
"""Test that URL mapping adds trailing slash if missing."""
|
||||
mapping = URLMapping(
|
||||
url_prefix="https://example.com/path",
|
||||
local_path="Z:"
|
||||
)
|
||||
assert mapping.url_prefix.endswith("/")
|
||||
|
||||
|
||||
def test_convert_url_example_from_docs(converter):
|
||||
"""Test the exact example from documentation."""
|
||||
url = "https://wpsagravitystg.file.core.windows.net/wpsagravitysync/aN5PysnXIuRECzcRbvHkjL7g0/Hintergrund_Agravity.png"
|
||||
result = converter.convert_url_to_path(url)
|
||||
|
||||
assert result is not None
|
||||
# Should be: Z:\aN5PysnXIuRECzcRbvHkjL7g0\Hintergrund_Agravity.png
|
||||
expected_parts = ["Z:", "aN5PysnXIuRECzcRbvHkjL7g0", "Hintergrund_Agravity.png"]
|
||||
result_str = str(result)
|
||||
for part in expected_parts:
|
||||
assert part in result_str
|
||||
Loading…
Add table
Add a link
Reference in a new issue