Skip to content

Commit

Permalink
feat: Add test for vector search functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Devasy23 committed Jun 1, 2024
1 parent c4f777e commit f25d6ea
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions testing/test_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import base64
import logging
from unittest.mock import MagicMock, patch


import pytest
from fastapi.testclient import TestClient

from API.database import Database
from API.route import router
from API.utils import init_logging_config

init_logging_config()

def test_vector_search():
mock_result = [
{
"Name": "Test1",
"Image": "encoded_string1",
"score": 0.8
},
{
"Name": "Test2",
"Image": "encoded_string2",
"score": 0.7
}
]

mock_vector_search = MagicMock(return_value=mock_result)

with patch("API.database.Database.vector_search", mock_vector_search):
embedding = [0.1, 0.2, 0.3]
result = Database.vector_search("collection_name", embedding)

assert result == mock_result
mock_vector_search.assert_called_once_with("collection_name", embedding)

0 comments on commit f25d6ea

Please sign in to comment.