Skip to content

Commit 6f24161

Browse files
committed
Add verify token tests
1 parent 946fc05 commit 6f24161

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/test_cli_login.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,31 @@ def test_notify_already_logged_in_user(
177177
assert result.exit_code == 0
178178
assert "Already logged in as [email protected]" in result.output
179179
assert "Run fastapi logout first if you want to switch accounts." in result.output
180+
181+
182+
@pytest.mark.respx(base_url=settings.base_api_url)
183+
def test_verify_token_returns_false_on_unauthorized(respx_mock: respx.MockRouter) -> None:
184+
from fastapi_cloud_cli.commands.login import _verify_token
185+
from fastapi_cloud_cli.utils.api import APIClient
186+
187+
respx_mock.get("/users/me").mock(return_value=Response(401))
188+
189+
with APIClient() as client:
190+
is_valid, email = _verify_token(client)
191+
192+
assert is_valid is False
193+
assert email is None
194+
195+
196+
@pytest.mark.respx(base_url=settings.base_api_url)
197+
def test_verify_token_returns_false_on_forbidden(respx_mock: respx.MockRouter) -> None:
198+
from fastapi_cloud_cli.commands.login import _verify_token
199+
from fastapi_cloud_cli.utils.api import APIClient
200+
201+
respx_mock.get("/users/me").mock(return_value=Response(403))
202+
203+
with APIClient() as client:
204+
is_valid, email = _verify_token(client)
205+
206+
assert is_valid is False
207+
assert email is None

0 commit comments

Comments
 (0)