-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
125 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from pinecone.core.openapi.control.models import IndexModel as OpenAPIIndexModel | ||
|
||
class IndexModel: | ||
def __init__(self, index: OpenAPIIndexModel): | ||
self.index = index | ||
self.deletion_protection = index.deletion_protection.value | ||
|
||
def __str__(self): | ||
return str(self.index) | ||
|
||
def __repr__(self): | ||
return repr(self.index) | ||
|
||
def __getattr__(self, attr): | ||
return getattr(self.index, attr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
from pinecone import PodSpec | ||
|
||
class TestDeletionProtection: | ||
def test_deletion_protection(self, client, index_name, environment): | ||
client.create_index(name=index_name, dimension=2, deletion_protection="enabled", spec=PodSpec(environment=environment)) | ||
desc = client.describe_index(index_name) | ||
print(desc.deletion_protection) | ||
print(desc.deletion_protection.__class__) | ||
assert desc.deletion_protection == "enabled" | ||
|
||
with pytest.raises(Exception) as e: | ||
client.delete_index(index_name) | ||
assert "Deletion protection is enabled for this index" in str(e.value) | ||
|
||
client.configure_index(index_name, deletion_protection="disabled") | ||
desc = client.describe_index(index_name) | ||
assert desc.deletion_protection == "disabled" | ||
|
||
client.delete_index(index_name) | ||
|
||
def test_configure_index_with_deletion_protection(self, client, index_name, environment): | ||
client.create_index(name=index_name, dimension=2, deletion_protection="enabled", spec=PodSpec(environment=environment)) | ||
desc = client.describe_index(index_name) | ||
assert desc.deletion_protection == "enabled" | ||
|
||
# Changing replicas only should not change deletion protection | ||
client.configure_index(name=index_name, replicas=2) | ||
desc = client.describe_index(index_name) | ||
assert desc.spec.pod.replicas == 2 | ||
assert desc.deletion_protection == "enabled" | ||
|
||
# Changing both replicas and delete protection in one shot | ||
client.configure_index(name=index_name, replicas=3, deletion_protection="disabled") | ||
desc = client.describe_index(index_name) | ||
assert desc.spec.pod.replicas == 3 | ||
assert desc.deletion_protection == "disabled" | ||
|
||
# Cleanup | ||
client.delete_index(index_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
tests/integration/control/serverless/test_deletion_protection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import pytest | ||
|
||
class TestDeletionProtection: | ||
def test_deletion_protection(self, client, create_sl_index_params): | ||
name = create_sl_index_params["name"] | ||
client.create_index(**create_sl_index_params, deletion_protection=True) | ||
desc = client.describe_index(name) | ||
assert desc.deletion_protection == "enabled" | ||
|
||
with pytest.raises(Exception) as e: | ||
client.delete_index(name) | ||
assert "Deletion protection is enabled for this index" in str(e.value) | ||
|
||
client.configure_index(name, deletion_protection=False) | ||
desc = client.describe_index(name) | ||
assert desc.deletion_protection == "disabled" | ||
|
||
client.delete_index(name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters