|
2 | 2 | from unittest.mock import AsyncMock, Mock, patch |
3 | 3 |
|
4 | 4 | import pytest |
| 5 | +from auth0_server_python.auth_types import CompleteConnectAccountResponse, ConnectAccountOptions |
5 | 6 | from fastapi import HTTPException, Request, Response |
6 | 7 |
|
7 | 8 | from auth0_fastapi.auth.auth_client import AuthClient |
@@ -392,3 +393,48 @@ async def test_store_options_validation(self, auth_client): |
392 | 393 | await auth_client.start_login(store_options=valid_options) |
393 | 394 |
|
394 | 395 | mock_start.assert_called() |
| 396 | + |
| 397 | + |
| 398 | +class TestConnectedAccountFlow: |
| 399 | + """Test connected account functionality.""" |
| 400 | + |
| 401 | + @pytest.mark.asyncio |
| 402 | + async def test_start_connect_account(self, auth_client): |
| 403 | + """Test initiating user account linking.""" |
| 404 | + mock_connect_url = "https://test.auth0.com/connected-accounts/connect?ticket" |
| 405 | + |
| 406 | + with patch.object(auth_client.client, 'start_connect_account', new_callable=AsyncMock) as mock_start_connect: |
| 407 | + mock_start_connect.return_value = mock_connect_url |
| 408 | + |
| 409 | + result = await auth_client.start_connect_account( |
| 410 | + connection="google-oauth2", |
| 411 | + app_state={"returnTo": "/profile"}, |
| 412 | + authorization_params={"prompt": "consent"}, |
| 413 | + ) |
| 414 | + |
| 415 | + assert result == mock_connect_url |
| 416 | + mock_start_connect.assert_called_once_with( |
| 417 | + options=ConnectAccountOptions( |
| 418 | + connection="google-oauth2", |
| 419 | + app_state={"returnTo": "/profile"}, |
| 420 | + authorization_params={"prompt": "consent"}, |
| 421 | + ), store_options=None) |
| 422 | + |
| 423 | + @pytest.mark.asyncio |
| 424 | + async def test_complete_connect_account(self, auth_client): |
| 425 | + """Test initiating user account linking.""" |
| 426 | + mock_callback_url = "https://test.auth0.com/connected-accounts/connect?ticket" |
| 427 | + mock_result = CompleteConnectAccountResponse( |
| 428 | + id="id_12345", |
| 429 | + connection="google-oauth2", |
| 430 | + access_type="offline", |
| 431 | + scopes=["read:foo"], |
| 432 | + created_at="1970-01-01T00:00:00Z" |
| 433 | + ) |
| 434 | + with patch.object(auth_client.client, 'complete_connect_account', new_callable=AsyncMock) as mock_complete: |
| 435 | + mock_complete.return_value = mock_result |
| 436 | + |
| 437 | + result = await auth_client.complete_connect_account(mock_callback_url) |
| 438 | + |
| 439 | + assert result == mock_result |
| 440 | + mock_complete.assert_called_once_with(mock_callback_url, store_options=None) |
0 commit comments