Skip to content

Commit

Permalink
feat: Adding get-index API (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
adilansari authored May 24, 2023
1 parent a8d2e76 commit 96d24c9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from unittest import TestCase
from unittest.mock import patch

from tigrisdb.search import Search
from tigrisdb.types import ClientConfig


@patch("api.generated.server.v1.search_pb2_grpc.SearchStub")
class SearchTest(TestCase):
def setUp(self) -> None:
self.client_config = ClientConfig(
server_url="localhost:5000", project_name="db1"
)

def test_get_index(self, grpc_search):
mock_grpc = grpc_search()
search = Search(mock_grpc, self.client_config)
search_index = search.get_index("test-index")

self.assertEqual("test-index", search_index.name)
self.assertEqual(self.client_config.project_name, search_index.project)
3 changes: 3 additions & 0 deletions tigrisdb/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ def delete_index(self, name: str) -> bool:
raise TigrisServerError("failed to delete search index", e)

return resp.status == "deleted"

def get_index(self, name: str) -> SearchIndex:
return SearchIndex(index_name=name, client=self.__client, config=self.__config)

0 comments on commit 96d24c9

Please sign in to comment.