示例#1
0
    def test_get_captcha_ok(self):
        ag = AntiCaptcha(api_key, loop=self.loop)
        ag.close()
        ag._session = fake_client_session(200, 'OK|123')

        cid = self.loop.run_until_complete(ag._get_captcha('id'))
        self.assertEqual(cid, '123')
示例#2
0
    def test_get_captcha_inv_reply(self):
        ag = AntiCaptcha(api_key, loop=self.loop)
        ag.close()
        ag._session = fake_client_session(200, 'abc')

        with self.assertRaises(ServiceError) as cm:
            self.loop.run_until_complete(ag._get_captcha('id'))
        self.assertIn('Invalid server reply', str(cm.exception))
示例#3
0
    def test_get_captcha_http_err(self):
        ag = AntiCaptcha(api_key, loop=self.loop)
        ag.close()
        ag._session = fake_client_session(400, 'OK')

        with self.assertRaises(ServiceError) as cm:
            self.loop.run_until_complete(ag._get_captcha('id'))
        self.assertIn('HTTP error', str(cm.exception))
示例#4
0
    def test_get_captcha_handle_error(self):
        ag = AntiCaptcha(api_key, loop=self.loop)
        ag.close()
        ag._session = fake_client_session(200,
                                          'ERROR_NO_REQUEST_ACTION_RECEIVED')

        with self.assertRaises(ServiceError) as cm:
            self.loop.run_until_complete(ag._get_captcha('id'))
        self.assertIn('No request action received', str(cm.exception))
示例#5
0
    def test_get_captcha_not_ready(self, sleep_mock):
        sleep_mock.side_effect = fake_coroutine(1)

        ag = AntiCaptcha(api_key, loop=self.loop)
        ag.close()
        ag._session = fake_client_session(200, ['CAPCHA_NOT_READY', 'OK|123'],
                                          iter_v=True)

        cid = self.loop.run_until_complete(ag._get_captcha('id'))
        self.assertEqual(cid, '123')
        self.assertEqual(ag._session.get.call_count, 2)
        sleep_mock.assert_called_with(ag._check_interval, loop=ag._loop)
示例#6
0
    def test_get_captcha_client_error(self):
        ag = AntiCaptcha(api_key, loop=self.loop)
        ag.close()
        ag._session, resp = fake_client_session(200,
                                                aiohttp.ClientError(),
                                                ret_resp=True)

        with self.assertRaises(ServiceError) as cm:
            self.loop.run_until_complete(ag._get_captcha('id'))
        self.assertIn('Network error', str(cm.exception))
        self.assertTrue(resp.release.called)
        self.assertTrue(resp.close.called)