Skip to content

Commit

Permalink
Merge pull request #13 from seatsio/matti/workspace-calls
Browse files Browse the repository at this point in the history
Added workspace calls
  • Loading branch information
mroloux authored Feb 26, 2020
2 parents e501a9e + 6091884 commit 79ee05d
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 9 deletions.
3 changes: 3 additions & 0 deletions seatsio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from seatsio.httpClient import HttpClient
from seatsio.reports.usage.usageReports import UsageReports
from seatsio.subaccounts.subaccountsClient import SubaccountsClient
from seatsio.workspaces.workspacesClient import WorkspacesClient


class Client:
def __init__(self, secret_key, workspaceKey=None, base_url="https://api.seatsio.net"):
Expand All @@ -14,5 +16,6 @@ def __init__(self, secret_key, workspaceKey=None, base_url="https://api.seatsio.
self.events = EventsClient(self.http_client)
self.accounts = AccountsClient(self.http_client)
self.subaccounts = SubaccountsClient(self.http_client)
self.workspaces = WorkspacesClient(self.http_client)
self.hold_tokens = HoldTokensClient(self.http_client)
self.usage_reports = UsageReports(self.http_client)
4 changes: 3 additions & 1 deletion seatsio/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,16 @@ def __init__(self, data):
self.public_key = data.get("publicKey")
self.name = data.get("name")
self.active = data.get("active")
self.workspace = Workspace.create(data.get("workspace"))


class Workspace:

def __init__(self, data):
self.id = data.get("id")
self.name = data.get("name")
self.key = data.get("key")
self.secret_key = data.get("secretKey")
self.is_test = data.get("isTest")

@classmethod
def create(cls, param):
Expand Down
3 changes: 3 additions & 0 deletions seatsio/workspaces/UpdateWorkspaceRequest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class UpdateWorkspaceRequest:
def __init__(self, name):
self.name = name
Empty file added seatsio/workspaces/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions seatsio/workspaces/createWorkspaceRequest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class CreateWorkspaceRequest:
def __init__(self, name, is_test=None):
self.name = name
if is_test is not None:
self.isTest = is_test
32 changes: 32 additions & 0 deletions seatsio/workspaces/workspacesClient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from seatsio.domain import Workspace
from seatsio.pagination.listableObjectsClient import ListableObjectsClient
from seatsio.pagination.lister import Lister
from seatsio.pagination.pageFetcher import PageFetcher
from seatsio.workspaces.UpdateWorkspaceRequest import UpdateWorkspaceRequest
from seatsio.workspaces.createWorkspaceRequest import CreateWorkspaceRequest


class WorkspacesClient(ListableObjectsClient):

def __init__(self, http_client):
ListableObjectsClient.__init__(self, http_client, Workspace, "/workspaces")

def create(self, name, is_test=None):
response = self.http_client.url("/workspaces").post(
CreateWorkspaceRequest(name, is_test))
return Workspace(response.json())

def update(self, key, name):
self.http_client.url("/workspaces/{key}", key=key).post(
UpdateWorkspaceRequest(name))

def retrieve(self, key):
return self.http_client.url("/workspaces/{key}", key=key).get_as(Workspace)

def list(self, filter=None):
page_fetcher = PageFetcher(Workspace, self.http_client, "/workspaces")

if filter is not None:
page_fetcher.set_query_param("filter", filter)

return Lister(page_fetcher).list()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='seatsio',
version='v47',
version='v48',
description='The official Seats.io Python client library',
author='The seats.io dev team',
author_email='[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/copyChartToSubaccountTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test(self):

copied_chart = self.client.charts.copy_to_subaccount(chart.key, subaccount.id)

subaccount_client = seatsio.Client(subaccount.secret_key, None, "https://api-staging.seatsio.net")
subaccount_client = self.create_client(subaccount.secret_key, None)
assert_that(copied_chart.name).is_equal_to("my chart")
retrieved_chart = subaccount_client.charts.retrieve(copied_chart.key)
assert_that(retrieved_chart.name).is_equal_to("my chart")
Expand Down
6 changes: 5 additions & 1 deletion tests/seatsioClientTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SeatsioClientTest(unittest2.TestCase):
def setUp(self):
super(SeatsioClientTest, self).setUp()
self.user = self.create_test_user()
self.client = seatsio.Client(self.user["secretKey"], None, BASE_URL)
self.client = self.create_client(self.user["secretKey"], None)

def tearDown(self):
super(SeatsioClientTest, self).tearDown()
Expand All @@ -30,6 +30,10 @@ def create_test_user(self):
else:
raise Exception("Failed to create a test user")

@staticmethod
def create_client(secretKey, workspaceKey):
return seatsio.Client(secretKey, workspaceKey, BASE_URL)

@staticmethod
def random_email():
return str(uuid.uuid4()) + "@mailinator.com"
Expand Down
3 changes: 0 additions & 3 deletions tests/subaccounts/retrieveSubaccountTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@ def test(self):
assert_that(retrieved_subaccount.public_key).is_not_blank()
assert_that(retrieved_subaccount.name).is_equal_to("joske")
assert_that(retrieved_subaccount.active).is_true()
assert_that(retrieved_subaccount.workspace).is_not_none()
assert_that(retrieved_subaccount.workspace.id).is_not_none()
assert_that(retrieved_subaccount.workspace.key).is_not_blank()
4 changes: 2 additions & 2 deletions tests/workspaceKeyAuthenticationTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class WorkspaceKeyAuthenticationTest(SeatsioClientTest):
def test(self):
subaccount = self.client.subaccounts.create()

subaccount_client = seatsio.Client(self.user["secretKey"], subaccount.workspace.key, "https://api-staging.seatsio.net")
subaccount_client = self.create_client(self.user["secretKey"], subaccount.public_key)
hold_token = subaccount_client.hold_tokens.create()

assert_that(hold_token.workspaceKey).is_equal_to(subaccount.workspace.key)
assert_that(hold_token.workspaceKey).is_equal_to(subaccount.public_key)
Empty file added tests/workspaces/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions tests/workspaces/createWorkspaceTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from tests.seatsioClientTest import SeatsioClientTest
from tests.util.asserts import assert_that


class CreateWorkspaceTest(SeatsioClientTest):

def test_create_workspace(self):
workspace = self.client.workspaces.create("my workspace")

assert_that(workspace.id).is_not_zero()
assert_that(workspace.name).is_equal_to("my workspace")
assert_that(workspace.key).is_not_none()
assert_that(workspace.secret_key).is_not_none()
assert_that(workspace.is_test).is_false()

def test_create_test_workspace(self):
workspace = self.client.workspaces.create("my workspace", True)

assert_that(workspace.id).is_not_zero()
assert_that(workspace.name).is_equal_to("my workspace")
assert_that(workspace.key).is_not_none()
assert_that(workspace.secret_key).is_not_none()
assert_that(workspace.is_test).is_true()
23 changes: 23 additions & 0 deletions tests/workspaces/listAllWorkspacesTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from tests.seatsioClientTest import SeatsioClientTest
from tests.util.asserts import assert_that


class ListAllWorkspacesTest(SeatsioClientTest):

def test(self):
self.client.workspaces.create("ws1")
self.client.workspaces.create("ws2")
self.client.workspaces.create("ws3")

workspaces = self.client.workspaces.list()

assert_that(workspaces).extracting("name").contains_exactly("ws3", "ws2", "ws1", "Main workspace")

def test_filter(self):
self.client.workspaces.create("someWorkspace")
self.client.workspaces.create("anotherWorkspace")
self.client.workspaces.create("anotherAnotherWorkspace")

workspaces = self.client.workspaces.list("another")

assert_that(workspaces).extracting("name").contains_exactly("anotherAnotherWorkspace", "anotherWorkspace")
15 changes: 15 additions & 0 deletions tests/workspaces/retrieveWorkspaceTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from tests.seatsioClientTest import SeatsioClientTest
from tests.util.asserts import assert_that


class UpdateWorkspaceTest(SeatsioClientTest):

def test(self):
workspace = self.client.workspaces.create("my workspace")

retrieved_workspace = self.client.workspaces.retrieve(workspace.key)
assert_that(retrieved_workspace.id).is_not_zero()
assert_that(retrieved_workspace.name).is_equal_to("my workspace")
assert_that(retrieved_workspace.key).is_not_none()
assert_that(retrieved_workspace.secret_key).is_not_none()
assert_that(retrieved_workspace.is_test).is_false()
17 changes: 17 additions & 0 deletions tests/workspaces/updateWorkspaceTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from tests.seatsioClientTest import SeatsioClientTest
from tests.util.asserts import assert_that


class UpdateWorkspaceTest(SeatsioClientTest):

def test(self):
workspace = self.client.workspaces.create("my workspace")

self.client.workspaces.update(workspace.key, "my ws")

retrieved_workspace = self.client.workspaces.retrieve(workspace.key)
assert_that(retrieved_workspace.id).is_not_zero()
assert_that(retrieved_workspace.name).is_equal_to("my ws")
assert_that(retrieved_workspace.key).is_not_none()
assert_that(retrieved_workspace.secret_key).is_not_none()
assert_that(retrieved_workspace.is_test).is_false()

0 comments on commit 79ee05d

Please sign in to comment.