Skip to content

Commit 7a4fa20

Browse files
authored
Expose delete organization function (#543)
# Expose delete organization function ## Summary Exposes the `delete_organization` endpoint through the public `OrganizationResource` interface. This endpoint was available in the generated OpenAPI client but was not accessible through the public SDK API. ## Changes ### Implementation - Added `delete()` method to `OrganizationResource` class in `pinecone/admin/resources/organization.py` - Method follows the same pattern as `ApiKeyResource.delete()` and `ProjectResource.delete()` - Includes `@require_kwargs` decorator for parameter validation - Added RST-formatted docstring with warning about permanent deletion - Updated class docstring to mention delete functionality ### Testing Added comprehensive unit tests in `tests/unit/admin/test_organization.py`: - **Request verification**: Tests verify that `delete()` correctly calls the underlying API method with the correct `organization_id` parameter - **Parameter validation**: Tests verify that `@require_kwargs` enforces the required `organization_id` parameter - **Edge cases**: Tests with different `organization_id` values to ensure proper parameter passing All tests use mocks to verify request building without making real API calls. ## Usage Example ```python from pinecone import Admin admin = Admin() # Delete an organization admin.organization.delete( organization_id="42ca341d-43bf-47cb-9f27-e645dbfabea6" ) ``` ## Backward Compatibility ✅ Fully backward compatible. This is a new method addition that does not modify existing functionality. ## Files Changed - `pinecone/admin/resources/organization.py` - Added `delete()` method - `tests/unit/admin/test_organization.py` - New file with unit tests - `tests/unit/admin/__init__.py` - New file for package structure ## Related This addresses the gap identified in `ENDPOINT_COVERAGE_AUDIT_RESULTS.md` where `delete_organization` was marked as missing from the public interface. The endpoint was available in `pinecone/core/openapi/admin/api/organizations_api.py` but not exposed through `OrganizationResource`.
1 parent b1f3151 commit 7a4fa20

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

pinecone/admin/resources/organization.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class OrganizationResource:
99
"""
10-
This class is used to list, fetch, and update organizations.
10+
This class is used to list, fetch, update, and delete organizations.
1111
1212
.. note::
1313
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):
191191
return self._organizations_api.update_organization(
192192
organization_id=organization_id, update_organization_request=update_request
193193
)
194+
195+
@require_kwargs
196+
def delete(self, organization_id: str):
197+
"""
198+
Delete an organization by organization_id.
199+
200+
.. warning::
201+
Deleting an organization is a permanent and irreversible operation.
202+
Please be very sure you want to delete the organization and everything
203+
associated with it before calling this function.
204+
205+
Before deleting an organization, you must delete all projects (including indexes,
206+
assistants, backups, and collections) associated with the organization.
207+
208+
:param organization_id: The organization_id of the organization to delete.
209+
:type organization_id: str
210+
:return: ``None``
211+
212+
Examples
213+
--------
214+
215+
.. code-block:: python
216+
:caption: Delete an organization by organization_id
217+
:emphasize-lines: 7-9
218+
219+
from pinecone import Admin
220+
221+
# Credentials read from PINECONE_CLIENT_ID and
222+
# PINECONE_CLIENT_SECRET environment variables
223+
admin = Admin()
224+
225+
admin.organization.delete(
226+
organization_id="42ca341d-43bf-47cb-9f27-e645dbfabea6"
227+
)
228+
229+
"""
230+
return self._organizations_api.delete_organization(organization_id=organization_id)

tests/unit/admin/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Unit tests for admin resources."""
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""Unit tests for OrganizationResource delete method.
2+
3+
These tests verify that the delete() method correctly builds and passes requests
4+
to the underlying API client without making real API calls.
5+
"""
6+
7+
import pytest
8+
9+
from pinecone.admin.resources.organization import OrganizationResource
10+
from pinecone.openapi_support import ApiClient
11+
12+
13+
class TestOrganizationResourceDelete:
14+
"""Test parameter translation in OrganizationResource.delete()"""
15+
16+
def setup_method(self):
17+
"""Set up test fixtures"""
18+
api_client = ApiClient()
19+
self.organization_resource = OrganizationResource(api_client=api_client)
20+
21+
def test_delete_calls_api_with_organization_id(self, mocker):
22+
"""Test delete() calls the API method with correct organization_id"""
23+
mocker.patch.object(
24+
self.organization_resource._organizations_api, "delete_organization", autospec=True
25+
)
26+
27+
organization_id = "test-org-id-123"
28+
self.organization_resource.delete(organization_id=organization_id)
29+
30+
# Verify API was called with correct arguments
31+
self.organization_resource._organizations_api.delete_organization.assert_called_once_with(
32+
organization_id=organization_id
33+
)
34+
35+
def test_delete_requires_organization_id(self):
36+
"""Test that delete() requires organization_id parameter via @require_kwargs"""
37+
with pytest.raises(TypeError):
38+
self.organization_resource.delete()
39+
40+
def test_delete_with_different_organization_id(self, mocker):
41+
"""Test delete() with a different organization_id value"""
42+
mocker.patch.object(
43+
self.organization_resource._organizations_api, "delete_organization", autospec=True
44+
)
45+
46+
organization_id = "another-org-id-456"
47+
self.organization_resource.delete(organization_id=organization_id)
48+
49+
# Verify API was called with the specific organization_id
50+
self.organization_resource._organizations_api.delete_organization.assert_called_once_with(
51+
organization_id=organization_id
52+
)

0 commit comments

Comments
 (0)