def setUp(self):
        self.engine_name = 'some-engine-name'
        self.client = Client('host_identifier', 'api_key')

        self.document_index_url = "{}/{}".format(
            self.client.swiftype_session.base_url,
            "engines/{}/documents".format(self.engine_name))
예제 #2
0
def main():
    print('Setting up connection')
    client = Client(
        api_key='',
        base_endpoint='192.168.1.1:3002/api/as/v1',
        use_https=False,
    )
    print('connection established')

    docs = []
    with open(FILE, 'r', encoding='utf-8-sig') as file_std:
        csv_reader = csv.reader(file_std, delimiter=',')
        row_num = 0

        # Read every line, sending NUM_DOCS documents at once.
        for line in csv_reader:
            if row_num == 0:
                columns = line
                print(f'Column names are {", ".join(line)}')
            elif row_num % NUM_DOCS == 0:
                print('Indexing documents {} through {}'.format(
                    row_num - NUM_DOCS, row_num))
                docs.append(dict(zip(columns, line)))
                responses = client.index_documents(SEARCH_ENGINE, docs)
                for response in responses:
                    if 'errors' in response and len(
                            response.get('errors')) > 0:
                        print(response.get('errors'))
                        return
                docs = []
            else:
                docs.append(dict(zip(columns, line)))
            row_num += 1
    def test_host_identifier_is_optional(self):
        client = Client('', 'api_key', 'localhost:3002/api/as/v1', False)
        query = 'query'

        with requests_mock.Mocker() as m:
            url = "http://localhost:3002/api/as/v1/engines/some-engine-name/search"
            m.register_uri('GET', url, json={}, status_code=200)
            client.search(self.engine_name, query, {})
 def test_deprecated_init_support_with_positional(self):
     self.client = Client('host_identifier', 'api_key', 'example.com',
                          False)
     self.assertEqual(self.client.account_host_key, 'host_identifier')
 def test_deprecated_init_support_with_new_names(self):
     self.client = Client(host_identifier='host_identifier',
                          api_key='api_key')
     self.assertEqual(self.client.account_host_key, 'host_identifier')