-
Notifications
You must be signed in to change notification settings - Fork 0
π§ͺ Add tests for get_gemini_oauth_status #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sheepdestroyer
merged 9 commits into
master
from
chore/add-oauth-status-tests-15591368961301252072
Jul 1, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
02a8e69
Add tests for get_gemini_oauth_status
google-labs-jules[bot] 58074e0
Merge branch 'master' into chore/add-oauth-status-tests-1559136896130β¦
sheepdestroyer db6f898
Add tests for get_gemini_oauth_status
google-labs-jules[bot] 7a28bce
Add tests for get_gemini_oauth_status
google-labs-jules[bot] 432934e
Add tests for get_gemini_oauth_status
google-labs-jules[bot] 3833538
Merge branch 'master' into chore/add-oauth-status-tests-1559136896130β¦
sheepdestroyer 3278149
Merge branch 'master' into chore/add-oauth-status-tests-1559136896130β¦
sheepdestroyer 2f1658b
Merge branch 'master' into chore/add-oauth-status-tests-1559136896130β¦
sheepdestroyer 84f30b3
Add tests for get_gemini_oauth_status
google-labs-jules[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import pytest | ||
| import os | ||
| import sys | ||
| import json | ||
| from unittest.mock import patch, mock_open | ||
|
|
||
| # Ensure router directory is in sys.path | ||
| router_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) | ||
| if router_path not in sys.path: | ||
| sys.path.insert(0, router_path) | ||
|
|
||
| import main | ||
|
|
||
| def test_get_gemini_oauth_status_missing_file(): | ||
| with patch("os.path.exists", return_value=False): | ||
| result = main.get_gemini_oauth_status() | ||
| assert result == {"status": "missing", "detail": "No oauth_creds.json found", "expiry_ms": 0} | ||
|
|
||
| def test_get_gemini_oauth_status_no_access_token(): | ||
| mock_data = {"expiry_date": 1234567890000} | ||
| with patch("os.path.exists", return_value=True), \ | ||
| patch("builtins.open", mock_open(read_data=json.dumps(mock_data))): | ||
| result = main.get_gemini_oauth_status() | ||
| assert result == {"status": "missing", "detail": "No access token in file", "expiry_ms": 0} | ||
|
|
||
| def test_get_gemini_oauth_status_valid_less_than_60s(): | ||
| current_time_ms = 1000000000000 | ||
| expiry_ms = current_time_ms + 45000 # 45 seconds from now | ||
| mock_data = {"access_token": "test_token", "expiry_date": expiry_ms} | ||
| with patch("os.path.exists", return_value=True), \ | ||
| patch("builtins.open", mock_open(read_data=json.dumps(mock_data))), \ | ||
| patch("time.time", return_value=current_time_ms / 1000.0): | ||
| result = main.get_gemini_oauth_status() | ||
| assert result == {"status": "valid", "detail": "Expires in 45s", "expiry_ms": expiry_ms} | ||
|
|
||
| def test_get_gemini_oauth_status_valid_less_than_3600s(): | ||
| current_time_ms = 1000000000000 | ||
| expiry_ms = current_time_ms + 1500000 # 25 minutes from now (25 * 60 = 1500 seconds) | ||
| mock_data = {"access_token": "test_token", "expiry_date": expiry_ms} | ||
| with patch("os.path.exists", return_value=True), \ | ||
| patch("builtins.open", mock_open(read_data=json.dumps(mock_data))), \ | ||
| patch("time.time", return_value=current_time_ms / 1000.0): | ||
| result = main.get_gemini_oauth_status() | ||
| assert result == {"status": "valid", "detail": "Expires in 25m 0s", "expiry_ms": expiry_ms} | ||
|
|
||
| def test_get_gemini_oauth_status_valid_more_than_3600s(): | ||
| current_time_ms = 1000000000000 | ||
| expiry_ms = current_time_ms + 7500000 # 2 hours, 5 minutes from now (2 * 3600 + 5 * 60 = 7500) | ||
| mock_data = {"access_token": "test_token", "expiry_date": expiry_ms} | ||
| with patch("os.path.exists", return_value=True), \ | ||
| patch("builtins.open", mock_open(read_data=json.dumps(mock_data))), \ | ||
| patch("time.time", return_value=current_time_ms / 1000.0): | ||
| result = main.get_gemini_oauth_status() | ||
| assert result == {"status": "valid", "detail": "Expires in 2h 5m", "expiry_ms": expiry_ms} | ||
|
|
||
| def test_get_gemini_oauth_status_expired_less_than_3600s(): | ||
| current_time_ms = 1000000000000 | ||
| expiry_ms = current_time_ms - 1500000 # Expired 25 minutes ago | ||
| mock_data = {"access_token": "test_token", "expiry_date": expiry_ms} | ||
| with patch("os.path.exists", return_value=True), \ | ||
| patch("builtins.open", mock_open(read_data=json.dumps(mock_data))), \ | ||
| patch("time.time", return_value=current_time_ms / 1000.0): | ||
| result = main.get_gemini_oauth_status() | ||
| assert result == {"status": "expired", "detail": "Expired 25 minutes ago", "expiry_ms": expiry_ms} | ||
|
|
||
| def test_get_gemini_oauth_status_expired_less_than_86400s(): | ||
| current_time_ms = 1000000000000 | ||
| expiry_ms = current_time_ms - 7500000 # Expired 2 hours ago | ||
| mock_data = {"access_token": "test_token", "expiry_date": expiry_ms} | ||
| with patch("os.path.exists", return_value=True), \ | ||
| patch("builtins.open", mock_open(read_data=json.dumps(mock_data))), \ | ||
| patch("time.time", return_value=current_time_ms / 1000.0): | ||
| result = main.get_gemini_oauth_status() | ||
| assert result == {"status": "expired", "detail": "Expired 2 hours ago", "expiry_ms": expiry_ms} | ||
|
|
||
| def test_get_gemini_oauth_status_expired_more_than_86400s(): | ||
| current_time_ms = 1000000000000 | ||
| expiry_ms = current_time_ms - 172800000 # Expired 2 days ago (2 * 86400 * 1000 = 172800000) | ||
| mock_data = {"access_token": "test_token", "expiry_date": expiry_ms} | ||
| with patch("os.path.exists", return_value=True), \ | ||
| patch("builtins.open", mock_open(read_data=json.dumps(mock_data))), \ | ||
| patch("time.time", return_value=current_time_ms / 1000.0): | ||
| result = main.get_gemini_oauth_status() | ||
| assert result == {"status": "expired", "detail": "Expired 2 days ago", "expiry_ms": expiry_ms} | ||
|
|
||
| def test_get_gemini_oauth_status_exception(): | ||
| with patch("os.path.exists", return_value=True), \ | ||
| patch("builtins.open", side_effect=Exception("Test error")): | ||
| result = main.get_gemini_oauth_status() | ||
| assert result == {"status": "error", "detail": "Test error", "expiry_ms": 0} | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing
maindirectly at the module level will trigger the configuration loading logic inrouter/main.py(lines 261-267). If/config/config.yamldoes not exist in the environment where the tests are run (which is common in local development or CI environments),main.pywill callsys.exit(1). This causes the test runner to crash immediately during test collection.To prevent this, we can write a minimal dummy configuration to a temporary file and set the
CONFIG_PATHenvironment variable before importingmain.