Skip to content

Commit

Permalink
Added using API generated by openapi-python-client
Browse files Browse the repository at this point in the history
  • Loading branch information
ckunki committed Apr 16, 2024
1 parent 284dc05 commit 72f73a7
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 8 deletions.
47 changes: 47 additions & 0 deletions exasol/saas/client/gapi.py
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)
61 changes: 53 additions & 8 deletions test/integration/generated_api_test.py
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)

0 comments on commit 72f73a7

Please sign in to comment.