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
39 changes: 38 additions & 1 deletion pinecone/admin/resources/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions tests/unit/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Unit tests for admin resources."""
52 changes: 52 additions & 0 deletions tests/unit/admin/test_organization.py
Original file line number Diff line number Diff line change
@@ -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
)
Loading