def test_secured_api_keys(self): hosts = F.hosts(self.client.app_id) config1 = SearchConfig(F.get_app_id(), F.get_api_key()) config1.hosts = hosts client1 = F.decide(SearchClient.create_with_config(config1)) index1 = F.index(client1, self._testMethodName) index2 = F.index(client1, '{}_dev'.format(self._testMethodName)) index1.save_object({'objectID': 'one'}).wait() index2.save_object({'objectID': 'one'}).wait() api_key = self.client.generate_secured_api_key( os.environ['ALGOLIA_SEARCH_KEY_1'], { "validUntil": int(round(time.time())) + (60 * 10), # + 10 min "restrictIndices": index1.name }) config2 = SearchConfig(F.get_app_id(), api_key) config2.hosts = hosts client2 = F.decide(SearchClient.create_with_config(config2)) index1_search = client2.init_index(index1.name) index2_search = client2.init_index(index2.name) index1_search.search('') with self.assertRaises(RequestException) as _: index2_search.search('')
def test_create_with_config(self): config = SearchConfig('foo', 'bar') self.assertIsInstance( SearchClient.create_with_config(config), SearchClient )
def search_client(app_id=None, api_key=None): # type: (Optional[str], Optional[str]) -> SearchClient app_id = app_id if app_id is not None else Factory.get_app_id() api_key = api_key if api_key is not None else Factory.get_api_key() config = SearchConfig(app_id, api_key) config.hosts = Factory.hosts(app_id) return Factory.decide(SearchClient.create_with_config(config))
def search_client(app_id=None, api_key=None): # type: (Optional[str], Optional[str]) -> SearchClient app_id = app_id if app_id is not None else Factory.get_app_id() api_key = api_key if api_key is not None else Factory.get_api_key() config = SearchConfig(app_id, api_key) # To ensure `Consistency` during the Common Test Suite, # we force the transporter to work with a single # host in the { host-1, host-2, host-3 } config.hosts = Factory.hosts(app_id) return Factory.decide(SearchClient.create_with_config(config))
def syncAlgoliaWith(data, id, ingredients): config = SearchConfig(ALGOLIA_ID, ALGOLIA_ADMIN_KEY) config.batch_size = 1 client = SearchClient.create_with_config(config) client._config.bach_size = 1 # Add an 'objectID' field which Algolia requires data["objectID"] = id data["filtered_ingredients"] = ingredients # Write to the algolia index index = client.init_index('Recipes') index.save_objects([data])
def test_dns_timeout(self): config = SearchConfig(F.get_app_id(), F.get_api_key()) config.hosts = HostsCollection([ Host('algolia.biz', 10), Host('{}-1.algolianet.com'.format(F.get_app_id())), Host('{}-2.algolianet.com'.format(F.get_app_id())), Host('{}-3.algolianet.com'.format(F.get_app_id())) ]) client = SearchClient.create_with_config(config) client.list_indices() # We test that the first Host `algolia.biz` is down. self.assertFalse(config.hosts.read()[0].up) self.assertTrue(config.hosts.read()[1].up) self.assertTrue(config.hosts.read()[2].up) self.assertTrue(config.hosts.read()[3].up)
def test_create_with_config(self): config = SearchConfig('foo', 'bar') self.assertIsInstance(SearchClient.create_with_config(config), SearchClient)
def test_create_with_config(self): config = SearchConfig("foo", "bar") self.assertIsInstance(SearchClient.create_with_config(config), SearchClient)