diff --git a/docs/conf.py b/docs/conf.py index 11afbdfc..6f7b0779 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,6 +18,7 @@ image_captcha, lemin_captcha, rotate_captcha, + datadome_captcha, ) from python_rucaptcha.__version__ import __version__ diff --git a/docs/index.rst b/docs/index.rst index d692d073..fbebfb8b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -41,6 +41,7 @@ Check our other projects here - `RedPandaDev group >> DataDomeCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122", + ... websiteURL="3ceb8624-1970-4e6b-91d5-70317b70b651", + ... captchaUrl="https://rucaptcha.com/demo/hcaptcha", + ... userAgent="https://rucaptcha.com/demo/hcaptcha", + ... proxyType="socks5", + ... proxyAddress="1.2.3.4", + ... proxyPort="445", + ... ).captcha_handler() + { + "errorId":0, + "status":"ready", + "solution":{ + "cookie": "datadome=4ZXwCBlyHx9ktZhSnycMF...; Path=/; Secure; SameSite=Lax" + }, + "cost":"0.00299", + "ip":"1.2.3.4", + "createTime":1692863536, + "endTime":1692863556, + "solveCount":1, + "taskId": 73243152973, + } + + >>> await DataDomeCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122", + ... websiteURL="3ceb8624-1970-4e6b-91d5-70317b70b651", + ... captchaUrl="https://rucaptcha.com/demo/hcaptcha", + ... userAgent="https://rucaptcha.com/demo/hcaptcha", + ... proxyType="socks5", + ... proxyAddress="1.2.3.4", + ... proxyPort="445", + ... ).aio_captcha_handler() + { + "errorId":0, + "status":"ready", + "solution":{ + "cookie": "datadome=4ZXwCBlyHx9ktZhSnycMF...; Path=/; Secure; SameSite=Lax" + }, + "cost":"0.00299", + "ip":"1.2.3.4", + "createTime":1692863536, + "endTime":1692863556, + "solveCount":1, + "taskId": 73243152973, + } + + Returns: + Dict with full server response + + Notes: + https://rucaptcha.com/api-docs/datadome-slider-captcha + """ + super().__init__(method=DataDomeSliderEnm.DataDomeSliderTask, *args, **kwargs) + + self.create_task_payload["task"].update( + { + "websiteURL": websiteURL, + "captchaUrl": captchaUrl, + "userAgent": userAgent, + "proxyType": proxyType, + "proxyAddress": proxyAddress, + "proxyPort": proxyPort, + } + ) + + def captcha_handler(self, **kwargs) -> dict: + """ + Sync solving method + + Args: + kwargs: Parameters for the `requests` library + + Returns: + Dict with full server response + + Notes: + Check class docstirng for more info + """ + + return self._processing_response(**kwargs) + + async def aio_captcha_handler(self) -> dict: + """ + Async solving method + + Returns: + Dict with full server response + + Notes: + Check class docstirng for more info + """ + return await self._aio_processing_response() diff --git a/tests/test_datadome.py b/tests/test_datadome.py new file mode 100644 index 00000000..6e01f97b --- /dev/null +++ b/tests/test_datadome.py @@ -0,0 +1,122 @@ +import pytest + +from tests.conftest import BaseTest +from python_rucaptcha.core.enums import DataDomeSliderEnm +from python_rucaptcha.datadome_captcha import DataDomeCaptcha + + +class TestHCaptcha(BaseTest): + websiteURL = "https://www.pokemoncenter.com/" + captchaUrl = "https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAlk-FmAyNOW8AUyTH_g%3D%3D&hash=5B45875B653A484CC79E57036CE9FC&cid=noJuZstmvINksqOxaXWQogbPBd01y3VaH3r-CZ4eqK4roZuelJMHVhO2rR0IySRieoAivkg74B4UpJ.xj.jVNB6-aLaW.Bwvik7__EncryD6COavwx8RmOqgZ7DK_3v&t=fe&referer=https%3A%2F%2Fwww.pokemoncenter.com%2F&s=9817&e=2b1d5a78107ded0dcdc8317aa879979ed5083a2b3a95b734dbe7871679e1403" + userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" + proxyType = "http" + proxyAddress = "1.2.3.4" + proxyPort = "8080" + kwargs_params = {"proxyLogin": "user23", "proxyPassword": "p4$$w0rd"} + + def test_methods_exists(self): + assert "captcha_handler" in DataDomeCaptcha.__dict__.keys() + assert "aio_captcha_handler" in DataDomeCaptcha.__dict__.keys() + + def test_args(self): + instance = DataDomeCaptcha( + rucaptcha_key=self.RUCAPTCHA_KEY, + websiteURL=self.websiteURL, + captchaUrl=self.captchaUrl, + userAgent=self.userAgent, + proxyType=self.proxyType, + proxyAddress=self.proxyAddress, + proxyPort=self.proxyPort, + ) + assert instance.create_task_payload["clientKey"] == self.RUCAPTCHA_KEY + assert instance.create_task_payload["task"]["type"] == DataDomeSliderEnm.DataDomeSliderTask + assert instance.create_task_payload["task"]["websiteURL"] == self.websiteURL + assert instance.create_task_payload["task"]["captchaUrl"] == self.captchaUrl + assert instance.create_task_payload["task"]["userAgent"] == self.userAgent + assert instance.create_task_payload["task"]["proxyType"] == self.proxyType + assert instance.create_task_payload["task"]["proxyAddress"] == self.proxyAddress + assert instance.create_task_payload["task"]["proxyPort"] == self.proxyPort + + def test_kwargs(self): + instance = DataDomeCaptcha( + rucaptcha_key=self.RUCAPTCHA_KEY, + websiteURL=self.websiteURL, + captchaUrl=self.captchaUrl, + userAgent=self.userAgent, + proxyType=self.proxyType, + proxyAddress=self.proxyAddress, + proxyPort=self.proxyPort, + **self.kwargs_params, + ) + assert set(self.kwargs_params.keys()).issubset(set(instance.create_task_payload["task"].keys())) + assert set(self.kwargs_params.values()).issubset(set(instance.create_task_payload["task"].values())) + + """ + Fail tests + """ + + def test_no_websiteURL(self): + with pytest.raises(TypeError): + DataDomeCaptcha( + rucaptcha_key=self.RUCAPTCHA_KEY, + captchaUrl=self.captchaUrl, + userAgent=self.userAgent, + proxyType=self.proxyType, + proxyAddress=self.proxyAddress, + proxyPort=self.proxyPort, + ) + + def test_no_captchaUrl(self): + with pytest.raises(TypeError): + DataDomeCaptcha( + rucaptcha_key=self.RUCAPTCHA_KEY, + websiteURL=self.websiteURL, + userAgent=self.userAgent, + proxyType=self.proxyType, + proxyAddress=self.proxyAddress, + proxyPort=self.proxyPort, + ) + + def test_no_userAgent(self): + with pytest.raises(TypeError): + DataDomeCaptcha( + rucaptcha_key=self.RUCAPTCHA_KEY, + websiteURL=self.websiteURL, + captchaUrl=self.captchaUrl, + proxyType=self.proxyType, + proxyAddress=self.proxyAddress, + proxyPort=self.proxyPort, + ) + + def test_no_proxyType(self): + with pytest.raises(TypeError): + DataDomeCaptcha( + rucaptcha_key=self.RUCAPTCHA_KEY, + websiteURL=self.websiteURL, + captchaUrl=self.captchaUrl, + userAgent=self.userAgent, + proxyAddress=self.proxyAddress, + proxyPort=self.proxyPort, + ) + + def test_no_proxyAddress(self): + with pytest.raises(TypeError): + DataDomeCaptcha( + rucaptcha_key=self.RUCAPTCHA_KEY, + websiteURL=self.websiteURL, + captchaUrl=self.captchaUrl, + userAgent=self.userAgent, + proxyType=self.proxyType, + proxyPort=self.proxyPort, + ) + + def test_no_proxyPort(self): + with pytest.raises(TypeError): + DataDomeCaptcha( + rucaptcha_key=self.RUCAPTCHA_KEY, + websiteURL=self.websiteURL, + captchaUrl=self.captchaUrl, + userAgent=self.userAgent, + proxyType=self.proxyType, + proxyAddress=self.proxyAddress, + )