-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for namespace operations
- Loading branch information
Showing
5 changed files
with
179 additions
and
2 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,63 @@ | ||
import pytest | ||
|
||
from tests import NAMESPACES, ensure_ns_exists, ensure_ns_exists_async | ||
from upstash_vector import Index, AsyncIndex | ||
from upstash_vector.core.index_operations import DEFAULT_NAMESPACE | ||
|
||
|
||
def test_list_namespaces(index: Index): | ||
for ns in NAMESPACES: | ||
ensure_ns_exists(index, ns) | ||
|
||
all_ns = index.list_namespaces() | ||
|
||
assert len(all_ns) == len(NAMESPACES) | ||
assert NAMESPACES[0] in all_ns | ||
assert NAMESPACES[1] in all_ns | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_list_namespaces_async(async_index: AsyncIndex): | ||
for ns in NAMESPACES: | ||
await ensure_ns_exists_async(async_index, ns) | ||
|
||
all_ns = await async_index.list_namespaces() | ||
|
||
assert len(all_ns) == len(NAMESPACES) | ||
assert NAMESPACES[0] in all_ns | ||
assert NAMESPACES[1] in all_ns | ||
|
||
|
||
def test_delete_namespaces(index: Index): | ||
for ns in NAMESPACES: | ||
ensure_ns_exists(index, ns) | ||
|
||
for ns in NAMESPACES: | ||
if ns == DEFAULT_NAMESPACE: | ||
continue | ||
|
||
# Should not fail | ||
index.delete_namespace(namespace=ns) | ||
|
||
info = index.info() | ||
|
||
# Only default namespace should exist | ||
assert len(info.namespaces) == 1 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_delete_namespaces_async(async_index: AsyncIndex): | ||
for ns in NAMESPACES: | ||
await ensure_ns_exists_async(async_index, ns) | ||
|
||
for ns in NAMESPACES: | ||
if ns == DEFAULT_NAMESPACE: | ||
continue | ||
|
||
# Should not fail | ||
await async_index.delete_namespace(namespace=ns) | ||
|
||
info = await async_index.info() | ||
|
||
# Only default namespace should exist | ||
assert len(info.namespaces) == 1 |
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