|
| 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