Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
fix: Add workspaces.create method (#130)
Browse files Browse the repository at this point in the history
* Add workspaces.create method

* add abc for workspaces for create, add test for workspaces create

* various fixes from testing

* add regression

---------

Co-authored-by: Severin Ibarluzea <[email protected]>
  • Loading branch information
andrii-balitskyi and seveibar authored Nov 28, 2023
1 parent 71db16e commit 75713b1
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
14 changes: 14 additions & 0 deletions seamapi/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class Workspace:
workspace_id: str
name: str
is_sandbox: bool
connect_partner_name: str = None
webview_primary_button_color: str = None
webview_logo_shape: str = None


@dataclass_json
Expand Down Expand Up @@ -581,6 +584,17 @@ def list(self) -> List[Workspace]:
def get(self, workspace_id: Optional[str] = None) -> Workspace:
raise NotImplementedError

@abc.abstractmethod
def create(
self,
name: str,
connect_partner_name: str,
is_sandbox: Optional[bool] = None,
webview_primary_button_color: Optional[str] = None,
webview_logo_shape: Optional[str] = None,
) -> Workspace:
raise NotImplementedError

@abc.abstractmethod
def reset_sandbox(self) -> None:
raise NotImplementedError
Expand Down
62 changes: 62 additions & 0 deletions seamapi/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,65 @@ def reset_sandbox(self) -> None:
message="Successfully reset workspace sandbox",
ok=True,
)

@report_error
def create(
self,
name: str,
connect_partner_name: str,
is_sandbox: Optional[bool] = None,
webview_primary_button_color: Optional[str] = None,
webview_logo_shape: Optional[str] = None,
) -> Workspace:
"""Creates a workspace.
Parameters
----------
name : string
Workspace name
connect_partner_name : string
Name shown on the connect webview
is_sandbox : string, optional
If true, creates a sandbox workspace; if false, creates a production workspace. Defaults to false.
webview_primary_button_color : string, optional
The color of the primary button in the webview, represented in hex format (e.g., "#RRGGBB").
webview_logo_shape : string, optional
The shape of the logo in the webview: "circle" or "square".
Raises
------
Exception
If the API request wasn't successful.
Returns
------
Workspace
"""

create_payload = {
"workspace_name": name,
"name": name,
"connect_partner_name": connect_partner_name
}

if is_sandbox is not None:
create_payload["is_sandbox"] = is_sandbox
if webview_primary_button_color is not None:
create_payload["webview_primary_button_color"] = webview_primary_button_color
if webview_logo_shape is not None:
create_payload["webview_logo_shape"] = webview_logo_shape

res = self.seam.make_request(
"POST",
"/workspaces/create",
json=create_payload,
)
return Workspace(
workspace_id=res["workspace"]["workspace_id"],
name=res["workspace"]["name"],
is_sandbox=res["workspace"]["is_sandbox"],
connect_partner_name=res["workspace"]["connect_partner_name"],
webview_primary_button_color=res["workspace"]["webview_primary_button_color"],
webview_logo_shape=res["workspace"]["webview_logo_shape"],
)
9 changes: 9 additions & 0 deletions tests/workspaces/test_workspaces_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from seamapi import Seam


def test_workspaces_create(seam: Seam):
workspace = seam.workspaces.create(
workspace_name="Test Workspace", connect_partner_name="Example Partner"
)

assert workspace.workspace_id

0 comments on commit 75713b1

Please sign in to comment.