def __init__(self, recommend_client, transporter, search_config):
        # type: (RecommendClient, TransporterAsync, SearchConfig) -> None

        self._recommend_client = recommend_client
        self._transporter_async = transporter

        super(RecommendClientAsync,
              self).__init__(recommend_client._transporter, search_config)

        recommend_client = RecommendClient(transporter, search_config)
        recommend_client.__setattr__("_sync", self._sync)
        _create_async_methods_in(self, recommend_client)
Пример #2
0
    def recommend_client(app_id=None, api_key=None):
        # type: (Optional[str], Optional[str]) -> RecommendClient

        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()

        return Factory.decide(RecommendClient.create(app_id, api_key))
Пример #3
0
 def setUp(self):
     self.client = RecommendClient.create("foo", "bar")
     # `_session` is initialized with `None` to make it closable, we override it
     # here to mock it.
     self.client._transporter._requester._session = requests.Session()
     self.client._transporter._requester._session.send = mock.Mock(
         name="send")
     self.client._transporter._requester._session.send.return_value.status_code = 200
Пример #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 test_app_id_getter(self):
        client = RecommendClient.create("foo", "bar")

        self.assertEqual(client.app_id, "foo")
Пример #6
0
    def test_create_with_config(self):
        config = SearchConfig("foo", "bar")

        self.assertIsInstance(RecommendClient.create_with_config(config),
                              RecommendClient)
Пример #7
0
 def test_create(self):
     self.assertIsInstance(self.client, RecommendClient)
     with self.assertRaises(AssertionError) as _:
         RecommendClient.create("", "")