|
1 | 1 | import pytest |
2 | 2 |
|
3 | 3 | from tests.conftest import BaseTest |
4 | | -from python3_capsolver.core.enum import ResponseStatusEnm |
| 4 | +from python3_capsolver.core.enum import MtCaptchaTypeEnm, ResponseStatusEnm |
5 | 5 | from python3_capsolver.mt_captcha import MtCaptcha |
6 | 6 | from python3_capsolver.core.serializer import CaptchaResponseSer |
7 | 7 |
|
|
11 | 11 |
|
12 | 12 |
|
13 | 13 | class TestMtCaptchaBase(BaseTest): |
| 14 | + captcha_types = (MtCaptchaTypeEnm.MtCaptchaTask, MtCaptchaTypeEnm.MtCaptchaTaskProxyLess) |
| 15 | + |
14 | 16 | def test_captcha_handler_exist(self): |
15 | 17 | assert "captcha_handler" in MtCaptcha.__dict__.keys() |
16 | 18 |
|
17 | 19 | def test_aio_captcha_handler_exist(self): |
18 | 20 | assert "aio_captcha_handler" in MtCaptcha.__dict__.keys() |
19 | 21 |
|
20 | | - def test_no_website_url(self): |
21 | | - with pytest.raises(TypeError): |
22 | | - MtCaptcha(api_key=self.API_KEY, websiteKey=websiteKey, proxy=proxy) |
23 | | - |
24 | | - def test_no_website_key(self): |
| 22 | + @pytest.mark.parametrize("captcha_type", captcha_types) |
| 23 | + def test_no_website_url(self, captcha_type: str): |
25 | 24 | with pytest.raises(TypeError): |
26 | | - MtCaptcha(api_key=self.API_KEY, websiteURL=websiteURL, proxy=proxy) |
| 25 | + MtCaptcha(api_key=self.API_KEY, captcha_type=captcha_type, websiteKey=websiteKey, proxy=proxy) |
27 | 26 |
|
28 | | - def test_no_proxy(self): |
| 27 | + @pytest.mark.parametrize("captcha_type", captcha_types) |
| 28 | + def test_no_website_key(self, captcha_type: str): |
29 | 29 | with pytest.raises(TypeError): |
30 | | - MtCaptcha(api_key=self.API_KEY, websiteURL=websiteURL, websiteKey=websiteKey) |
| 30 | + MtCaptcha(api_key=self.API_KEY, captcha_type=captcha_type, websiteURL=websiteURL, proxy=proxy) |
31 | 31 |
|
32 | 32 |
|
33 | 33 | class TestMtCaptcha(BaseTest): |
| 34 | + captcha_types = (MtCaptchaTypeEnm.MtCaptchaTask, MtCaptchaTypeEnm.MtCaptchaTaskProxyLess) |
34 | 35 | """ |
35 | 36 | Success tests |
36 | 37 | """ |
37 | 38 |
|
38 | 39 | @pytest.mark.parametrize("proxy_type", BaseTest.proxyTypes) |
39 | | - def test_params(self, proxy_type: str): |
40 | | - MtCaptcha(api_key=self.API_KEY, websiteURL=websiteURL, websiteKey=websiteKey, proxy=proxy) |
| 40 | + @pytest.mark.parametrize("captcha_type", captcha_types) |
| 41 | + def test_params(self, proxy_type: str, captcha_type: str): |
| 42 | + MtCaptcha( |
| 43 | + api_key=self.API_KEY, captcha_type=captcha_type, websiteURL=websiteURL, websiteKey=websiteKey, proxy=proxy |
| 44 | + ) |
41 | 45 |
|
42 | 46 | @pytest.mark.parametrize("proxy_type", BaseTest.proxyTypes) |
43 | | - def test_params_context(self, proxy_type: str): |
44 | | - with MtCaptcha(api_key=self.API_KEY, websiteURL=websiteURL, websiteKey=websiteKey, proxy=proxy) as instance: |
| 47 | + @pytest.mark.parametrize("captcha_type", captcha_types) |
| 48 | + def test_params_context(self, proxy_type: str, captcha_type: str): |
| 49 | + with MtCaptcha( |
| 50 | + api_key=self.API_KEY, captcha_type=captcha_type, websiteURL=websiteURL, websiteKey=websiteKey, proxy=proxy |
| 51 | + ) as instance: |
45 | 52 | pass |
46 | 53 |
|
47 | 54 | """ |
48 | 55 | Failed tests |
49 | 56 | """ |
50 | 57 |
|
51 | | - def test_proxy_err(self): |
| 58 | + @pytest.mark.parametrize("captcha_type", captcha_types) |
| 59 | + def test_proxy_err(self, captcha_type: str): |
52 | 60 | resp = MtCaptcha( |
53 | | - api_key=self.API_KEY, websiteURL=websiteURL, websiteKey=websiteKey, proxy=proxy |
| 61 | + api_key=self.API_KEY, captcha_type=captcha_type, websiteURL=websiteURL, websiteKey=websiteKey, proxy=proxy |
54 | 62 | ).captcha_handler() |
55 | 63 | assert isinstance(resp, CaptchaResponseSer) |
56 | 64 | assert resp.status == ResponseStatusEnm.Processing |
57 | 65 | assert resp.errorId == 1 |
58 | 66 | assert resp.errorCode == "ERROR_INVALID_TASK_DATA" |
59 | 67 | assert resp.solution is None |
60 | 68 |
|
61 | | - async def test_aio_proxy_err(self): |
| 69 | + @pytest.mark.parametrize("captcha_type", captcha_types) |
| 70 | + async def test_aio_proxy_err(self, captcha_type: str): |
62 | 71 | resp = await MtCaptcha( |
63 | | - api_key=self.API_KEY, websiteURL=websiteURL, websiteKey=websiteKey, proxy=proxy |
| 72 | + api_key=self.API_KEY, captcha_type=captcha_type, websiteURL=websiteURL, websiteKey=websiteKey, proxy=proxy |
64 | 73 | ).aio_captcha_handler() |
65 | 74 | assert isinstance(resp, CaptchaResponseSer) |
66 | 75 | assert resp.status == ResponseStatusEnm.Processing |
|
0 commit comments