Skip to content

Commit 158193a

Browse files
authored
feat: Add function to list organization domains (#290)
1 parent 9b3a5de commit 158193a

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

cloudfoundry_client/v3/organizations.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import TYPE_CHECKING
22

3+
from cloudfoundry_client.common_objects import Pagination
34
from cloudfoundry_client.v3.entities import EntityManager, Entity, ToOneRelationship
45

56
if TYPE_CHECKING:
@@ -47,6 +48,10 @@ def get_default_isolation_segment(self, guid: str) -> ToOneRelationship:
4748
super().get(guid, "relationships", "default_isolation_segment")
4849
)
4950

51+
def list_domains(self, guid: str, **kwargs) -> Pagination[Entity]:
52+
uri: str = "%s/%s/domains" % (self.entity_uri, guid)
53+
return super()._list(requested_path=uri, **kwargs)
54+
5055
def get_default_domain(self, guid: str) -> Entity:
5156
return super().get(guid, "domains", "default")
5257

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"pagination": {
3+
"total_results": 1,
4+
"total_pages": 1,
5+
"first": {
6+
"href": "https://api.example.org/v3/organizations/016b770b-b447-4a12-800a-1b4c69406a9f/domains?page=1&per_page=50"
7+
},
8+
"last": {
9+
"href": "https://api.example.org/v3/organizations/016b770b-b447-4a12-800a-1b4c69406a9f/domains?page=1&per_page=50"
10+
},
11+
"next": null,
12+
"previous": null
13+
},
14+
"resources": [
15+
{
16+
"guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5",
17+
"created_at": "2019-03-08T01:06:19Z",
18+
"updated_at": "2019-03-08T01:06:19Z",
19+
"name": "test-domain.com",
20+
"internal": false,
21+
"router_group": { "guid": "5806148f-cce6-4d86-7fbd-aa269e3f6f3f" },
22+
"supported_protocols": ["tcp"],
23+
"metadata": {
24+
"labels": {},
25+
"annotations": {}
26+
},
27+
"relationships": {
28+
"organization": {
29+
"data": null
30+
},
31+
"shared_organizations": {
32+
"data": []
33+
}
34+
},
35+
"links": {
36+
"self": {
37+
"href": "https://api.example.org/v3/domains/016b770b-b447-4a12-800a-1b4c69406a9f"
38+
},
39+
"route_reservations": {
40+
"href": "https://api.example.org/v3/domains/016b770b-b447-4a12-800a-1b4c69406a9f/route_reservations"
41+
},
42+
"router_group": {
43+
"href": "https://api.example.org/routing/v1/router_groups/5806148f-cce6-4d86-7fbd-aa269e3f6f3f"
44+
}
45+
}
46+
}
47+
]
48+
}

tests/v3/test_organizations.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import cloudfoundry_client.main.main as main
77
from abstract_test_case import AbstractTestCase
8+
9+
from cloudfoundry_client.common_objects import Pagination
810
from cloudfoundry_client.v3.entities import Entity, ToOneRelationship
911

1012

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

149+
def test_get_domains(self):
150+
self.client.get.return_value = self.mock_response(
151+
"/v3/organizations/organization_id/domains",
152+
HTTPStatus.OK,
153+
{"Content-Type": "application/json"},
154+
"v3",
155+
"organizations",
156+
"GET_{id}_domains_response.json",
157+
)
158+
organization_domains_response: Pagination[Entity] = self.client.v3.organizations.list_domains("organization_id")
159+
domains: list[dict] = [domain for domain in organization_domains_response]
160+
print(domains)
161+
self.assertIsInstance(domains, list)
162+
self.assertEqual(len(domains), 1)
163+
domain: dict = domains[0]
164+
self.assertIsInstance(domain, dict)
165+
self.assertEqual(domain.get("guid"), "3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
166+
self.assertEqual(domain.get("name"), "test-domain.com")
167+
147168
@patch.object(sys, "argv", ["main", "list_organizations"])
148169
def test_main_list_organizations(self):
149170
with patch("cloudfoundry_client.main.main.build_client_from_configuration", new=lambda: self.client):

0 commit comments

Comments
 (0)