Repository: algolia/algoliasearch-client-python

Issue:
feat: add request options in exists method
We need to allow passing the `request_options` into the exists method.

Discussion:

Patch:
diff --git a/algoliasearch/search_index.py b/algoliasearch/search_index.py
index b280c3a52..4aaf25d49 100644
--- a/algoliasearch/search_index.py
+++ b/algoliasearch/search_index.py
@@ -49,11 +49,11 @@ class SearchIndex(object):
         self._config = config
         self._name = name
 
-    def exists(self):
-        # type: () -> bool
+    def exists(self, request_options=None):
+        # type: (Optional[Union[dict, RequestOptions]]) -> bool
 
         try:
-            self.get_settings()
+            self.get_settings(request_options)
         except RequestException as e:
             if e.status_code == 404:
                 return False
diff --git a/algoliasearch/search_index_async.py b/algoliasearch/search_index_async.py
index 562d508a6..beabc70ab 100644
--- a/algoliasearch/search_index_async.py
+++ b/algoliasearch/search_index_async.py
@@ -79,11 +79,11 @@ class SearchIndexAsync(SearchIndex):
         return RuleIteratorAsync(self._transporter_async, self._name,
                                  request_options)
 
-    def exists_async(self):
-        # type: () -> bool
+    def exists_async(self, request_options=None):  # type: ignore # noqa: E501
+        # type: (Optional[Union[dict, RequestOptions]]) -> bool
 
         try:
-            yield from self.get_settings_async()
+            yield from self.get_settings_async(request_options)
         except RequestException as e:
             if e.status_code == 404:
                 return False


Test patch:
diff --git a/tests/unit/test_search_index.py b/tests/unit/test_search_index.py
index 246d5c45d..935e6a883 100644
--- a/tests/unit/test_search_index.py
+++ b/tests/unit/test_search_index.py
@@ -29,7 +29,8 @@ class TestSearchIndex(unittest.TestCase):
     def test_name_getter(self):
         self.assertEqual(self.index.name, 'index-name')
 
-    def test_index_does_not_exist(self):
+    def test_exists(self):
+
         with mock.patch.object(self.index, 'get_settings') as submethod_mock:
             submethod_mock.side_effect = RequestException(
                 "Index does not exist", 404
@@ -38,9 +39,13 @@ class TestSearchIndex(unittest.TestCase):
             indexExists = self.index.exists()
 
             self.index.get_settings.assert_called_once()
-            self.assertEqual(indexExists, False);
 
-    def test_index_exist_raises_non_4O4_exceptions(self):
+            # No request options
+            args = self.index.get_settings.call_args[0]
+            self.assertEqual(args[0], None)
+
+            self.assertEqual(indexExists, False)
+
         with mock.patch.object(self.index, 'get_settings') as submethod_mock:
             submethod_mock.side_effect = RequestException(
                 "Permissions error", 400
@@ -49,7 +54,25 @@ class TestSearchIndex(unittest.TestCase):
             with self.assertRaises(RequestException) as _:
                 self.index.exists()
 
-    def test_index_exists(self):
+        with mock.patch.object(self.index, 'get_settings') as submethod_mock:
+            submethod_mock.return_value = {
+                'hitsPerPage': 20,
+                'maxValuesPerFacet': 100
+            }
+
+            request_options = {
+                'X-Algolia-User-ID': 'Foo'
+            }
+
+            indexExists = self.index.exists(request_options)
+
+            # With request options
+            args = self.index.get_settings.call_args[0]
+            self.assertEqual(args[0], request_options)
+
+            self.index.get_settings.assert_called_once()
+            self.assertEqual(indexExists, True)
+
         with mock.patch.object(self.index, 'get_settings') as submethod_mock:
             submethod_mock.return_value = {
                 'hitsPerPage': 20,
@@ -59,7 +82,7 @@ class TestSearchIndex(unittest.TestCase):
             indexExists = self.index.exists()
 
             self.index.get_settings.assert_called_once()
-            self.assertEqual(indexExists, True);
+            self.assertEqual(indexExists, True)
 
     def test_save_objects(self):
         # Saving an object without object id