-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(google-drive): add scope validation for Google Drive API credent…
…ials (#667)
- Loading branch information
1 parent
1e3af5a
commit 3455e76
Showing
2 changed files
with
75 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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,39 @@ | ||
import pytest | ||
|
||
from langchain_google_community.drive import GoogleDriveLoader | ||
|
||
|
||
def test_drive_default_scope() -> None: | ||
"""Test that default scope is set correctly.""" | ||
loader = GoogleDriveLoader(folder_id="dummy_folder") | ||
assert loader.scopes == ["https://www.googleapis.com/auth/drive.file"] | ||
|
||
|
||
def test_drive_custom_scope() -> None: | ||
"""Test setting custom scope.""" | ||
custom_scopes = ["https://www.googleapis.com/auth/drive.readonly"] | ||
loader = GoogleDriveLoader(folder_id="dummy_folder", scopes=custom_scopes) | ||
assert loader.scopes == custom_scopes | ||
|
||
|
||
def test_drive_multiple_scopes() -> None: | ||
"""Test setting multiple valid scopes.""" | ||
custom_scopes = [ | ||
"https://www.googleapis.com/auth/drive.readonly", | ||
"https://www.googleapis.com/auth/drive.metadata.readonly", | ||
] | ||
loader = GoogleDriveLoader(folder_id="dummy_folder", scopes=custom_scopes) | ||
assert loader.scopes == custom_scopes | ||
|
||
|
||
def test_drive_empty_scope_list() -> None: | ||
"""Test that empty scope list raises error.""" | ||
with pytest.raises(ValueError, match="At least one scope must be provided"): | ||
GoogleDriveLoader(folder_id="dummy_folder", scopes=[]) | ||
|
||
|
||
def test_drive_invalid_scope() -> None: | ||
"""Test that invalid scope raises error.""" | ||
invalid_scopes = ["https://www.googleapis.com/auth/drive.invalid"] | ||
with pytest.raises(ValueError, match="Invalid Google Drive API scope"): | ||
GoogleDriveLoader(folder_id="dummy_folder", scopes=invalid_scopes) |