-
-
Notifications
You must be signed in to change notification settings - Fork 465
fix: route local tile URLs through jupyter-loopback in get_local_tile_url #1337
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,55 @@ def test_set_proxy_successful_request(self, mock_get): | |
| self.assertEqual(os.environ["HTTPS_PROXY"], "http://192.168.0.1:8080") | ||
| mock_get.assert_called_once_with("https://google.com") | ||
|
|
||
| def _mock_localtileserver(self): | ||
| """Return a fake ``localtileserver`` module with a mocked TileClient.""" | ||
| fake_client = MagicMock() | ||
| fake_client.get_tile_url.return_value = ( | ||
| "http://127.0.0.1:0/api/tiles/{z}/{x}/{y}.png" | ||
| ) | ||
| fake_module = MagicMock() | ||
| fake_module.TileClient.return_value = fake_client | ||
| return fake_module, fake_client | ||
|
|
||
| @patch.dict(os.environ, {}, clear=True) | ||
| def test_get_local_tile_url_enables_jupyter_loopback(self): | ||
| """enable_jupyter_loopback is invoked when the client supports it.""" | ||
| fake_module, fake_client = self._mock_localtileserver() | ||
| with patch.dict("sys.modules", {"localtileserver": fake_module}): | ||
| url = get_local_tile_url("test.tif") | ||
| fake_client.enable_jupyter_loopback.assert_called_once() | ||
| self.assertEqual(url, "http://127.0.0.1:0/api/tiles/{z}/{x}/{y}.png") | ||
|
|
||
| @patch.dict(os.environ, {}, clear=True) | ||
| def test_get_local_tile_url_without_loopback_support(self): | ||
| """A client lacking enable_jupyter_loopback must not raise.""" | ||
| fake_client = MagicMock(spec=["get_tile_url"]) | ||
| fake_client.get_tile_url.return_value = "http://tile" | ||
| fake_module = MagicMock() | ||
| fake_module.TileClient.return_value = fake_client | ||
| with patch.dict("sys.modules", {"localtileserver": fake_module}): | ||
| url = get_local_tile_url("test.tif") | ||
| self.assertFalse(hasattr(fake_client, "enable_jupyter_loopback")) | ||
| self.assertEqual(url, "http://tile") | ||
|
|
||
| @patch.dict(os.environ, {}, clear=True) | ||
| def test_get_local_tile_url_prefix_precedence(self): | ||
| """The prefix kwarg takes final precedence over the env var.""" | ||
| fake_module, _ = self._mock_localtileserver() | ||
| with patch.dict("sys.modules", {"localtileserver": fake_module}): | ||
| get_local_tile_url("test.tif", prefix="proxy/{port}") | ||
| self.assertEqual(os.environ["LOCALTILESERVER_CLIENT_PREFIX"], "proxy/{port}") | ||
|
|
||
|
Comment on lines
+110
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win Add a test for
`@patch.dict`(
os.environ, {"LOCALTILESERVER_CLIENT_PREFIX": "old/{port}"}, clear=True
)
def test_get_local_tile_url_prefix_overrides_existing_env(self):
"""An explicit prefix kwarg overrides an already-set env var."""
fake_module, _ = self._mock_localtileserver()
with patch.dict("sys.modules", {"localtileserver": fake_module}):
get_local_tile_url("test.tif", prefix="proxy/{port}")
self.assertEqual(os.environ["LOCALTILESERVER_CLIENT_PREFIX"], "proxy/{port}")🤖 Prompt for AI Agents |
||
| @patch.dict( | ||
| os.environ, {"LOCALTILESERVER_CLIENT_PREFIX": "keep/{port}"}, clear=True | ||
| ) | ||
| def test_get_local_tile_url_prefix_none_ignored(self): | ||
| """prefix=None is ignored and does not overwrite an existing env var.""" | ||
| fake_module, _ = self._mock_localtileserver() | ||
| with patch.dict("sys.modules", {"localtileserver": fake_module}): | ||
| get_local_tile_url("test.tif", prefix=None) | ||
| self.assertEqual(os.environ["LOCALTILESERVER_CLIENT_PREFIX"], "keep/{port}") | ||
|
|
||
| # def test_pmtile_metadata_validates_pmtiles_suffix(self): | ||
| # with self.assertRaises(ValueError) as cm: | ||
| # pmtiles_metadata("/some/path/to/pmtiles.pmtiles") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.