async def test_true_aiocustomcaptcha_context(self):
     with CustomCaptchaTask.aioCustomCaptchaTask(
             anticaptcha_key=self.anticaptcha_key_true,
             assignment=self.CUSTOM_TASK) as customcaptcha:
         response = await customcaptcha.captcha_handler(
             imageUrl=self.image_url)
         assert 0 == response["errorId"]
示例#2
0
    def test_get_result_payload(self):
        customcaptcha = CustomCaptchaTask.CustomCaptchaTask(
            anticaptcha_key=self.anticaptcha_key_fail,
            assignment=self.CUSTOM_TASK)
        # check response type
        assert isinstance(customcaptcha, CustomCaptchaTask.CustomCaptchaTask)

        with requests_mock.Mocker() as req_mock:
            req_mock.register_uri("POST",
                                  config.create_task_url,
                                  json=self.VALID_RESPONSE_JSON)
            req_mock.register_uri("POST",
                                  config.get_result_url,
                                  json=self.VALID_RESPONSE_RESULT_JSON)
            customcaptcha.captcha_handler(imageUrl=self.image_url)

        history = req_mock.request_history

        assert len(history) == 2

        request_payload = history[1].json()

        # check all dict keys
        assert ["clientKey", "taskId"] == list(request_payload.keys())
        assert request_payload["taskId"] == self.VALID_RESPONSE_JSON["taskId"]
    def test_fail_customcaptcha_context(self):
        with CustomCaptchaTask.CustomCaptchaTask(
                anticaptcha_key=self.anticaptcha_key_fail,
                assignment=self.CUSTOM_TASK) as customcaptcha:

            response = customcaptcha.captcha_handler(imageUrl=self.image_url)

            assert 1 == response["errorId"]
    def test_true_customcaptcha(self):
        customcaptcha = CustomCaptchaTask.CustomCaptchaTask(
            anticaptcha_key=self.anticaptcha_key_true,
            assignment=self.CUSTOM_TASK)

        response = customcaptcha.captcha_handler(imageUrl=self.image_url)

        assert 0 == response["errorId"]
示例#5
0
async def run():
    try:
        # Пример работы антикапчи с кастомной капчёй, асинхронно
        result = CustomCaptchaTask.aioCustomCaptchaTask(anticaptcha_key=ANTICAPTCHA_KEY,
                                                        assignment='Enter license plate number',
                                                        forms=custom_form).\
                    captcha_handler(imageUrl=imageUrl)
        
        print(result)

    except Exception as err:
        print(err)
    async def test_response_aiocustomcaptcha(self):
        customcaptcha = CustomCaptchaTask.aioCustomCaptchaTask(
            anticaptcha_key=self.anticaptcha_key_fail,
            assignment=self.CUSTOM_TASK)
        # check response type
        assert isinstance(customcaptcha, CustomCaptchaTask.CustomCaptchaTask)

        response = await customcaptcha.captcha_handler(imageUrl=self.image_url)
        # check response type
        assert isinstance(response, dict)
        # check all dict keys
        assert ["errorId", "errorCode",
                "errorDescription"] == list(response.keys())
示例#7
0
    def test_response_customcaptcha(self):
        customcaptcha = CustomCaptchaTask.CustomCaptchaTask(
            anticaptcha_key=self.anticaptcha_key_fail,
            assignment=self.CUSTOM_TASK)
        # check response type
        assert isinstance(customcaptcha, CustomCaptchaTask.CustomCaptchaTask)

        with requests_mock.Mocker() as req_mock:
            req_mock.post(config.create_task_url,
                          json=self.ERROR_RESPONSE_JSON)
            response = customcaptcha.captcha_handler(imageUrl=self.image_url)

        # check response type
        assert isinstance(response, dict)
        # check all dict keys
        assert ["errorId", "errorCode",
                "errorDescription"] == list(response.keys())
示例#8
0
    def test_aiocustomcaptcha(self):
        customcaptcha = CustomCaptchaTask.aioCustomCaptchaTask(
            anticaptcha_key=self.anticaptcha_key,
            sleep_time=10,
            assignment="Smth interesting",
        )
        # check response type
        assert (type(customcaptcha) is
                python3_anticaptcha.CustomCaptchaTask.aioCustomCaptchaTask)

        response = yield customcaptcha.captcha_handler(
            imageUrl=self.server_ip +
            "/static/image/common_image_example/088636.png")
        # check response type
        assert type(response) is dict
        # check all dict keys
        assert ["errorId", "errorCode",
                "errorDescription"] == list(response.keys())
示例#9
0
    def test_create_task_payload(self):
        customcaptcha = CustomCaptchaTask.CustomCaptchaTask(
            anticaptcha_key=self.anticaptcha_key_fail,
            assignment=self.CUSTOM_TASK)
        # check response type
        assert isinstance(customcaptcha, CustomCaptchaTask.CustomCaptchaTask)

        with requests_mock.Mocker() as req_mock:
            req_mock.post(config.create_task_url,
                          json=self.ERROR_RESPONSE_JSON)
            customcaptcha.captcha_handler(imageUrl=self.image_url)

        history = req_mock.request_history

        assert len(history) == 1

        request_payload = history[0].json()

        # check all dict keys
        assert ["clientKey", "task", "softId"] == list(request_payload.keys())
        assert request_payload["softId"] == config.app_key
        assert ["type", "assignment",
                "imageUrl"] == list(request_payload["task"].keys())
        assert request_payload["task"]["type"] == "CustomCaptchaTask"
 async def test_fail_aiocustomcaptcha(self):
     customcaptcha = CustomCaptchaTask.aioCustomCaptchaTask(
         anticaptcha_key=self.anticaptcha_key_fail,
         assignment=self.CUSTOM_TASK)
     response = await customcaptcha.captcha_handler(imageUrl=self.image_url)
     assert 1 == response["errorId"]
示例#11
0
                            "caption": "Grey color"
                        },
                        {
                            "value": "blue",
                            "caption": "Blue color"
                        },
                        {
                            "value": "red",
                            "caption": "Red color"
                        }
                    ]
                }
            ]'''

my_custom_task = CustomCaptchaTask.CustomCaptchaTask(anticaptcha_key=ANTICAPTCHA_KEY,
                                                     assignment='Enter license plate number',
                                                     forms=custom_form).\
                    captcha_handler(imageUrl=imageUrl)


print(my_custom_task)


# Асинхронный пример работы
async def run():
    try:
        # Пример работы антикапчи с кастомной капчёй, асинхронно
        result = CustomCaptchaTask.aioCustomCaptchaTask(anticaptcha_key=ANTICAPTCHA_KEY,
                                                        assignment='Enter license plate number',
                                                        forms=custom_form).\
                    captcha_handler(imageUrl=imageUrl)