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
5 changes: 5 additions & 0 deletions cloudfoundry_client/v3/organizations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import TYPE_CHECKING

from cloudfoundry_client.common_objects import Pagination
from cloudfoundry_client.v3.entities import EntityManager, Entity, ToOneRelationship

if TYPE_CHECKING:
Expand Down Expand Up @@ -47,6 +48,10 @@ def get_default_isolation_segment(self, guid: str) -> ToOneRelationship:
super().get(guid, "relationships", "default_isolation_segment")
)

def list_domains(self, guid: str, **kwargs) -> Pagination[Entity]:
uri: str = "%s/%s/domains" % (self.entity_uri, guid)
return super()._list(requested_path=uri, **kwargs)

def get_default_domain(self, guid: str) -> Entity:
return super().get(guid, "domains", "default")

Expand Down
48 changes: 48 additions & 0 deletions tests/fixtures/v3/organizations/GET_{id}_domains_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"pagination": {
"total_results": 1,
"total_pages": 1,
"first": {
"href": "https://api.example.org/v3/organizations/016b770b-b447-4a12-800a-1b4c69406a9f/domains?page=1&per_page=50"
},
"last": {
"href": "https://api.example.org/v3/organizations/016b770b-b447-4a12-800a-1b4c69406a9f/domains?page=1&per_page=50"
},
"next": null,
"previous": null
},
"resources": [
{
"guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5",
"created_at": "2019-03-08T01:06:19Z",
"updated_at": "2019-03-08T01:06:19Z",
"name": "test-domain.com",
"internal": false,
"router_group": { "guid": "5806148f-cce6-4d86-7fbd-aa269e3f6f3f" },
"supported_protocols": ["tcp"],
"metadata": {
"labels": {},
"annotations": {}
},
"relationships": {
"organization": {
"data": null
},
"shared_organizations": {
"data": []
}
},
"links": {
"self": {
"href": "https://api.example.org/v3/domains/016b770b-b447-4a12-800a-1b4c69406a9f"
},
"route_reservations": {
"href": "https://api.example.org/v3/domains/016b770b-b447-4a12-800a-1b4c69406a9f/route_reservations"
},
"router_group": {
"href": "https://api.example.org/routing/v1/router_groups/5806148f-cce6-4d86-7fbd-aa269e3f6f3f"
}
}
}
]
}
21 changes: 21 additions & 0 deletions tests/v3/test_organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import cloudfoundry_client.main.main as main
from abstract_test_case import AbstractTestCase

from cloudfoundry_client.common_objects import Pagination
from cloudfoundry_client.v3.entities import Entity, ToOneRelationship


Expand Down Expand Up @@ -144,6 +146,25 @@ def test_get_usage_summary(self):
self.client.v3.organizations.get_usage_summary("organization_id")
self.client.get.assert_called_with(self.client.get.return_value.url)

def test_get_domains(self):
self.client.get.return_value = self.mock_response(
"/v3/organizations/organization_id/domains",
HTTPStatus.OK,
{"Content-Type": "application/json"},
"v3",
"organizations",
"GET_{id}_domains_response.json",
)
organization_domains_response: Pagination[Entity] = self.client.v3.organizations.list_domains("organization_id")
domains: list[dict] = [domain for domain in organization_domains_response]
print(domains)
self.assertIsInstance(domains, list)
self.assertEqual(len(domains), 1)
domain: dict = domains[0]
self.assertIsInstance(domain, dict)
self.assertEqual(domain.get("guid"), "3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
self.assertEqual(domain.get("name"), "test-domain.com")

@patch.object(sys, "argv", ["main", "list_organizations"])
def test_main_list_organizations(self):
with patch("cloudfoundry_client.main.main.build_client_from_configuration", new=lambda: self.client):
Expand Down
Loading