Skip to content

Commit 158af6a

Browse files
committed
Adds unit level tests to getVersion on get_settings
1 parent 52ea962 commit 158af6a

File tree

4 files changed

+44
-23
lines changed

4 files changed

+44
-23
lines changed

algoliasearch/search_index.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ def get_objects(self, object_ids, request_options=None):
132132
request_options
133133
)
134134
# store attributesToRetrieve for use in each request
135-
attributes_to_retrieve = request_options.data.pop('attributesToRetrieve', None)
135+
attributes_to_retrieve = request_options.data.pop(
136+
'attributesToRetrieve', None)
136137

137138
requests = []
138139
for object_id in object_ids:
@@ -234,17 +235,16 @@ def set_settings(self, settings, request_options=None):
234235
def get_settings(self, request_options=None):
235236
# type: (Optional[Union[dict, RequestOptions]]) -> dict # noqa: E501
236237

237-
params = {'getVersion': 2}
238+
if request_options is None or isinstance(request_options, dict):
239+
request_options = RequestOptions.create(self._config,
240+
request_options)
238241

239-
if request_options is None:
240-
request_options = {'getVersion':2}
241-
else:
242-
request_options.append({'getVersion':2})
242+
request_options.query_parameters['getVersion'] = 2
243243

244244
raw_response = self._transporter.read(
245245
Verb.GET,
246246
endpoint('1/indexes/{}/settings', self._name),
247-
params,
247+
None,
248248
request_options
249249
)
250250

algoliasearch/search_index_async.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ def browse_rules_async(self, request_options=None):
8080
def get_settings_async(self, request_options=None): # type: ignore
8181
# type: (Optional[Union[dict, RequestOptions]]) -> dict
8282

83-
if request_options == None:
84-
request_options = {'getVersion':2}
85-
else:
86-
request_options.append({'getVersion':2})
83+
if request_options is None or isinstance(request_options, dict):
84+
request_options = RequestOptions.create(self._config,
85+
request_options)
86+
87+
request_options.query_parameters['getVersion'] = 2
8788

8889
raw_response = yield from self._transporter_async.read(
8990
Verb.GET,

tests/features/test_account_client.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,10 @@ def test_cross_app_copy_index(self):
4646
self.assertEqual(self.index2.get_rule('one'), rule)
4747

4848
# Assert synonyms got copied
49-
list_synonyms1 = []
50-
list_synonyms2 = []
49+
list_synonyms1 = [synonym for synonym in self.index.browse_synonyms()]
50+
list_synonyms2 = [synonym for synonym in self.index2.browse_synonyms()]
5151

52-
for synonym1 in self.index.browse_synonyms():
53-
list_synonyms1.append(synonym1)
54-
55-
for synonym2 in self.index2.browse_synonyms():
56-
list_synonyms2.append(synonym2)
57-
58-
self.assertEqual(list_synonyms1,list_synonyms1)
52+
self.assertEqual(list_synonyms1, list_synonyms2)
5953

6054
# Assert synomys are the same
6155
self.assertEqual(self.index2.get_synonym('one'), synonym)

tests/unit/test_search_index.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,48 @@ def test_get_settings(self):
172172
'ignorePlurals': True,
173173
}
174174

175-
settings = self.index.get_settings({'foo': 'bar'})
175+
request_options = RequestOptions.create(self.config, {'foo': 'bar'})
176+
settings = self.index.get_settings(request_options)
176177

177178
self.transporter.read.assert_called_once_with(
178179
'GET',
179180
'1/indexes/index-name/settings',
180-
{'getVersion': 2}, # asserts version 2 it's used.
181-
{'foo': 'bar'}
181+
None, # asserts version 2 it's used.
182+
request_options
182183
)
183184

185+
self.assertEqual(request_options.query_parameters['getVersion'], 2)
186+
184187
self.assertEqual(settings, {
185188
'searchableAttributes': ['attr1', 'attr2'],
186189
'numericAttributesForFiltering': ['attr1', 'attr2'],
187190
'replicas': ['index1', 'index2'],
188191
'ignorePlurals': True,
189192
})
190193

194+
def test_get_settings_none_as_request_options(self):
195+
self.index.get_settings()
196+
197+
args = self.transporter.read.call_args[0]
198+
199+
self.assertEqual(args[3].query_parameters['getVersion'], 2)
200+
201+
def test_get_settings_dict_as_request_options(self):
202+
self.index.get_settings({'foo': 'bar'})
203+
204+
args = self.transporter.read.call_args[0]
205+
206+
self.assertEqual(args[3].query_parameters['getVersion'], 2)
207+
208+
def test_get_settings_dict_as_request_options(self):
209+
request_options = RequestOptions.create(self.config, {'foo': 'bar'})
210+
211+
self.index.get_settings(request_options)
212+
213+
args = self.transporter.read.call_args[0]
214+
215+
self.assertEqual(args[3].query_parameters['getVersion'], 2)
216+
191217
def test_save_synonyms(self):
192218
# Test null response
193219
self.index.save_synonyms([]).wait()

0 commit comments

Comments
 (0)