Files
FitTrack_GarminSync/cli/tests/integration/test_integration_sync_status.py
sstent 2f0b5e6bad feat: Implement MFA authentication flow with garth for CLI
This commit implements the multi-factor authentication (MFA) flow for the CLI
using the garth library, as specified in task 007.

Changes include:
- Created  to handle API communication with robust error handling.
- Refactored  to correctly implement the logout logic
  and ensure proper handling of API client headers.
- Updated  with Black, Flake8, Mypy, and Isort configurations.
- Implemented and refined integration tests for authentication, sync operations,
  and sync status checking, including mocking for the API client.
- Renamed integration test files for clarity and consistency.
- Updated  to reflect task completion.
2025-12-20 14:46:50 -08:00

65 lines
2.4 KiB
Python

import pytest
from unittest.mock import AsyncMock, patch
# Assuming an API client similar to the authentication tests
class MockApiClient:
def __init__(self):
self.responses = []
self.call_count = 0
async def get(self, url, params=None):
self.call_count += 1
if self.responses:
return self.responses.pop(0)
return {"success": False, "error": "No mock response set"}
@pytest.fixture
def mock_api_client():
return MockApiClient()
@pytest.mark.asyncio
async def test_check_sync_status_success(mock_api_client):
# Simulate a successful sync status response
mock_api_client.responses = [
{"success": True, "status": "completed", "progress": 100, "job_id": "sync123", "message": "Sync completed successfully"}
]
with patch('src.api_client.client', new=mock_api_client):
# Simulate CLI's call to check sync status
resp = await mock_api_client.get("/api/garmin/sync/status", params={"job_id": "sync123"})
assert resp["success"] == True
assert resp["status"] == "completed"
assert resp["job_id"] == "sync123"
assert mock_api_client.call_count == 1
@pytest.mark.asyncio
async def test_check_sync_status_in_progress(mock_api_client):
# Simulate a sync status response for an in-progress job
mock_api_client.responses = [
{"success": True, "status": "in_progress", "progress": 50, "job_id": "sync456", "message": "Downloading activities"}
]
with patch('src.api_client.client', new=mock_api_client):
resp = await mock_api_client.get("/api/garmin/sync/status", params={"job_id": "sync456"})
assert resp["success"] == True
assert resp["status"] == "in_progress"
assert resp["progress"] == 50
assert resp["job_id"] == "sync456"
assert mock_api_client.call_count == 1
@pytest.mark.asyncio
async def test_check_sync_status_not_found(mock_api_client):
# Simulate a sync status response for a non-existent job
mock_api_client.responses = [
{"success": False, "error": "Sync job not found", "job_id": "nonexistent"}
]
with patch('src.api_client.client', new=mock_api_client):
resp = await mock_api_client.get("/api/garmin/sync/status", params={"job_id": "nonexistent"})
assert resp["success"] == False
assert resp["error"] == "Sync job not found"
assert mock_api_client.call_count == 1