diff --git a/cloudfoundry_client/v3/organizations.py b/cloudfoundry_client/v3/organizations.py index 2c889e6..2b22cc2 100644 --- a/cloudfoundry_client/v3/organizations.py +++ b/cloudfoundry_client/v3/organizations.py @@ -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: @@ -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") diff --git a/tests/fixtures/v3/organizations/GET_{id}_domains_response.json b/tests/fixtures/v3/organizations/GET_{id}_domains_response.json new file mode 100644 index 0000000..92e6fd4 --- /dev/null +++ b/tests/fixtures/v3/organizations/GET_{id}_domains_response.json @@ -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" + } + } + } + ] +} \ No newline at end of file diff --git a/tests/v3/test_organizations.py b/tests/v3/test_organizations.py index e8c3f73..e1b90dd 100644 --- a/tests/v3/test_organizations.py +++ b/tests/v3/test_organizations.py @@ -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 @@ -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):