Skip to content

Commit

Permalink
Update test_funcaptcha.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiDrang committed Dec 7, 2023
1 parent 03af6b1 commit d61c6ef
Showing 1 changed file with 42 additions and 34 deletions.
76 changes: 42 additions & 34 deletions tests/test_funcaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ class TestFunCaptcha(BaseTest):
"https://api.funcaptcha.com/tile-game-lite-mode/fc/api/nojs/?pkey=69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC&lang=en"
)
surl = "https://client-api.arkoselabs.com"

kwargs_params = {
"funcaptchaApiJSSubdomain": "sample-api.arkoselabs.com",
"userAgent": "Some specific user agent",
"proxyType": "socks5",
"proxyAddress": BaseTest.proxyAddress,
"proxyPort": BaseTest.proxyPort,
}
"""
Success tests
"""
Expand All @@ -21,20 +27,37 @@ def test_methods_exists(self):
assert "captcha_handler" in FunCaptcha.__dict__.keys()
assert "aio_captcha_handler" in FunCaptcha.__dict__.keys()

@pytest.mark.parametrize("method", FunCaptchaEnm.list_values())
def test_args(self, method: str):
instance = FunCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY,
websiteURL=self.pageurl,
websitePublicKey=self.publickey,
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.pageurl

def test_kwargs(self):
instance = FunCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY,
websiteURL=self.pageurl,
websitePublicKey=self.publickey,
method=FunCaptchaEnm.FunCaptchaTaskProxyless,
**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()))

def test_basic_data(self):
instance = FunCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY,
pageurl=self.pageurl,
publickey=self.publickey,
surl=self.surl,
websiteURL=self.pageurl,
websitePublicKey=self.publickey,
method=FunCaptchaEnm.FunCaptchaTaskProxyless.value,
)

assert instance.create_task_payload["method"] == FunCaptchaEnm.FunCaptchaTaskProxyless.value
assert instance.create_task_payload["pageurl"] == self.pageurl
assert instance.create_task_payload["publickey"] == self.publickey
assert instance.create_task_payload["surl"] == self.surl

result = instance.captcha_handler()

assert isinstance(result, dict) is True
Expand All @@ -52,17 +75,11 @@ def test_basic_data(self):
async def test_aio_basic_data(self):
instance = FunCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY,
pageurl=self.pageurl,
publickey=self.publickey,
surl=self.surl,
websiteURL=self.pageurl,
websitePublicKey=self.publickey,
method=FunCaptchaEnm.FunCaptchaTaskProxyless.value,
)

assert instance.create_task_payload["method"] == FunCaptchaEnm.FunCaptchaTaskProxyless.value
assert instance.create_task_payload["pageurl"] == self.pageurl
assert instance.create_task_payload["publickey"] == self.publickey
assert instance.create_task_payload["surl"] == self.surl

result = await instance.aio_captcha_handler()

assert isinstance(result, dict) is True
Expand All @@ -79,29 +96,21 @@ async def test_aio_basic_data(self):
def test_context_basic_data(self):
with FunCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY,
pageurl=self.pageurl,
publickey=self.publickey,
surl=self.surl,
websiteURL=self.pageurl,
websitePublicKey=self.publickey,
method=FunCaptchaEnm.FunCaptchaTaskProxyless.value,
) as instance:
assert instance.create_task_payload["method"] == FunCaptchaEnm.FunCaptchaTaskProxyless.value
assert instance.create_task_payload["pageurl"] == self.pageurl
assert instance.create_task_payload["publickey"] == self.publickey
assert instance.create_task_payload["surl"] == self.surl
assert instance.captcha_handler()

@pytest.mark.asyncio
async def test_context_aio_basic_data(self):
async with FunCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY,
pageurl=self.pageurl,
publickey=self.publickey,
surl=self.surl,
websiteURL=self.pageurl,
websitePublicKey=self.publickey,
method=FunCaptchaEnm.FunCaptchaTaskProxyless.value,
) as instance:
assert instance.create_task_payload["method"] == FunCaptchaEnm.FunCaptchaTaskProxyless.value
assert instance.create_task_payload["pageurl"] == self.pageurl
assert instance.create_task_payload["publickey"] == self.publickey
assert instance.create_task_payload["surl"] == self.surl
assert await instance.aio_captcha_handler()

"""
Fail tests
Expand All @@ -111,8 +120,7 @@ def test_wrong_method(self):
with pytest.raises(ValueError):
FunCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY,
pageurl=self.pageurl,
publickey=self.publickey,
surl=self.surl,
websiteURL=self.pageurl,
websitePublicKey=self.publickey,
method=self.get_random_string(length=5),
)

0 comments on commit d61c6ef

Please sign in to comment.