Skip to content

Commit 34ff520

Browse files
author
Andrei
authored
Merge pull request #19 from AndreiDrang/main
0.5.1
2 parents d70bf7c + 6030029 commit 34ff520

4 files changed

Lines changed: 155 additions & 2 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.5"
1+
__version__ = "0.5.1"

src/python3_captchaai/kasada.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from python3_captchaai.core.base import BaseCaptcha
44
from python3_captchaai.core.enum import ProxyType, CaptchaTypeEnm
55
from python3_captchaai.core.config import REQUEST_URL
6-
from python3_captchaai.core.serializer import KasadaOptionsSer, CaptchaResponseSer
6+
from python3_captchaai.core.serializer import KasadaOptionsSer, CaptchaResponseSer, RequestCreateTaskSer
77

88

99
class BaseKasada(BaseCaptcha):
@@ -134,6 +134,7 @@ def captcha_handler(self, **additional_params) -> CaptchaResponseSer:
134134
Check class docstirng for more info
135135
"""
136136
self.task_params.update({**additional_params})
137+
self._prepare_create_task_payload(serializer=RequestCreateTaskSer, create_params=self.task_params)
137138
return CaptchaResponseSer(**self._create_task(url_postfix=self.task_postfix))
138139

139140
async def aio_captcha_handler(self, **additional_params) -> CaptchaResponseSer:
@@ -173,4 +174,5 @@ async def aio_captcha_handler(self, **additional_params) -> CaptchaResponseSer:
173174
Check class docstirng for more info
174175
"""
175176
self.task_params.update({**additional_params})
177+
self._prepare_create_task_payload(serializer=RequestCreateTaskSer, create_params=self.task_params)
176178
return CaptchaResponseSer(**await self._aio_create_task(url_postfix=self.task_postfix))

src/tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class BaseTest:
1616
API_KEY = os.getenv("API_KEY", "ad9053f3182ca81755768608fa758570")
1717
sleep_time = 5
1818

19+
proxyAddress = "0.0.0.0"
20+
proxyPort = 9999
21+
1922
@staticmethod
2023
def get_random_string(length: int) -> str:
2124
"""

src/tests/test_kasada.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import pytest
2+
3+
from src.tests.conftest import BaseTest
4+
from python3_captchaai.kasada import Kasada
5+
from python3_captchaai.core.enum import ProxyType
6+
7+
pageURL = "http://mywebsite.com/kasada"
8+
9+
10+
class TestFunCaptchaBase(BaseTest):
11+
def test_captcha_handler_exist(self):
12+
assert "captcha_handler" in Kasada.__dict__.keys()
13+
14+
def test_aio_captcha_handler_exist(self):
15+
assert "aio_captcha_handler" in Kasada.__dict__.keys()
16+
17+
18+
class TestKasada(BaseTest):
19+
20+
"""
21+
Success tests
22+
"""
23+
24+
@pytest.mark.parametrize("proxy_type", ProxyType.list_values())
25+
def test_params(self, proxy_type: str):
26+
Kasada(
27+
api_key=self.get_random_string(36),
28+
pageURL=pageURL,
29+
proxyAddress=self.proxyAddress,
30+
proxyType=proxy_type,
31+
proxyPort=self.proxyPort,
32+
proxyLogin=self.get_random_string(5),
33+
proxyPassword=self.get_random_string(5),
34+
)
35+
36+
@pytest.mark.parametrize("proxy_type", ProxyType.list_values())
37+
def test_params_context(self, proxy_type: str):
38+
with Kasada(
39+
api_key=self.get_random_string(36),
40+
pageURL=pageURL,
41+
proxyAddress=self.proxyAddress,
42+
proxyType=proxy_type,
43+
proxyPort=self.proxyPort,
44+
proxyLogin=self.get_random_string(5),
45+
proxyPassword=self.get_random_string(5),
46+
) as instance:
47+
pass
48+
49+
"""
50+
Failed tests
51+
"""
52+
53+
@pytest.mark.parametrize("proxy_type", ProxyType.list_values())
54+
def test_err(self, proxy_type: str):
55+
with pytest.raises(ValueError):
56+
Kasada(
57+
api_key=self.get_random_string(36),
58+
pageURL=pageURL,
59+
proxyAddress=self.proxyAddress,
60+
proxyType=proxy_type,
61+
proxyPort=self.proxyPort,
62+
proxyLogin=self.get_random_string(5),
63+
proxyPassword=self.get_random_string(5),
64+
).captcha_handler()
65+
66+
@pytest.mark.parametrize("proxy_type", ProxyType.list_values())
67+
async def test_aio_err(self, proxy_type: str):
68+
with pytest.raises(ValueError):
69+
await Kasada(
70+
api_key=self.get_random_string(36),
71+
pageURL=pageURL,
72+
proxyAddress=self.proxyAddress,
73+
proxyType=proxy_type,
74+
proxyPort=self.proxyPort,
75+
proxyLogin=self.get_random_string(5),
76+
proxyPassword=self.get_random_string(5),
77+
).aio_captcha_handler()
78+
79+
@pytest.mark.parametrize("proxy_type", ProxyType.list_values())
80+
def test_no_pageurl(self, proxy_type: str):
81+
with pytest.raises(TypeError):
82+
Kasada(
83+
api_key=self.get_random_string(36),
84+
proxyAddress=self.proxyAddress,
85+
proxyType=proxy_type,
86+
proxyPort=self.proxyPort,
87+
proxyLogin=self.get_random_string(5),
88+
proxyPassword=self.get_random_string(5),
89+
)
90+
91+
@pytest.mark.parametrize("proxy_type", ProxyType.list_values())
92+
def test_no_proxyaddress(self, proxy_type: str):
93+
with pytest.raises(TypeError):
94+
Kasada(
95+
api_key=self.get_random_string(36),
96+
pageURL=pageURL,
97+
proxyType=proxy_type,
98+
proxyPort=self.proxyPort,
99+
proxyLogin=self.get_random_string(5),
100+
proxyPassword=self.get_random_string(5),
101+
)
102+
103+
def test_no_proxytype(self):
104+
with pytest.raises(TypeError):
105+
Kasada(
106+
api_key=self.get_random_string(36),
107+
pageURL=pageURL,
108+
proxyAddress=self.proxyAddress,
109+
proxyPort=self.proxyPort,
110+
proxyLogin=self.get_random_string(5),
111+
proxyPassword=self.get_random_string(5),
112+
)
113+
114+
@pytest.mark.parametrize("proxy_type", ProxyType.list_values())
115+
def test_no_proxyport(self, proxy_type: str):
116+
with pytest.raises(TypeError):
117+
Kasada(
118+
api_key=self.get_random_string(36),
119+
pageURL=pageURL,
120+
proxyAddress=self.proxyAddress,
121+
proxyType=proxy_type,
122+
proxyLogin=self.get_random_string(5),
123+
proxyPassword=self.get_random_string(5),
124+
)
125+
126+
@pytest.mark.parametrize("proxy_type", ProxyType.list_values())
127+
def test_no_proxylogin(self, proxy_type: str):
128+
with pytest.raises(TypeError):
129+
Kasada(
130+
api_key=self.get_random_string(36),
131+
pageURL=pageURL,
132+
proxyAddress=self.proxyAddress,
133+
proxyType=proxy_type,
134+
proxyPort=self.proxyPort,
135+
proxyPassword=self.get_random_string(5),
136+
)
137+
138+
@pytest.mark.parametrize("proxy_type", ProxyType.list_values())
139+
def test_no_proxypassword(self, proxy_type: str):
140+
with pytest.raises(TypeError):
141+
Kasada(
142+
api_key=self.get_random_string(36),
143+
pageURL=pageURL,
144+
proxyAddress=self.proxyAddress,
145+
proxyType=proxy_type,
146+
proxyPort=self.proxyPort,
147+
proxyLogin=self.get_random_string(5),
148+
)

0 commit comments

Comments
 (0)