Beispiel #1
0
    async def test_true_aiospend_stats(self):
        captcha_control = AntiCaptchaControl.aioAntiCaptchaControl(anticaptcha_key=self.anticaptcha_key_true)
        response = await captcha_control.get_spend_stats()

        assert isinstance(response, dict)

        assert ("errorId", "data") == tuple(response.keys())
Beispiel #2
0
    async def test_fail_aiotype_complaint(self):
        captcha_control = AntiCaptchaControl.aioAntiCaptchaControl(anticaptcha_key=self.anticaptcha_key_fail)

        with pytest.raises(ValueError):
            assert await captcha_control.complaint_on_result(
                reported_id=self.REPORT_ID, captcha_type=self.WRONG_CAPTCHA_TYPE
            )
Beispiel #3
0
 def test_true_aiocontrol(self):
     # prepare client
     result = AntiCaptchaControl.aioAntiCaptchaControl(
         anticaptcha_key=self.anticaptcha_key_true
     )
     # complaint on result
     response = yield result.complaint_on_result(
         reported_id=self.WRONG_TASK_ID, captcha_type="image"
     )
     # check response type
     assert type(response) is dict
     # check all dict keys
     assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
     # check error code
     assert response["errorId"] == 16
     # complaint on result
     response = yield result.complaint_on_result(
         reported_id=self.WRONG_TASK_ID, captcha_type="recaptcha"
     )
     # check response type
     assert type(response) is dict
     # check all dict keys
     assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
     # check error code
     assert response["errorId"] == 16
Beispiel #4
0
 def test_control_type(self):
     # prepare client
     result = AntiCaptchaControl.AntiCaptchaControl(
         anticaptcha_key=self.anticaptcha_key_fail
     )
     # check response type
     assert type(result) is AntiCaptchaControl.AntiCaptchaControl
Beispiel #5
0
    def test_fail_key_app_stats(self):
        captcha_control = AntiCaptchaControl.AntiCaptchaControl(anticaptcha_key=self.anticaptcha_key_fail)

        response = captcha_control.get_app_stats(softId=self.WRONG_SOFT_ID)

        assert isinstance(response, dict)

        assert 1 == response["errorId"]
Beispiel #6
0
    async def test_fail_aioid_app_stats(self):
        captcha_control = AntiCaptchaControl.aioAntiCaptchaControl(anticaptcha_key=self.anticaptcha_key_true)

        response = await captcha_control.get_app_stats(softId=self.WRONG_SOFT_ID)

        assert isinstance(response, dict)

        assert 1 == response["errorId"]
Beispiel #7
0
    def test_true_balance(self):
        captcha_control = AntiCaptchaControl.AntiCaptchaControl(anticaptcha_key=self.anticaptcha_key_true)

        response = captcha_control.get_balance()

        assert isinstance(response, dict)

        assert 0 == response["errorId"]
Beispiel #8
0
    async def test_fail_aiobalance(self):
        captcha_control = AntiCaptchaControl.aioAntiCaptchaControl(anticaptcha_key=self.anticaptcha_key_fail)

        response = await captcha_control.get_balance()

        assert isinstance(response, dict)

        assert 1 == response["errorId"]
Beispiel #9
0
    def test_true_spend_stats_context(self):
        with AntiCaptchaControl.AntiCaptchaControl(
                anticaptcha_key=self.anticaptcha_key_true) as captcha_control:
            response = captcha_control.get_spend_stats()

        assert isinstance(response, dict)

        assert ("errorId", "data") == tuple(response.keys())
Beispiel #10
0
    def test_true_aioapp_stats(self):
        # prepare client
        result = AntiCaptchaControl.aioAntiCaptchaControl(
            anticaptcha_key=self.anticaptcha_key_true
        )
        # complaint on result
        response = yield result.get_app_stats(softId=867)
        # check response type
        assert type(response) is dict
        # check all dict keys
        assert ["errorId", "chartData", "fromDate", "toDate"] == list(response.keys())
        # check error code
        assert response["errorId"] == 0

        # get balance
        response = yield result.get_app_stats(softId=867, mode="errors")
        # check response type
        assert type(response) is dict
        # check all dict keys
        assert ["errorId", "chartData", "fromDate", "toDate"] == list(response.keys())
        # check error code
        assert response["errorId"] == 0

        # get balance
        response = yield result.get_app_stats(softId=867, mode="views")
        # check response type
        assert type(response) is dict
        # check all dict keys
        assert ["errorId", "chartData", "fromDate", "toDate"] == list(response.keys())
        # check error code
        assert response["errorId"] == 0

        # get balance
        response = yield result.get_app_stats(softId=867, mode="downloads")
        # check response type
        assert type(response) is dict
        # check all dict keys
        assert ["errorId", "chartData", "fromDate", "toDate"] == list(response.keys())
        # check error code
        assert response["errorId"] == 0

        # get balance
        response = yield result.get_app_stats(softId=867, mode="users")
        # check response type
        assert type(response) is dict
        # check all dict keys
        assert ["errorId", "chartData", "fromDate", "toDate"] == list(response.keys())
        # check error code
        assert response["errorId"] == 0

        # get balance
        response = yield result.get_app_stats(softId=867, mode="money")
        # check response type
        assert type(response) is dict
        # check all dict keys
        assert ["errorId", "chartData", "fromDate", "toDate"] == list(response.keys())
        # check error code
        assert response["errorId"] == 0
Beispiel #11
0
    def test_true_mode_app_stats(self):
        captcha_control = AntiCaptchaControl.AntiCaptchaControl(anticaptcha_key=self.anticaptcha_key_true)

        for mode in AntiCaptchaControl.mods:
            response = captcha_control.get_app_stats(softId=config.app_key, mode=mode)

            assert isinstance(response, dict)

            assert 0 == response["errorId"]
Beispiel #12
0
    def test_fail_app_stats_context(self):
        with AntiCaptchaControl.AntiCaptchaControl(
                anticaptcha_key=self.anticaptcha_key_fail) as captcha_control:

            response = captcha_control.get_app_stats(softId=config.app_key)

            assert isinstance(response, dict)

            assert 1 == response["errorId"]
Beispiel #13
0
    async def test_fail_aiomode_app_stats(self):
        with AntiCaptchaControl.aioAntiCaptchaControl(
                anticaptcha_key=self.anticaptcha_key_fail) as captcha_control:

            response = await captcha_control.get_balance()

            assert isinstance(response, dict)

            assert 1 == response["errorId"]
Beispiel #14
0
    def test_fail_balance_context(self):
        with AntiCaptchaControl.AntiCaptchaControl(
                anticaptcha_key=self.anticaptcha_key_fail) as captcha_control:

            response = captcha_control.get_balance()

            assert isinstance(response, dict)

            assert 1 == response["errorId"]
Beispiel #15
0
    def test_fail_aioqueue_status(self):
        # prepare client
        result = AntiCaptchaControl.AntiCaptchaControl(
            anticaptcha_key=self.anticaptcha_key_fail
        )
        q_id = self.WRONG_QUEUE_ID

        with pytest.raises(ValueError):
            # get queue status
            assert result.get_queue_status(queue_id=q_id)
Beispiel #16
0
    def test_fail_key_complaint(self):
        captcha_control = AntiCaptchaControl.AntiCaptchaControl(anticaptcha_key=self.anticaptcha_key_fail)

        response = captcha_control.complaint_on_result(
            reported_id=self.REPORT_ID, captcha_type=AntiCaptchaControl.complaint_types[0]
        )

        assert isinstance(response, dict)

        assert 1 == response["errorId"]
Beispiel #17
0
    async def test_true_aiospend_stats_queues(self):
        queues = AntiCaptchaControl.queues_names

        captcha_control = AntiCaptchaControl.aioAntiCaptchaControl(anticaptcha_key=self.anticaptcha_key_true)
        for queue in queues:
            response = await captcha_control.get_spend_stats(queue=queue)

            assert isinstance(response, dict)

            assert ("errorId", "data") == tuple(response.keys())
Beispiel #18
0
    async def test_fail_aioid_complaint(self):
        captcha_control = AntiCaptchaControl.aioAntiCaptchaControl(anticaptcha_key=self.anticaptcha_key_true)

        response = await captcha_control.complaint_on_result(
            reported_id=self.REPORT_ID, captcha_type=AntiCaptchaControl.complaint_types[0]
        )

        assert isinstance(response, dict)

        assert 16 == response["errorId"]
Beispiel #19
0
 def test_fail_aiobalance(self):
     # prepare client
     result = AntiCaptchaControl.aioAntiCaptchaControl(
         anticaptcha_key=self.anticaptcha_key_fail
     )
     # get balance
     response = yield result.get_balance()
     # check response type
     assert type(response) is dict
     # check all dict keys
     assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
Beispiel #20
0
 def test_true_aioqueue_status(self):
     # prepare client
     result = AntiCaptchaControl.aioAntiCaptchaControl(
         anticaptcha_key=self.anticaptcha_key_true
     )
     q_id = random.choice(AntiCaptchaControl.queue_ids)
     for q_id in AntiCaptchaControl.queue_ids:
         # get queue status
         response = yield result.get_queue_status(queue_id=q_id)
         # check response type
         assert type(response) is dict
         # check all dict keys
         assert ["waiting", "load", "bid", "speed", "total"] == list(response.keys())
Beispiel #21
0
 def test_true_aiobalance(self):
     # prepare client
     result = AntiCaptchaControl.aioAntiCaptchaControl(
         anticaptcha_key=self.anticaptcha_key_true
     )
     # get balance
     response = yield result.get_balance()
     # check response type
     assert type(response) is dict
     # check all dict keys
     assert ["errorId", "balance"] == list(response.keys())
     # check error code
     assert response["errorId"] == 0
Beispiel #22
0
    def test_fail_aioapp_stats(self):
        # prepare client
        result = AntiCaptchaControl.aioAntiCaptchaControl(
            anticaptcha_key=self.anticaptcha_key_fail
        )
        # complaint on result
        response = yield result.get_app_stats(softId=867)
        # check response type
        assert type(response) is dict
        # check all dict keys
        assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
        # check error code
        assert response["errorId"] == 1

        with pytest.raises(ValueError):
            assert result.get_app_stats(softId=867, mode="filure")
Beispiel #23
0
    def test_fail_aiocomplaint_on_result(self):
        # prepare client
        result = AntiCaptchaControl.aioAntiCaptchaControl(
            anticaptcha_key=self.anticaptcha_key_fail
        )
        # complaint on result
        response = yield result.complaint_on_result(reported_id=self.WRONG_TASK_ID)
        # check response type
        assert type(response) is dict
        # check all dict keys
        assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
        # check error code
        assert response["errorId"] == 1

        with pytest.raises(ValueError):
            assert result.complaint_on_result(
                reported_id=self.WRONG_TASK_ID, captcha_type="not_image"
            )
Beispiel #24
0
    def test_balance_payload(self):
        control = AntiCaptchaControl.AntiCaptchaControl(anticaptcha_key=self.anticaptcha_key_true)
        # check response type
        assert isinstance(control, AntiCaptchaControl.AntiCaptchaControl)

        with requests_mock.Mocker() as req_mock:
            req_mock.post(AntiCaptchaControl.get_balance_url, json=self.ERROR_RESPONSE_JSON)
            control.get_balance()

        history = req_mock.request_history

        assert len(history) == 1

        request_payload = history[0].json()

        # check all dict keys
        assert [
            "clientKey",
        ] == list(request_payload.keys())
        assert request_payload["clientKey"] == self.anticaptcha_key_true
Beispiel #25
0
    def test_fail_aiocontrol_context(self):
        # prepare client
        with AntiCaptchaControl.aioAntiCaptchaControl(
            anticaptcha_key=self.anticaptcha_key_fail
        ) as result:
            # get balance
            response = yield result.get_balance()
            # check response type
            assert type(response) is dict
            # check all dict keys
            assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())

            # complaint on result
            response = yield result.complaint_on_result(reported_id=self.WRONG_TASK_ID)
            # check response type
            assert type(response) is dict
            # check all dict keys
            assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
            # check error code
            assert response["errorId"] == 1
Beispiel #26
0
    def test_stats_payload(self):
        control = AntiCaptchaControl.AntiCaptchaControl(anticaptcha_key=self.anticaptcha_key_true)
        # check response type
        assert isinstance(control, AntiCaptchaControl.AntiCaptchaControl)
        mode = random.choice(AntiCaptchaControl.mods)

        with requests_mock.Mocker() as req_mock:
            req_mock.post(AntiCaptchaControl.get_app_stats_url, json=self.ERROR_RESPONSE_JSON)
            control.get_app_stats(softId=config.app_key, mode=mode)

        history = req_mock.request_history

        assert len(history) == 1

        request_payload = history[0].json()

        # check all dict keys
        assert ["clientKey", "softId", "mode"] == list(request_payload.keys())
        assert request_payload["clientKey"] == self.anticaptcha_key_true
        assert request_payload["softId"] == config.app_key
        assert request_payload["mode"] == mode
Beispiel #27
0
    def test_complaint_re_payload(self):
        control = AntiCaptchaControl.AntiCaptchaControl(anticaptcha_key=self.anticaptcha_key_true)
        # check response type
        assert isinstance(control, AntiCaptchaControl.AntiCaptchaControl)
        task_id = 123456

        with requests_mock.Mocker() as req_mock:
            req_mock.post(AntiCaptchaControl.incorrect_recaptcha_url, json=self.ERROR_RESPONSE_JSON)
            control.complaint_on_result(
                reported_id=task_id, captcha_type=AntiCaptchaControl.complaint_types[1]
            )

        history = req_mock.request_history

        assert len(history) == 1

        request_payload = history[0].json()

        # check all dict keys
        assert ["clientKey", "taskId"] == list(request_payload.keys())
        assert request_payload["clientKey"] == self.anticaptcha_key_true
        assert request_payload["taskId"] == task_id
Beispiel #28
0
    def test_aiocontrol_context(self):
        # prepare client
        with AntiCaptchaControl.aioAntiCaptchaControl(
                anticaptcha_key=self.anticaptcha_key) as result:
            # check response type
            assert (type(result) is
                    python3_anticaptcha.AntiCaptchaControl.AntiCaptchaControl)

            # get balance
            response = yield result.get_balance()
            # check response type
            assert type(response) is dict
            # check all dict keys
            assert ["errorId", "errorCode",
                    "errorDescription"] == list(response.keys())

            # complaint on result
            response = yield result.complaint_on_result(reported_id=432423342)
            # check response type
            assert type(response) is dict
            # check all dict keys
            assert ["errorId", "errorCode",
                    "errorDescription"] == list(response.keys())
    def test_control(self):
        # prepare client
        result = AntiCaptchaControl.AntiCaptchaControl(
            anticaptcha_key=self.anticaptcha_key)
        # check response type
        assert type(
            result
        ) is python3_anticaptcha.AntiCaptchaControl.AntiCaptchaControl

        # get balance
        response = result.get_balance()
        # check response type
        assert type(response) is dict
        # check all dict keys
        assert ['errorId', 'errorCode',
                'errorDescription'] == list(response.keys())

        # complaint on result
        response = result.complaint_on_result(reported_id=432423342)
        # check response type
        assert type(response) is dict
        # check all dict keys
        assert ['errorId', 'errorCode',
                'errorDescription'] == list(response.keys())
Beispiel #30
0
import asyncio

from python3_anticaptcha import AntiCaptchaControl


ANTICAPTCHA_KEY = ""
# Пример метода, отправляющего жалобу на неправильно решённую капчу-изображение.
# В качестве параметра, принимает ключ антикапчи и ID неправильно решённой капчи + тип капчи
# Возвращает логические True(жалоба прошла)/False(ошибка при жалобе)
result = AntiCaptchaControl.AntiCaptchaControl(
    anticaptcha_key=ANTICAPTCHA_KEY
).complaint_on_result(reported_id=-5, captcha_type="image")
print(result)
# Пример метода, отправляющего жалобу на неправильно решённую ReCaptcha.
# В качестве параметра, принимает ключ антикапчи и ID неправильно решённой ReCaptcha + тип капчи
# Возвращает логические True(жалоба прошла)/False(ошибка при жалобе)
result = AntiCaptchaControl.AntiCaptchaControl(
    anticaptcha_key=ANTICAPTCHA_KEY
).complaint_on_result(reported_id=-5, captcha_type="recaptcha")
print(result)
# Пример метода, принимающего ключ аккаунта и возвращающего актуальный баланс
result = AntiCaptchaControl.AntiCaptchaControl(anticaptcha_key=ANTICAPTCHA_KEY).get_balance()
print(result)
# Пример метода, выдающий информацию о загрузке очереди, в зависимости от ID очереди
# В данном случае queue_id = 1, то есть получаем информацию по загрузке очереди ImageToText (язык английский)
result = AntiCaptchaControl.AntiCaptchaControl(anticaptcha_key=ANTICAPTCHA_KEY).get_queue_status(
    queue_id=1
)
print(result)

# Асинхронный метод работы