Esempio n. 1
0
    def test_get_balance_ok(self):
        ag = AntiCaptcha(api_key, loop=self.loop)
        ag.close()
        ag._session = fake_client_session(200, '0.5')

        balance = self.loop.run_until_complete(ag.get_balance())
        self.assertEqual(balance, 0.5)
Esempio n. 2
0
    def test_get_balance_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_balance())
        self.assertIn('Invalid server reply', str(cm.exception))
Esempio n. 3
0
    def test_get_balance_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_balance())
        self.assertIn('HTTP error', str(cm.exception))
Esempio n. 4
0
    def test_get_balance_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_balance())
        self.assertIn('No request action received', str(cm.exception))
Esempio n. 5
0
    def test_get_balance_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_balance())
        self.assertIn('Network error', str(cm.exception))
        self.assertTrue(resp.release.called)
        self.assertTrue(resp.close.called)