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

Align get_indexes() with API spec #114

Draft
wants to merge 1 commit into
base: mainline
Choose a base branch
from
Draft
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
9 changes: 3 additions & 6 deletions src/marqo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,15 @@ def index(self, index_name: str) -> Index:
return Index(self.config, index_name=index_name)
raise Exception('The index UID should not be None')

def get_indexes(self) -> Dict[str, List[Index]]:
def get_indexes(self) -> Dict[str, List[Dict[str, str]]]:
"""Get all indexes.

Returns:
Indexes, a dictionary with the name of indexes.
Indexes, a dictionary with the name of indexes.
"""
response = self.http.get(path='indexes')
response['results'] = [
Index(
config=self.config,
index_name=index_info["index_name"],
)
{'index_name': index_info["index_name"]}
for index_info in response["results"]
]
return response
Expand Down
42 changes: 6 additions & 36 deletions tests/v0_tests/test_get_indexes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import pprint
import time
import marqo.index
from marqo.client import Client
from marqo.errors import MarqoApiError, MarqoError, MarqoWebError
import unittest
from marqo.errors import MarqoApiError
from tests.marqo_test import MarqoTestCase

import time
from typing import Dict, List

class TestAddDocuments(MarqoTestCase):

Expand All @@ -27,9 +24,9 @@ def tearDown(self) -> None:
except MarqoApiError:
pass

def _is_index_name_in_get_indexes_response(self, index_name, get_indexes_response):
def _is_index_name_in_get_indexes_response(self, index_name: str, get_indexes_response: Dict[str, List[Dict[str, str]]]):
for found_index in get_indexes_response['results']:
if index_name == found_index.index_name:
if index_name == found_index["index_name"]:
return True
return False

Expand All @@ -53,31 +50,4 @@ def test_get_indexes(self):
assert len(ix_1['results']) > len(ix_0['results'])

for found_index in ix_2['results']:
assert isinstance(found_index, marqo.index.Index)

def test_get_indexes_usable(self):
"""Are the indices we get back usable? """
self.client.create_index(self.index_name_1)
get_ixes_res = self.client.get_indexes()
assert self._is_index_name_in_get_indexes_response(self.index_name_1, get_ixes_res)

my_ix = None
for found_index in get_ixes_res['results']:
if self.index_name_1 == found_index.index_name:
my_ix = found_index

if my_ix is None:
raise AssertionError

assert my_ix.get_stats()['numberOfDocuments'] == 0
my_ix.add_documents([{'some doc': 'gold fish'}])

if self.IS_MULTI_INSTANCE:
time.sleep(1)

assert my_ix.get_stats()['numberOfDocuments'] == 1

if self.IS_MULTI_INSTANCE:
self.warm_request(my_ix.search,q='aquatic animal')

assert len(my_ix.search(q='aquatic animal')['hits']) == 1
assert isinstance(found_index, dict)
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py38
; [tox]
; envlist = py38

[testenv]
passenv =
Expand Down