Esempio n. 1
0
    def test_dict_access(self):
        response = {
            'foo': 'bar',
        }

        response_object = IndexingResponse({}, [response])
        self.assertEqual(response_object[0]['foo'], 'bar')

        response_object = MultipleResponse([response])
        self.assertEqual(response_object[0]['foo'], 'bar')

        response_object = MultipleResponse([IndexingResponse({}, [response])])
        self.assertEqual(response_object[0][0]['foo'], 'bar')

        response_object = AddApiKeyResponse({}, response)
        self.assertEqual(response_object['foo'], 'bar')

        response_object = UpdateApiKeyResponse({}, response, {})
        self.assertEqual(response_object['foo'], 'bar')

        response_object = DeleteApiKeyResponse({}, response, '')
        self.assertEqual(response_object['foo'], 'bar')

        response_object = MultipleIndexBatchIndexingResponse({}, response)
        self.assertEqual(response_object['foo'], 'bar')
    def test_dict_access(self):
        response = {
            "foo": "bar",
        }

        response_object = IndexingResponse({}, [response])
        self.assertEqual(response_object[0]["foo"], "bar")

        response_object = MultipleResponse([response])
        self.assertEqual(response_object[0]["foo"], "bar")

        response_object = MultipleResponse([IndexingResponse({}, [response])])
        self.assertEqual(response_object[0][0]["foo"], "bar")

        response_object = AddApiKeyResponse({}, response)
        self.assertEqual(response_object["foo"], "bar")

        response_object = UpdateApiKeyResponse({}, response, {})
        self.assertEqual(response_object["foo"], "bar")

        response_object = DeleteApiKeyResponse({}, response, "")
        self.assertEqual(response_object["foo"], "bar")

        response_object = MultipleIndexBatchIndexingResponse({}, response)
        self.assertEqual(response_object["foo"], "bar")
Esempio n. 3
0
    def test_uses_request_options_on_wait(self):
        index = SearchClient.create('foo', 'bar').init_index('foo')
        index.wait_task = mock.Mock(name='wait_task')
        index._sync = mock.Mock(name='_sync')
        index._sync.return_value = index

        response = IndexingResponse(index, [{'taskID': 1}])
        response.wait({'bar': 2})
        index.wait_task.assert_called_once_with(1, {'bar': 2})
    def test_uses_request_options_on_wait(self):
        index = SearchClient.create("foo", "bar").init_index("foo")
        index.wait_task = mock.Mock(name="wait_task")
        index._sync = mock.Mock(name="_sync")
        index._sync.return_value = index

        response = IndexingResponse(index, [{"taskID": 1}])
        response.wait({"bar": 2})
        index.wait_task.assert_called_once_with(1, {"bar": 2})
    def test_uses_request_options_on_wait(self):
        index = SearchClient.create('foo', 'bar').init_index('foo')
        index.wait_task = mock.Mock(name='wait_task')
        index._sync = mock.Mock(name='_sync')
        index._sync.return_value = index

        response = IndexingResponse(index, [{'taskID': 1}])
        response.wait({'bar': 2})
        index.wait_task.assert_called_once_with(1, {'bar': 2})
Esempio n. 6
0
    def save_rules(self, rules, request_options=None):
        # type: (Union[List[dict], Iterator[dict]], Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501

        if not rules:
            return IndexingResponse(self, [])

        assert_object_id(rules)

        raw_response = self._transporter.write(
            Verb.POST, endpoint('1/indexes/{}/rules/batch', self._name),
            list(rules), request_options)

        return IndexingResponse(self, [raw_response])
Esempio n. 7
0
    def _chunk(self, action, objects, request_options,
               validate_object_id=True):
        # type: (str, Union[List[dict], Iterator[dict]], Optional[Union[dict, RequestOptions]], bool) -> IndexingResponse # noqa: E501

        raw_responses = []
        batch = []
        batch_size = self._config.batch_size
        for obj in objects:
            batch.append(obj)

            if len(batch) == batch_size:
                if validate_object_id:
                    assert_object_id(batch)

                requests = build_raw_response_batch(action, batch)
                raw_responses.append(
                    self._raw_batch(requests, request_options))
                batch = []

        if len(batch):
            if validate_object_id:
                assert_object_id(batch)
            requests = build_raw_response_batch(action, batch)
            raw_responses.append(self._raw_batch(requests, request_options))

        return IndexingResponse(self, raw_responses)
Esempio n. 8
0
    def clear_objects(self, request_options=None):
        # type: (Optional[Union[dict, RequestOptions]]) -> IndexingResponse

        raw_response = self._transporter.write(
            Verb.POST, endpoint("1/indexes/{}/clear", self._name), None, request_options
        )

        return IndexingResponse(self, [raw_response])
Esempio n. 9
0
    def delete(self, request_options=None):
        # type: (Optional[Union[dict, RequestOptions]]) -> Response

        raw_response = self._transporter.write(
            Verb.DELETE, endpoint("1/indexes/{}", self._name), None, request_options
        )

        return IndexingResponse(self, [raw_response])
Esempio n. 10
0
    def test_dict_access(self):
        response = {
            'foo': 'bar',
        }

        index = self.client.init_index('foo')
        response = IndexingResponse(index, [response])
        self.assertEqual(response.raw_responses[0]['foo'], 'bar')
Esempio n. 11
0
    def delete_by(self, filters, request_options=None):
        # type: (dict, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501

        raw_response = self._transporter.write(
            Verb.POST, endpoint('1/indexes/{}/deleteByQuery', self._name),
            filters, request_options)

        return IndexingResponse(self, [raw_response])
Esempio n. 12
0
    def set_settings(self, settings, request_options=None):
        # type: (dict, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501

        raw_response = self._transporter.write(
            Verb.PUT, endpoint('1/indexes/{}/settings', self._name), settings,
            request_options)

        return IndexingResponse(self, [raw_response])
Esempio n. 13
0
    def delete_rule(self, object_id, request_options=None):
        # type: (str, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501

        raw_response = self._transporter.write(
            Verb.DELETE,
            endpoint('1/indexes/{}/rules/{}', self._name, object_id), None,
            request_options)

        return IndexingResponse(self, [raw_response])
Esempio n. 14
0
    def copy_to(self, name, request_options=None):
        # type: (str, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501

        raw_response = self._transporter.write(
            Verb.POST, endpoint('1/indexes/{}/operation', self._name), {
                'operation': 'copy',
                'destination': name
            }, request_options)

        return IndexingResponse(self, [raw_response])
Esempio n. 15
0
    def move_to(self, name, request_options=None):
        # type: (str, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501

        raw_response = self._transporter.write(
            Verb.POST,
            endpoint("1/indexes/{}/operation", self._name),
            {"operation": "move", "destination": name},
            request_options,
        )

        return IndexingResponse(self, [raw_response])
    def move_index(self, src_index_name, dst_index_name, request_options=None):
        # type: (str, str, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501

        raw_response = self._transporter.write(
            Verb.POST, endpoint('1/indexes/{}/operation', src_index_name), {
                'operation': 'move',
                'destination': dst_index_name
            }, request_options)

        return IndexingResponse(self.init_index(src_index_name),
                                [raw_response])
    def copy_index(self, src_index_name, dst_index_name, request_options=None):
        # type: (str, str, Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501

        raw_response = self._transporter.write(
            Verb.POST,
            endpoint("1/indexes/{}/operation", src_index_name),
            {
                "operation": "copy",
                "destination": dst_index_name
            },
            request_options,
        )

        return IndexingResponse(self.init_index(src_index_name),
                                [raw_response])
Esempio n. 18
0
    def batch(self, requests, request_options=None):
        # type: (Union[List[dict], Iterator[dict]], Optional[Union[dict, RequestOptions]]) -> IndexingResponse # noqa: E501

        raw_response = self._raw_batch(requests, request_options)

        return IndexingResponse(self, [raw_response])