Skip to content

Commit

Permalink
Create test_mtcaptcha.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiDrang committed Dec 11, 2023
1 parent 5028374 commit a81d26f
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/test_mtcaptcha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import pytest

from tests.conftest import BaseTest
from python_rucaptcha.core.enums import MTCaptchaEnm
from python_rucaptcha.mt_captcha import MTCaptcha


class TestMTCaptcha(BaseTest):
websiteURL = "https://service.mtcaptcha.com/mtcv1/demo/index.html"
websiteKey = "MTPublic-DemoKey9M"

kwargs_params = {
"proxyType": "socks5",
"proxyAddress": BaseTest.proxyAddress,
"proxyPort": BaseTest.proxyPort,
}

def test_methods_exists(self):
assert "captcha_handler" in MTCaptcha.__dict__.keys()
assert "aio_captcha_handler" in MTCaptcha.__dict__.keys()

@pytest.mark.parametrize("method", MTCaptchaEnm.list_values())
def test_args(self, method: str):
instance = MTCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY, websiteURL=self.websiteURL, websiteKey=self.websiteKey, method=method
)
assert instance.create_task_payload["clientKey"] == self.RUCAPTCHA_KEY
assert instance.create_task_payload["task"]["type"] == method
assert instance.create_task_payload["task"]["websiteURL"] == self.websiteURL
assert instance.create_task_payload["task"]["websiteKey"] == self.websiteKey

def test_kwargs(self):
instance = MTCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY,
websiteURL=self.websiteURL,
websiteKey=self.websiteKey,
**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):
MTCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY,
websiteKey=self.websiteKey,
)

def test_no_websiteKey(self):
with pytest.raises(TypeError):
MTCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY,
websiteURL=self.websiteURL,
)

def test_wrong_method(self):
with pytest.raises(ValueError):
MTCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY,
websiteURL=self.websiteURL,
websiteKey=self.websiteKey,
method=self.get_random_string(length=5),
)

0 comments on commit a81d26f

Please sign in to comment.