Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding test cases of check qdrant collection exists! #67

Closed
wants to merge 1 commit into from
Closed
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
72 changes: 72 additions & 0 deletions tests/integration/test_qdrant_collection_available.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from unittest import TestCase

from qdrant_client import models
from tc_hivemind_backend.db.qdrant import QdrantSingleton
from utils.qdrant_utils import QDrantUtils


class TestQDrantAvailableCollection(TestCase):
def setUp(self) -> None:
self.qdrant_client = QdrantSingleton.get_instance().get_client()
collections = self.qdrant_client.get_collections()
for col in collections.collections:
self.qdrant_client.delete_collection(col.name)
self.qdrant_utils = QDrantUtils()

def test_no_collection_available(self):
collection_name = "sample_collection"
available = self.qdrant_utils.chech_collection_exist(collection_name)

self.assertIsInstance(available, bool)
self.assertFalse(available)

def test_single_collection_available(self):
collection_name = "sample_collection"
self.qdrant_client.delete_collection(collection_name)
self.qdrant_client.create_collection(
collection_name,
vectors_config=models.VectorParams(
size=100, distance=models.Distance.COSINE
),
)
available = self.qdrant_utils.chech_collection_exist(collection_name)

self.assertIsInstance(available, bool)
self.assertTrue(available)

def test_multiple_collections_but_not_input(self):
"""
test if there was multiple collections available
but it isn't the collection we want to check for
"""
collections = ["collection1", "collection2", "collection3"]
for col in collections:
self.qdrant_client.create_collection(
col,
vectors_config=models.VectorParams(
size=100, distance=models.Distance.COSINE
),
)

available = self.qdrant_utils.chech_collection_exist("sample_collection")

self.assertIsInstance(available, bool)
self.assertFalse(available)

def test_multiple_collections_available_given_input(self):
"""
test multiple collections available with given input
"""
collections = ["collection1", "collection2", "collection3"]
for col in collections:
self.qdrant_client.create_collection(
col,
vectors_config=models.VectorParams(
size=100, distance=models.Distance.COSINE
),
)

available = self.qdrant_utils.chech_collection_exist("collection1")

self.assertIsInstance(available, bool)
self.assertTrue(available)
12 changes: 12 additions & 0 deletions utils/qdrant_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from tc_hivemind_backend.db.qdrant import QdrantSingleton


class QDrantUtils:
def __init__(self) -> None:
self.qdrant_client = QdrantSingleton.get_instance().get_client()

def chech_collection_exist(self, collection_name: str) -> bool:
"""
check if the collection exist on qdrant database
"""
pass
Loading