Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions router/tests/test_get_gemini_oauth_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@

@pytest.mark.asyncio
async def test_get_gemini_oauth_status_missing_file():
with patch("os.path.exists", return_value=False):
with patch("asyncio.to_thread", new_callable=AsyncMock, return_value=False):
result = await main.get_gemini_oauth_status()
assert result == {"status": "missing", "detail": "No oauth_creds.json found", "expiry_ms": 0}

@pytest.mark.asyncio
async def test_get_gemini_oauth_status_no_access_token():
mock_data = {"expiry_date": 1234567890000}
mock_file = AsyncMock()
mock_file.read.return_value = json.dumps(mock_data)
mock_file.__aenter__.return_value = mock_file
with patch("os.path.exists", return_value=True), \
patch("aiofiles.open", return_value=mock_file):
with patch("asyncio.to_thread", new_callable=AsyncMock, return_value=True), \
patch("router.main._read_json_file_async", new_callable=AsyncMock, return_value=mock_data):
result = await main.get_gemini_oauth_status()
assert result == {"status": "missing", "detail": "No access token in file", "expiry_ms": 0}

Expand All @@ -34,18 +31,14 @@ async def test_get_gemini_oauth_status_scenarios(delta, expected_status, expecte
current_time_ms = 1000000000000
expiry_ms = current_time_ms + delta
mock_data = {"access_token": "test_token", "expiry_date": expiry_ms}
mock_file = AsyncMock()
mock_file.read.return_value = json.dumps(mock_data)
mock_file.__aenter__.return_value = mock_file
with patch("os.path.exists", return_value=True), \
patch("aiofiles.open", return_value=mock_file), \
with patch("asyncio.to_thread", new_callable=AsyncMock, return_value=True), \
patch("router.main._read_json_file_async", new_callable=AsyncMock, return_value=mock_data), \
patch("time.time", return_value=current_time_ms / 1000.0):
result = await main.get_gemini_oauth_status()
assert result == {"status": expected_status, "detail": expected_detail, "expiry_ms": expiry_ms}

@pytest.mark.asyncio
async def test_get_gemini_oauth_status_exception():
with patch("os.path.exists", return_value=True), \
patch("aiofiles.open", side_effect=Exception("Test error")):
with patch("asyncio.to_thread", new_callable=AsyncMock, side_effect=Exception("Test error")):
result = await main.get_gemini_oauth_status()
assert result == {"status": "error", "detail": "Test error", "expiry_ms": 0}
Loading