-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added using API generated by openapi-python-client
- Loading branch information
Showing
2 changed files
with
100 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import json | ||
|
||
from typing import Iterable | ||
from exasol.saas.client.api import Database | ||
|
||
from exasol.saas.client import model | ||
|
||
from exasol.saas.client.model import ( | ||
generated, | ||
SAAS_HOST, | ||
) | ||
from exasol.saas.client.model.generated.api.databases import list_databases | ||
from exasol.saas.client.model.generated.api.databases import create_database | ||
# from exasol.saas.client.model.generated.api import databases | ||
|
||
|
||
class Session: | ||
""" | ||
Session for interacting with an Exasol SaaS instance. | ||
""" | ||
|
||
def __init__(self, token: str, account_id: str): | ||
self._token = token | ||
self._account = account_id | ||
self._client = generated.AuthenticatedClient( | ||
base_url=SAAS_HOST, | ||
token=token, | ||
) | ||
|
||
def databases(self) -> Iterable[Database]: | ||
"""List existing databases""" | ||
response = list_databases.sync_detailed(self._account, client=self._client) | ||
return ( Database(self, x) for x in json.loads(response.content) ) | ||
|
||
def create_database(self, name: str) -> Database: | ||
"""Create a new database.""" | ||
db = create_database( | ||
self._account, | ||
client=self._client, | ||
body=generated.models.CreateDatabase( | ||
name=name, | ||
initial_cluster=model.ClusterSpec(name="my-cluster"), | ||
provider="aws", | ||
region='us-east-1', | ||
) | ||
) | ||
return None # Database(self, db) |
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 |
---|---|---|
@@ -1,17 +1,62 @@ | ||
import os | ||
import json | ||
import os | ||
import pytest | ||
|
||
from exasol.saas.client import gapi | ||
from exasol.saas.client.model import generated | ||
from exasol.saas.client.model.generated.api.databases import list_databases | ||
from exasol.saas.client.model.generated.api.databases import create_database | ||
from exasol.saas.client.model import SAAS_API, SAAS_HOST | ||
|
||
def test_databases_list_client(): | ||
auth = generated.AuthenticatedClient( | ||
|
||
@pytest.fixture | ||
def saas_client(): | ||
return generated.AuthenticatedClient( | ||
base_url=SAAS_HOST, | ||
token=os.environ["SAAS_PAT"], | ||
) | ||
with auth as client: | ||
account_id = os.environ["SAAS_ACCOUNT_ID"] | ||
dbs = list_databases.sync_detailed(account_id, client=client) | ||
c = json.loads(dbs.content) | ||
print(f'{json.dumps(c, indent=4)}') | ||
|
||
|
||
@pytest.fixture | ||
def saas_session(): | ||
return gapi.Session( | ||
os.environ["SAAS_PAT"], | ||
os.environ["SAAS_ACCOUNT_ID"], | ||
) | ||
|
||
|
||
def pretty_print_response(response): | ||
c = json.loads(response.content) | ||
print(f'{json.dumps(c, indent=4)}') | ||
|
||
|
||
def test_databases_list_raw(saas_client): | ||
account_id = os.environ["SAAS_ACCOUNT_ID"] | ||
response = list_databases.sync_detailed(account_id, client=saas_client) | ||
print(f'{response}') | ||
# pretty_print_response(response) | ||
|
||
|
||
def test_databases_list(saas_session): | ||
dbs = saas_session.databases() | ||
for db in dbs: | ||
print(f'{db}') | ||
|
||
|
||
def test_database_create_raw(saas_client): | ||
account_id = os.environ["SAAS_ACCOUNT_ID"] | ||
cluster_spec = generated.models.CreateCluster( | ||
name="my-cluster", | ||
size="XS", | ||
) | ||
response = create_database.sync_detailed( | ||
account_id, | ||
client=saas_client, | ||
body=generated.models.CreateDatabase( | ||
name="my-name", | ||
initial_cluster=cluster_spec, | ||
provider="aws", | ||
region='us-east-1', | ||
) | ||
) | ||
pretty_print_response(response) |