Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/test_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ class TestPortal(object):
def setup(self, set_api_key):
self.portal = Portal()

@pytest.fixture
def mock_organization(self):
return {
"name": "Test Organization",
"object": "organization",
"id": "org_01EHT88Z8J8795GZNQ4ZP1J81T",
"domains": [
{
"domain": "example.com",
"object": "organization_domain",
"id": "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8",
}
],
}

@pytest.fixture
def mock_organizations(self):
return {
Expand Down Expand Up @@ -45,6 +60,19 @@ def mock_organizations(self):
"listMetadata": {"before": "before-id", "after": None},
}

def test_create_organization(self, mock_organization, mock_request_method):
organization = {"domains": ["example.com"], "name": "Test Organization"}
mock_response = Response()
mock_response.status_code = 201
mock_response.response_dict = mock_organization
mock_request_method("post", mock_response, 201)

result = self.portal.create_organization(organization)
subject = result.response_dict

assert subject["id"] == "org_01EHT88Z8J8795GZNQ4ZP1J81T"
assert subject["name"] == "Test Organization"

def test_list_organizations(self, mock_organizations, mock_request_method):
mock_response = Response()
mock_response.status_code = 200
Expand Down
23 changes: 21 additions & 2 deletions workos/portal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import workos
from workos.utils.request import RequestHelper, REQUEST_METHOD_GET
from workos.utils.request import RequestHelper, REQUEST_METHOD_GET, REQUEST_METHOD_POST
from workos.utils.validation import PORTAL_MODULE, validate_settings

ORGANIZATIONS_PATH = "organizations"
RESPONSE_LIMIT = 10


Expand All @@ -16,6 +17,24 @@ def request_helper(self):
self._request_helper = RequestHelper()
return self._request_helper

def create_organization(self, organization):
"""Create an organization

Args:
organization (dict) - An organization object
organization[domains] (list) - List of domains that belong to the organization
organization[name] (str) - A unique, descriptive name for the organization

Returns:
dict: Created Organization response from WorkOS.
"""
return self.request_helper.request(
ORGANIZATIONS_PATH,
method=REQUEST_METHOD_POST,
params=organization,
token=workos.api_key,
)

def list_organizations(
self, domains=None, limit=RESPONSE_LIMIT, before=None, after=None
):
Expand All @@ -37,7 +56,7 @@ def list_organizations(
"after": after,
}
return self.request_helper.request(
"organizations",
ORGANIZATIONS_PATH,
method=REQUEST_METHOD_GET,
params=params,
token=workos.api_key,
Expand Down