mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Rename session file (#5771)
* rename session file * rename method * Update README.md * placed as note * revert readme change --------- Co-authored-by: Pratyush Shukla <ps4534@nyu.edu>
This commit is contained in:
3
openbb_platform/README.md
vendored
3
openbb_platform/README.md
vendored
@@ -66,6 +66,9 @@ Set your keys at [OpenBB Hub](https://my.openbb.co/app/sdk/api-keys) and get you
|
||||
```python
|
||||
>>> from openbb import obb
|
||||
>>> openbb.account.login(pat="OPENBB_PAT")
|
||||
|
||||
>>> # Persist changes in OpenBB Hub
|
||||
>>> obb.account.save()
|
||||
```
|
||||
|
||||
### 2. Runtime
|
||||
|
||||
@@ -51,7 +51,7 @@ class HubService:
|
||||
self._session = self._get_session_from_email_password(email, password)
|
||||
return self._session
|
||||
if pat:
|
||||
self._session = self._get_session_from_sdk_token(pat)
|
||||
self._session = self._get_session_from_platform_token(pat)
|
||||
return self._session
|
||||
raise OpenBBError("Please provide 'email' and 'password' or 'pat'")
|
||||
|
||||
@@ -123,7 +123,7 @@ class HubService:
|
||||
detail = response.json().get("detail", None)
|
||||
raise HTTPException(status_code, detail)
|
||||
|
||||
def _get_session_from_sdk_token(self, token: str) -> HubSession:
|
||||
def _get_session_from_platform_token(self, token: str) -> HubSession:
|
||||
"""Get session from Platform personal access token."""
|
||||
if not token:
|
||||
raise OpenBBError("Platform personal access token not found.")
|
||||
|
||||
@@ -23,6 +23,8 @@ class Account:
|
||||
save
|
||||
refresh"""
|
||||
|
||||
SESSION_FILE = ".hub_session.json"
|
||||
|
||||
def __init__(self, base_app: "BaseApp"):
|
||||
self._base_app = base_app
|
||||
self._openbb_directory = (
|
||||
@@ -66,7 +68,7 @@ class Account:
|
||||
) -> HubService:
|
||||
"""Create hub service to handle connection."""
|
||||
if email is None and password is None and pat is None:
|
||||
session_file = Path(self._openbb_directory, ".sdk_hub_session.json")
|
||||
session_file = Path(self._openbb_directory, self.SESSION_FILE)
|
||||
if not session_file.exists():
|
||||
raise OpenBBError("Session not found.")
|
||||
|
||||
@@ -112,7 +114,7 @@ class Account:
|
||||
self._base_app._command_runner.user_settings = updated
|
||||
if remember_me:
|
||||
Path(self._openbb_directory).mkdir(parents=False, exist_ok=True)
|
||||
session_file = Path(self._openbb_directory, ".sdk_hub_session.json")
|
||||
session_file = Path(self._openbb_directory, self.SESSION_FILE)
|
||||
with open(session_file, "w") as f:
|
||||
if not hs.session:
|
||||
raise OpenBBError("Not connected to hub.")
|
||||
@@ -178,7 +180,7 @@ class Account:
|
||||
hs = HubService(hub_session)
|
||||
hs.disconnect()
|
||||
|
||||
session_file = Path(self._openbb_directory, ".sdk_hub_session.json")
|
||||
session_file = Path(self._openbb_directory, self.SESSION_FILE)
|
||||
if session_file.exists():
|
||||
session_file.unlink()
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ def test_connect_with_sdk_token():
|
||||
with patch(
|
||||
"requests.post", return_value=MagicMock(status_code=200, json=lambda: {})
|
||||
), patch.object(
|
||||
HubService, "_get_session_from_sdk_token", return_value=mock_hub_session
|
||||
HubService, "_get_session_from_platform_token", return_value=mock_hub_session
|
||||
):
|
||||
hub_service = HubService()
|
||||
result = hub_service.connect(pat="pat")
|
||||
@@ -86,7 +86,7 @@ def test_get_session_from_email_password():
|
||||
assert isinstance(result, HubSession)
|
||||
|
||||
|
||||
def test_get_session_from_sdk_token():
|
||||
def test_get_session_from_platform_token():
|
||||
"""Test get session from Platform personal access token."""
|
||||
|
||||
with patch(
|
||||
@@ -112,7 +112,7 @@ def test_get_session_from_sdk_token():
|
||||
"-JLZnFzyJ6dlHBZnkjQT2tfaaefxnTdAlSmToQwxGykvuatmI7L0wztPQ"
|
||||
)
|
||||
|
||||
result = HubService()._get_session_from_sdk_token(mock_token)
|
||||
result = HubService()._get_session_from_platform_token(mock_token)
|
||||
assert isinstance(result, HubSession)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user