Skip to content

Commit c915752

Browse files
committed
add extra test
1 parent 8103237 commit c915752

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/catalog/test_rest.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,3 +1748,42 @@ def test_drop_view_204(rest_mock: Mocker) -> None:
17481748
request_headers=TEST_HEADERS,
17491749
)
17501750
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).drop_view(("some_namespace", "some_view"))
1751+
1752+
1753+
@mock.patch("google.auth.transport.requests.Request")
1754+
@mock.patch("google.auth.load_credentials_from_file")
1755+
def test_rest_catalog_with_google_credentials_path(
1756+
mock_load_creds: mock.MagicMock, mock_google_request: mock.MagicMock, rest_mock: Mocker
1757+
) -> None:
1758+
mock_credentials = mock.MagicMock()
1759+
mock_credentials.token = "file_token"
1760+
mock_load_creds.return_value = (mock_credentials, "test_project_file")
1761+
1762+
# Given
1763+
rest_mock.get(
1764+
f"{TEST_URI}v1/config",
1765+
json={"defaults": {}, "overrides": {}},
1766+
status_code=200,
1767+
)
1768+
# Given
1769+
catalog_properties = {
1770+
"uri": TEST_URI,
1771+
"auth": {
1772+
"type": "google",
1773+
"google": {
1774+
"credentials_path": "/fake/path.json",
1775+
},
1776+
},
1777+
}
1778+
catalog = RestCatalog("rest", **catalog_properties) # type: ignore
1779+
assert catalog.uri == TEST_URI
1780+
1781+
expected_auth_header = "Bearer file_token"
1782+
assert rest_mock.last_request.headers["Authorization"] == expected_auth_header
1783+
1784+
mock_load_creds.assert_called_with("/fake/path.json", scopes=None)
1785+
mock_credentials.refresh.assert_called_once_with(mock_google_request.return_value)
1786+
history = rest_mock.request_history
1787+
assert len(history) == 1
1788+
actual_headers = history[0].headers
1789+
assert actual_headers["Authorization"] == expected_auth_header

0 commit comments

Comments
 (0)