bugraoz93 commented on code in PR #48855: URL: https://github.com/apache/airflow/pull/48855#discussion_r2031680775
########## airflow-ctl/tests/airflow_ctl/ctl/commands/test_auth_command.py: ########## @@ -16,32 +16,85 @@ # under the License. from __future__ import annotations +import io import json import os from unittest import mock from unittest.mock import patch from platformdirs import user_config_path +from airflowctl.api.datamodels.auth_generated import LoginResponse from airflowctl.ctl import cli_parser from airflowctl.ctl.commands import auth_command class TestCliAuthCommands: parser = cli_parser.get_parser() + login_response = LoginResponse( + access_token="TEST_TOKEN", + ) @patch.dict(os.environ, {"AIRFLOW_CLI_TOKEN": "TEST_TOKEN"}) @patch.dict(os.environ, {"AIRFLOW_CLI_ENVIRONMENT": "TEST_AUTH_LOGIN"}) @patch("airflowctl.api.client.keyring") - def test_login(self, mock_keyring): + def test_login(self, mock_keyring, api_client_maker): + api_client = api_client_maker( + path="/auth/token/cli", + response_json=self.login_response.model_dump(), + expected_http_status_code=201, + kind="auth", + ) + mock_keyring.set_password = mock.MagicMock() mock_keyring.get_password.return_value = None env = "TEST_AUTH_LOGIN" - auth_command.login(self.parser.parse_args(["auth", "login", "--api-url", "http://localhost:8080"])) + auth_command.login( + self.parser.parse_args(["auth", "login", "--api-url", "http://localhost:8080"]), + api_client=api_client, + ) default_config_dir = user_config_path("airflow", "Apache Software Foundation") assert os.path.exists(default_config_dir) with open(os.path.join(default_config_dir, f"{env}.json")) as f: assert json.load(f) == { "api_url": "http://localhost:8080", } + + mock_keyring.set_password.assert_called_once_with( + "airflowctl", "api_token-TEST_AUTH_LOGIN", "TEST_TOKEN" + ) + + # Test auth login with username and password + @patch("airflowctl.api.client.keyring") + def test_login_with_username_and_password(self, mock_keyring, api_client_maker, monkeypatch): + api_client = api_client_maker( + path="/auth/token/cli", + response_json=self.login_response.model_dump(), + expected_http_status_code=201, + kind="auth", Review Comment: ```suggestion kind=ClientKind.AUTH, ``` ########## airflow-ctl/tests/airflow_ctl/ctl/commands/test_auth_command.py: ########## @@ -16,32 +16,85 @@ # under the License. from __future__ import annotations +import io import json import os from unittest import mock from unittest.mock import patch from platformdirs import user_config_path +from airflowctl.api.datamodels.auth_generated import LoginResponse from airflowctl.ctl import cli_parser from airflowctl.ctl.commands import auth_command class TestCliAuthCommands: parser = cli_parser.get_parser() + login_response = LoginResponse( + access_token="TEST_TOKEN", + ) @patch.dict(os.environ, {"AIRFLOW_CLI_TOKEN": "TEST_TOKEN"}) @patch.dict(os.environ, {"AIRFLOW_CLI_ENVIRONMENT": "TEST_AUTH_LOGIN"}) @patch("airflowctl.api.client.keyring") - def test_login(self, mock_keyring): + def test_login(self, mock_keyring, api_client_maker): + api_client = api_client_maker( + path="/auth/token/cli", + response_json=self.login_response.model_dump(), + expected_http_status_code=201, + kind="auth", Review Comment: ```suggestion kind=ClientKind.AUTH, ``` ########## airflow-ctl/tests/airflow_ctl/ctl/commands/test_auth_command.py: ########## @@ -16,32 +16,85 @@ # under the License. from __future__ import annotations +import io import json import os from unittest import mock from unittest.mock import patch from platformdirs import user_config_path +from airflowctl.api.datamodels.auth_generated import LoginResponse Review Comment: ```suggestion from airflowctl.api.client import ClientKind from airflowctl.api.datamodels.auth_generated import LoginResponse ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org