Skip to content
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

Server info #89

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion mindsdb_sdk/connectors/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,11 @@ def upload_file(self, name: str, df: pd.DataFrame):
'file': fd,
}
)
_raise_for_status(r)
_raise_for_status(r)

def status(self) -> dict:

r = self.session.get(self.url + f'/api/status')
_raise_for_status(r)

return r.json()
10 changes: 10 additions & 0 deletions mindsdb_sdk/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ def __init__(self, api):
self.ml_handlers = Handlers(self.api, 'ml')
self.data_handlers = Handlers(self.api, 'data')

def status(self) -> dict:
"""
Get server information. It could content version
Example of getting version for local:
>>> print(server.status()['mindsdb_version'])

:return: server status info
"""
return self.api.status()

def __repr__(self):
return f'{self.__class__.__name__}({self.api.url})'

Expand Down
9 changes: 8 additions & 1 deletion tests/test_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ def check_table(self, table, mock_post):

class Test(BaseFlow):

@patch('requests.Session.get')
@patch('requests.Session.put')
@patch('requests.Session.post')
def test_flow(self, mock_post, mock_put):
def test_flow(self, mock_post, mock_put, mock_get):

# check local
server = mindsdb_sdk.connect()
str(server)
Expand All @@ -194,6 +196,11 @@ def test_flow(self, mock_post, mock_put):
assert call_args[0][0] == 'https://cloud.mindsdb.com/cloud/login'
assert call_args[1]['json']['email'] == '[email protected]'

# server status
server.status()
call_args = mock_get.call_args
assert call_args[0][0] == 'https://cloud.mindsdb.com/api/status'

# --------- databases -------------
response_mock(mock_post, pd.DataFrame([{'NAME': 'db1'}]))

Expand Down
Loading