|
18 | 18 | import base64 |
19 | 19 | import os |
20 | 20 | from typing import Any, Callable, Dict, cast |
| 21 | +from copy import deepcopy |
21 | 22 | from unittest import mock |
22 | 23 |
|
23 | 24 | import pytest |
@@ -858,6 +859,42 @@ def test_load_table_200(rest_mock: Mocker, example_table_metadata_with_snapshot_ |
858 | 859 | assert actual == expected |
859 | 860 |
|
860 | 861 |
|
| 862 | +def test_load_table_prefers_storage_credentials_over_config( |
| 863 | + rest_mock: Mocker, example_table_metadata_with_snapshot_v1_rest_json: Dict[str, Any], monkeypatch: pytest.MonkeyPatch |
| 864 | +) -> None: |
| 865 | + table_resp = deepcopy(example_table_metadata_with_snapshot_v1_rest_json) |
| 866 | + table_resp["config"] = {"some.key": "from-config", "only.config": "only-config"} |
| 867 | + table_resp["storage-credentials"] = {"some.key": "from-cred", "only.creds": "only-creds"} |
| 868 | + |
| 869 | + table_resp["metadata"].setdefault("properties", {})["meta.key"] = "from-metadata" |
| 870 | + |
| 871 | + captured: Dict[str, Any] = {} |
| 872 | + |
| 873 | + def _capture_io(_self: Any, properties: Dict[str, Any], location: Any) -> Any: # type: ignore |
| 874 | + captured["properties"] = dict(properties) |
| 875 | + captured["location"] = location |
| 876 | + class _DummyIO: |
| 877 | + pass |
| 878 | + return _DummyIO() |
| 879 | + |
| 880 | + monkeypatch.setattr(RestCatalog, "_load_file_io", _capture_io, raising=True) |
| 881 | + |
| 882 | + rest_mock.get( |
| 883 | + f"{TEST_URI}v1/namespaces/fokko/tables/table", |
| 884 | + json=table_resp, |
| 885 | + status_code=200, |
| 886 | + request_headers=TEST_HEADERS, |
| 887 | + ) |
| 888 | + |
| 889 | + catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN) |
| 890 | + _ = catalog.load_table(("fokko", "table")) |
| 891 | + |
| 892 | + props = cast(Dict[str, Any], captured["properties"]) |
| 893 | + assert props["meta.key"] == "from-metadata" |
| 894 | + assert props["some.key"] == "from-cred" |
| 895 | + assert props["only.creds"] == "only-creds" |
| 896 | + |
| 897 | + |
861 | 898 | def test_load_table_200_loading_mode( |
862 | 899 | rest_mock: Mocker, example_table_metadata_with_snapshot_v1_rest_json: Dict[str, Any] |
863 | 900 | ) -> None: |
|
0 commit comments