Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (C) 2022 GoodData Corporation
from __future__ import annotations

from typing import Any, Optional
from typing import Any

import attr
from gooddata_api_client.model.json_api_identity_provider_to_one_linkage import JsonApiIdentityProviderToOneLinkage
Expand All @@ -25,7 +25,7 @@ class CatalogOrganizationDocument(Base):
def client_class() -> type[JsonApiOrganizationInDocument]:
return JsonApiOrganizationInDocument

def to_api(self, oauth_client_secret: Optional[str] = None) -> JsonApiOrganizationInDocument:
def to_api(self, oauth_client_secret: str | None = None) -> JsonApiOrganizationInDocument:
dictionary = self._get_snake_dict()
if oauth_client_secret is not None:
dictionary["data"]["attributes"]["oauth_client_secret"] = oauth_client_secret
Expand All @@ -36,7 +36,7 @@ def to_api(self, oauth_client_secret: Optional[str] = None) -> JsonApiOrganizati
class CatalogOrganization(Base):
id: str
attributes: CatalogOrganizationAttributes
identity_provider_id: Optional[str] = None
identity_provider_id: str | None = None

@staticmethod
def client_class() -> type[JsonApiOrganizationIn]:
Expand All @@ -53,6 +53,8 @@ def from_api(cls, entity: dict[str, Any]) -> CatalogOrganization:
allowed_origins=safeget(ea, ["allowed_origins"]),
oauth_issuer_location=safeget(ea, ["oauth_issuer_location"]),
oauth_client_id=safeget(ea, ["oauth_client_id"]),
region=safeget(ea, ["region"]),
data_center=safeget(ea, ["data_center"]),
)

identity_provider_id = safeget(er, ["identityProvider", "data", "id"])
Expand Down Expand Up @@ -82,11 +84,13 @@ def to_api(self) -> JsonApiOrganizationIn:

@attr.s(auto_attribs=True, kw_only=True)
class CatalogOrganizationAttributes(Base):
name: Optional[str] = None
hostname: Optional[str] = None
allowed_origins: Optional[list[str]] = None
oauth_issuer_location: Optional[str] = None
oauth_client_id: Optional[str] = None
name: str | None = None
hostname: str | None = None
allowed_origins: list[str] | None = None
oauth_issuer_location: str | None = None
oauth_client_id: str | None = None
region: str | None = None
data_center: str | None = None

@staticmethod
def client_class() -> type[JsonApiOrganizationInAttributes]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,48 @@ def _default_organization_check(organization: CatalogOrganization):
assert organization.attributes.hostname == "localhost"


def test_organization_from_api_with_deployment_info():
# Test that deployment info fields are correctly extracted from API response
api_response = {
"id": "test_org",
"attributes": {
"name": "Test Organization",
"hostname": "test.example.com",
"allowed_origins": ["https://example.com"],
"region": "us-east-1",
"data_center": "aws-us",
},
}

organization = CatalogOrganization.from_api(api_response)

assert organization.id == "test_org"
assert organization.attributes.name == "Test Organization"
assert organization.attributes.hostname == "test.example.com"
assert organization.attributes.allowed_origins == ["https://example.com"]
assert organization.attributes.region == "us-east-1"
assert organization.attributes.data_center == "aws-us"


def test_organization_from_api_without_deployment_info():
# Test that organization can be created without deployment info fields
api_response = {
"id": "test_org",
"attributes": {
"name": "Test Organization",
"hostname": "test.example.com",
},
}

organization = CatalogOrganization.from_api(api_response)

assert organization.id == "test_org"
assert organization.attributes.name == "Test Organization"
assert organization.attributes.hostname == "test.example.com"
assert organization.attributes.region is None
assert organization.attributes.data_center is None


def _default_jwk(jwk_id=_default_jwk_id, alg=None, kid=None):
rsa_specification = CatalogRsaSpecification(
alg=alg if alg else "RS256",
Expand Down
Loading