From 35a6f0601c863c4031441b4968a34cc8229b154f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 24 Jul 2026 23:54:33 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20improve=20testing=20for=20get=5F?= =?UTF-8?q?gemini=5Foauth=5Fstatus=20by=20mocking=20asyncio.to=5Fthread?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: sheepdestroyer <1377479+sheepdestroyer@users.noreply.github.com> --- router/tests/test_get_gemini_oauth_status.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/router/tests/test_get_gemini_oauth_status.py b/router/tests/test_get_gemini_oauth_status.py index 89cfc3b..ddf0af2 100644 --- a/router/tests/test_get_gemini_oauth_status.py +++ b/router/tests/test_get_gemini_oauth_status.py @@ -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} @@ -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}