From 343282195bad5b12a86e8d8b367c90f491a980c1 Mon Sep 17 00:00:00 2001 From: OwenPendrighElliott Date: Thu, 6 Jul 2023 12:40:55 +1000 Subject: [PATCH] changed return type for get_indexes to match the rest API --- src/marqo/client.py | 9 +++---- tests/v0_tests/test_get_indexes.py | 42 +++++------------------------- tox.ini | 4 +-- 3 files changed, 11 insertions(+), 44 deletions(-) diff --git a/src/marqo/client.py b/src/marqo/client.py index c8e2dc27..79a21ea4 100644 --- a/src/marqo/client.py +++ b/src/marqo/client.py @@ -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 diff --git a/tests/v0_tests/test_get_indexes.py b/tests/v0_tests/test_get_indexes.py index a0eaaacd..6f7c2318 100644 --- a/tests/v0_tests/test_get_indexes.py +++ b/tests/v0_tests/test_get_indexes.py @@ -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): @@ -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 @@ -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) \ No newline at end of file diff --git a/tox.ini b/tox.ini index 5669f5ac..7cd0f403 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ -[tox] -envlist = py38 +; [tox] +; envlist = py38 [testenv] passenv =