コード例 #1
0
    def create_with_config(config):
        # type: (RecommendationConfig) -> RecommendationClient

        warnings.warn(
            "`%s.%s` is deprecated, use `%s.%s` instead."
            % (
                "RecommendationClient",
                "create_with_config",
                "PersonalizationClient",
                "create_with_config",
            ),
            DeprecationWarning,
        )

        requester = Requester()
        transporter = Transporter(requester, config)

        client = RecommendationClient(transporter, config)

        if is_async_available():
            from algoliasearch.recommendation_client_async import (
                RecommendationClientAsync,
            )
            from algoliasearch.http.transporter_async import TransporterAsync
            from algoliasearch.http.requester_async import RequesterAsync

            return RecommendationClientAsync(
                client, TransporterAsync(RequesterAsync(), config), config
            )

        return client
コード例 #2
0
 def setUp(self):
     self.config = SearchConfig('foo', 'bar')
     requester = Requester()
     self.transporter = Transporter(requester, self.config)
     self.transporter.read = mock.Mock(name="read")
     self.transporter.read.return_value = {}
     self.transporter.write = mock.Mock(name="write")
     self.transporter.write.return_value = {}
     self.index = SearchIndex(self.transporter, self.config, 'index-name')
コード例 #3
0
    def setUp(self):
        self.config = SearchConfig('foo', 'bar')
        self.transporter = Transporter(Requester(), self.config)
        self.transporter.read = mock.Mock(name="read")
        self.transporter.read.return_value = {}
        self.transporter.write = mock.Mock(name="write")
        self.transporter.write.return_value = {}

        self.client = SearchClient(self.transporter, self.config)
コード例 #4
0
    def setUp(self):
        self.config = SearchConfig("foo", "bar")
        self.transporter = Transporter(Requester(), self.config)
        self.transporter.read = mock.Mock(name="read")
        self.transporter.read.return_value = {}
        self.transporter.write = mock.Mock(name="write")
        self.transporter.write.return_value = {}

        self.client = RecommendClient(self.transporter, self.config)
コード例 #5
0
    def create_with_config(config):
        # type: (SearchConfig) -> SearchClient

        requester = Requester()
        transporter = Transporter(requester, config)

        client = SearchClient(transporter, config)

        if is_async_available():
            from algoliasearch.search_client_async import SearchClientAsync
            from algoliasearch.http.transporter_async import TransporterAsync
            from algoliasearch.http.requester_async import RequesterAsync

            return SearchClientAsync(
                client, TransporterAsync(RequesterAsync(), config), config)

        return client
コード例 #6
0
    def setUp(self):
        self.requester = Requester()
        self.requester.send = mock.Mock(name="send")
        self.requester.send.return_value = Response(200, {'foo': 'bar'})

        self.data = {'data': 'foo'}

        self.config = SearchConfig('foo', 'bar')

        self.request_options = RequestOptions.create(
            self.config, {
                'User-Agent': 'foo',
                'createIfNotExists': True,
                'readTimeout': 109,
                'bodyParam': 'bar'
            })

        self.transporter = Transporter(self.requester, self.config)
コード例 #7
0
    def create_with_config(config):
        # type: (RecommendationConfig) -> RecommendationClient

        requester = Requester()
        transporter = Transporter(requester, config)

        client = RecommendationClient(transporter, config)

        if is_async_available():
            from algoliasearch.recommendation_client_async import (
                RecommendationClientAsync, )
            from algoliasearch.http.transporter_async import TransporterAsync
            from algoliasearch.http.requester_async import RequesterAsync

            return RecommendationClientAsync(
                client, TransporterAsync(RequesterAsync(), config), config)

        return client
コード例 #8
0
    def create_with_config(config):
        # type: (InsightsConfig) -> InsightsClient

        requester = Requester()
        transporter = Transporter(requester, config)

        client = InsightsClient(transporter, config)

        if is_async_available():
            from algoliasearch.insights_client_async import InsightsClientAsync
            from algoliasearch.http.transporter_async import \
                TransporterAsync
            from algoliasearch.http.requester_async import RequesterAsync

            return InsightsClientAsync(
                client, TransporterAsync(RequesterAsync(), config), config)

        return client
コード例 #9
0
    def setUp(self):
        self.requester = Requester()
        self.requester.send = mock.Mock(name="send")
        self.requester.send.return_value = Response(200, {"foo": "bar"})

        self.data = {"data": "foo"}

        self.config = SearchConfig("foo", "bar")

        self.request_options = RequestOptions.create(
            self.config,
            {
                "User-Agent": "foo",
                "createIfNotExists": True,
                "readTimeout": 109,
                "bodyParam": "bar",
            },
        )

        self.transporter = Transporter(self.requester, self.config)
コード例 #10
0
    def test_with_proxy(self):
        config = SearchConfig("foo", "bar")
        requester = Requester()
        requester.send = mock.Mock(name="send")
        requester.send.return_value = Response(200, {"foo": "bar"})
        transporter = Transporter(requester, config)

        headers = RequestOptions.create(config).headers
        data = {}
        transporter.write("post", "endpoint/foo", data, None)

        request = Request(
            "POST",
            headers,
            {},
            2,  # Default connect timeout
            30,  # Default timeout
            proxies={"https": "https://127.0.0.1:8080"},
        )
        request.url = "https://foo.algolia.net/endpoint/foo?"
        requester.send.assert_called_once_with(request)