Skip to content

Commit 90e662b

Browse files
committed
Add test for login when deploy token is set
1 parent aec339c commit 90e662b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/test_cli_login.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,52 @@ def test_full_login(
7777
assert '"access_token":"test_token_1234"' in temp_auth_config.read_text()
7878

7979

80+
@pytest.mark.respx
81+
def test_full_login_with_deploy_token_set(
82+
respx_mock: respx.MockRouter, temp_auth_config: Path, settings: Settings
83+
) -> None:
84+
with patch("fastapi_cloud_cli.commands.login.typer.launch") as mock_open:
85+
respx_mock.post(
86+
"/login/device/authorization", data={"client_id": settings.client_id}
87+
).mock(
88+
return_value=Response(
89+
200,
90+
json={
91+
"verification_uri_complete": "http://test.com",
92+
"verification_uri": "http://test.com",
93+
"user_code": "1234",
94+
"device_code": "5678",
95+
},
96+
)
97+
)
98+
respx_mock.post(
99+
"/login/device/token",
100+
data={
101+
"device_code": "5678",
102+
"client_id": settings.client_id,
103+
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
104+
},
105+
).mock(return_value=Response(200, json={"access_token": "test_token_1234"}))
106+
107+
# Verify no auth file exists before login
108+
assert not temp_auth_config.exists()
109+
110+
result = runner.invoke(
111+
app,
112+
["login"],
113+
env={"FASTAPI_CLOUD_TOKEN": "test_deploy_token"}, # Should be ignored
114+
)
115+
116+
assert result.exit_code == 0
117+
assert mock_open.called
118+
assert mock_open.call_args.args == ("http://test.com",)
119+
assert "Now you are logged in!" in result.output
120+
121+
# Verify auth file was created with correct content
122+
assert temp_auth_config.exists()
123+
assert '"access_token":"test_token_1234"' in temp_auth_config.read_text()
124+
125+
80126
@pytest.mark.respx
81127
def test_fetch_access_token_success_immediately(
82128
respx_mock: respx.MockRouter, settings: Settings

0 commit comments

Comments
 (0)