From ab335b7227f15ae934726fa693f7a465498c41fa Mon Sep 17 00:00:00 2001 From: Jen Hamon Date: Sat, 15 Nov 2025 15:07:03 -0500 Subject: [PATCH] Delete org --- pinecone/admin/resources/organization.py | 39 +++++++++++++++++- tests/unit/admin/__init__.py | 1 + tests/unit/admin/test_organization.py | 52 ++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 tests/unit/admin/__init__.py create mode 100644 tests/unit/admin/test_organization.py diff --git a/pinecone/admin/resources/organization.py b/pinecone/admin/resources/organization.py index 79bc3fb5..9e2421a2 100644 --- a/pinecone/admin/resources/organization.py +++ b/pinecone/admin/resources/organization.py @@ -7,7 +7,7 @@ class OrganizationResource: """ - This class is used to list, fetch, and update organizations. + This class is used to list, fetch, update, and delete organizations. .. note:: The class should not be instantiated directly. Instead, access this classes @@ -191,3 +191,40 @@ def update(self, organization_id: str, name: Optional[str] = None): return self._organizations_api.update_organization( organization_id=organization_id, update_organization_request=update_request ) + + @require_kwargs + def delete(self, organization_id: str): + """ + Delete an organization by organization_id. + + .. warning:: + Deleting an organization is a permanent and irreversible operation. + Please be very sure you want to delete the organization and everything + associated with it before calling this function. + + Before deleting an organization, you must delete all projects (including indexes, + assistants, backups, and collections) associated with the organization. + + :param organization_id: The organization_id of the organization to delete. + :type organization_id: str + :return: ``None`` + + Examples + -------- + + .. code-block:: python + :caption: Delete an organization by organization_id + :emphasize-lines: 7-9 + + from pinecone import Admin + + # Credentials read from PINECONE_CLIENT_ID and + # PINECONE_CLIENT_SECRET environment variables + admin = Admin() + + admin.organization.delete( + organization_id="42ca341d-43bf-47cb-9f27-e645dbfabea6" + ) + + """ + return self._organizations_api.delete_organization(organization_id=organization_id) diff --git a/tests/unit/admin/__init__.py b/tests/unit/admin/__init__.py new file mode 100644 index 00000000..d973fe73 --- /dev/null +++ b/tests/unit/admin/__init__.py @@ -0,0 +1 @@ +"""Unit tests for admin resources.""" diff --git a/tests/unit/admin/test_organization.py b/tests/unit/admin/test_organization.py new file mode 100644 index 00000000..e2804bbb --- /dev/null +++ b/tests/unit/admin/test_organization.py @@ -0,0 +1,52 @@ +"""Unit tests for OrganizationResource delete method. + +These tests verify that the delete() method correctly builds and passes requests +to the underlying API client without making real API calls. +""" + +import pytest + +from pinecone.admin.resources.organization import OrganizationResource +from pinecone.openapi_support import ApiClient + + +class TestOrganizationResourceDelete: + """Test parameter translation in OrganizationResource.delete()""" + + def setup_method(self): + """Set up test fixtures""" + api_client = ApiClient() + self.organization_resource = OrganizationResource(api_client=api_client) + + def test_delete_calls_api_with_organization_id(self, mocker): + """Test delete() calls the API method with correct organization_id""" + mocker.patch.object( + self.organization_resource._organizations_api, "delete_organization", autospec=True + ) + + organization_id = "test-org-id-123" + self.organization_resource.delete(organization_id=organization_id) + + # Verify API was called with correct arguments + self.organization_resource._organizations_api.delete_organization.assert_called_once_with( + organization_id=organization_id + ) + + def test_delete_requires_organization_id(self): + """Test that delete() requires organization_id parameter via @require_kwargs""" + with pytest.raises(TypeError): + self.organization_resource.delete() + + def test_delete_with_different_organization_id(self, mocker): + """Test delete() with a different organization_id value""" + mocker.patch.object( + self.organization_resource._organizations_api, "delete_organization", autospec=True + ) + + organization_id = "another-org-id-456" + self.organization_resource.delete(organization_id=organization_id) + + # Verify API was called with the specific organization_id + self.organization_resource._organizations_api.delete_organization.assert_called_once_with( + organization_id=organization_id + )