Skip to content

Commit

Permalink
Merge pull request #2 from datastax/0.1.0
Browse files Browse the repository at this point in the history
ops fix
  • Loading branch information
kidrecursive authored Jun 7, 2021
2 parents 5c8a712 + c003d1c commit 64bd43c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
7 changes: 6 additions & 1 deletion astrapy/endpoints/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@
# limitations under the License.

from astrapy.rest import http_methods
import copy

DEFAULT_HOST = "https://api.astra.datastax.com"
PATH_PREFIX = "/v2"


class AstraOps():

def __init__(self, client=None):
self.client = client
self.client = copy.deepcopy(client)
self.client.base_url = DEFAULT_HOST
self.client.auth_header = "Authorization"
self.client.astra_application_token = f"Bearer {self.client.astra_application_token}"

def get_databases(self):
return self.client.request(method=http_methods.GET,
Expand Down
3 changes: 2 additions & 1 deletion astrapy/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ def __init__(self, astra_database_id=None,
self.astra_database_region = astra_database_region
self.astra_application_token = astra_application_token
self.base_url = f"https://{astra_database_id}-{astra_database_region}.apps.astra.datastax.com"
self.auth_header = "X-Cassandra-Token"

def request(self, method=http_methods.GET, path=None, json_data=None, url_params=None):
r = requests.request(method=method, url=f"{self.base_url}{path}",
params=url_params, json=json_data, timeout=DEFAULT_TIMEOUT,
headers={"X-Cassandra-Token": self.astra_application_token})
headers={self.auth_header: self.astra_application_token})
try:
return r.json()
except:
Expand Down
19 changes: 19 additions & 0 deletions tests/astrapy/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,22 @@ def astra_client():
@pytest.mark.it('should initialize an AstraDB REST Client')
def test_connect(astra_client):
assert type(astra_client) is AstraClient


@pytest.mark.it('should get a list of databases')
def test_get_databases(astra_client):
databases = astra_client.ops.get_databases()
assert type(databases) is list


# @pytest.mark.it('should create a database')
# def test_create_database(astra_client):
# res = astra_client.ops.create_database({
# "name": "astrapy-test-db",
# "keyspace": "astrapy_test",
# "cloudProvider": "AWS",
# "tier": "serverless",
# "capacityUnits": 1,
# "region": "us-west-2"
# })
# assert res is None

0 comments on commit 64bd43c

Please sign in to comment.