Skip to content

Commit d908e3b

Browse files
committed
Add test
1 parent 45fc73b commit d908e3b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/test_cli_login.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,24 @@ def test_fetch_access_token_handles_500_error(respx_mock: respx.MockRouter) -> N
162162
with APIClient() as client:
163163
with pytest.raises(httpx.HTTPStatusError):
164164
_fetch_access_token(client, "test_device_code", 5)
165+
166+
167+
@pytest.mark.respx(base_url=settings.base_api_url)
168+
def test_notify_already_logged_in_user(
169+
respx_mock: respx.MockRouter, logged_in_cli: None
170+
) -> None:
171+
respx_mock.get("/users/me").mock(
172+
return_value=Response(200, json={"email": "[email protected]"})
173+
)
174+
175+
device_auth_mock = respx_mock.post(
176+
"/login/device/authorization", data={"client_id": settings.client_id}
177+
).mock(return_value=Response(200, json={}))
178+
179+
result = runner.invoke(app, ["login"])
180+
181+
assert result.exit_code == 0
182+
assert "Already logged in as [email protected]" in result.output
183+
assert "Run fastapi logout first if you want to switch accounts." in result.output
184+
185+
assert device_auth_mock.call_count == 0

0 commit comments

Comments
 (0)