github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/clients/python-wrapper/tests/utests/test_client.py (about) 1 from lakefs.exceptions import NoAuthenticationFound 2 from tests.utests.common import ( 3 lakectl_test_config_context, 4 lakectl_no_config_context, 5 TEST_SERVER, 6 TEST_ACCESS_KEY_ID, 7 TEST_SECRET_ACCESS_KEY, 8 TEST_ENDPOINT_PATH, expect_exception_context 9 ) 10 11 TEST_CONFIG_KWARGS: dict[str, str] = { 12 "username": "my_username", 13 "password": "my_password", 14 "host": "http://my_host", 15 "access_token": "my_jwt_token" 16 } 17 18 19 class TestClient: 20 def test_client_no_config(self, monkeypatch): 21 with lakectl_no_config_context(monkeypatch) as client: 22 with expect_exception_context(NoAuthenticationFound): 23 client.Client() 24 25 def test_client_no_kwargs(self, monkeypatch, tmp_path): 26 with lakectl_test_config_context(monkeypatch, tmp_path) as client: 27 clt = client.Client() 28 config = clt.config 29 assert config.host == TEST_SERVER + TEST_ENDPOINT_PATH 30 assert config.username == TEST_ACCESS_KEY_ID 31 assert config.password == TEST_SECRET_ACCESS_KEY 32 33 def test_client_kwargs(self, monkeypatch, tmp_path): 34 # Use lakectl yaml file and ensure it is not being read in case kwargs are provided 35 with lakectl_test_config_context(monkeypatch, tmp_path) as client: 36 clt = client.Client(**TEST_CONFIG_KWARGS) 37 config = clt.config 38 assert config.host == TEST_CONFIG_KWARGS["host"] + TEST_ENDPOINT_PATH 39 assert config.username == TEST_CONFIG_KWARGS["username"] 40 assert config.password == TEST_CONFIG_KWARGS["password"] 41 assert config.access_token == TEST_CONFIG_KWARGS["access_token"]