Skip to content

Commit c19bc1f

Browse files
committed
ci: add new tests and CI setup for capmonster tasks
1 parent c84af28 commit c19bc1f

6 files changed

Lines changed: 131 additions & 9 deletions

File tree

.github/dependabot.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
version: 2
22
updates:
33
- package-ecosystem: "pip"
4-
directory: "/capmonster_python"
5-
schedule:
6-
interval: "daily"
7-
- package-ecosystem: "npm"
8-
directory: "/docs"
4+
directory: "/src/capmonster_python"
95
schedule:
106
interval: "weekly"
11-
ignore:
12-
- dependency-name: "*"

.github/workflows/tests.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Run Pytest Tests
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
paths:
7+
- "tests/**"
8+
- ".github/workflows/test.yml"
9+
- "**.py"
10+
pull_request:
11+
branches: [ "master" ]
12+
workflow_dispatch:
13+
14+
jobs:
15+
test:
16+
runs-on: ubuntu-latest
17+
18+
env:
19+
API_KEY: ${{ secrets.API_KEY }}
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v3
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: '3.10'
29+
30+
- name: Install dependencies
31+
run: |
32+
pip install -r requirements.txt
33+
pip install pytest
34+
35+
- name: Run tests
36+
run: |
37+
pytest tests/

src/capmonster_python/methods.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class GetBalancePayload(BaseModel):
1010
Represents a payload for retrieving the balance.
1111
1212
Attributes:
13-
clientKey (str): The key representing the client, used for identifying
14-
the client in balance-related operations.
13+
clientKey (str): The key representing the client, used for identifying
14+
the client in balance-related operations.
1515
"""
1616
clientKey: str = Field(..., description="Client key")
1717

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from capmonster_python import ComplexImageRecognitionTask
2+
3+
4+
def test_to_request():
5+
task = ComplexImageRecognitionTask(
6+
imagesBase64=["first", "second", "third"],
7+
task="oocl_rotate_double_new"
8+
)
9+
result = task.to_request()
10+
assert result["type"] == "ComplexImageTask"
11+
assert result["class"] == "recognition"
12+
assert result["metadata"]["Task"] == "oocl_rotate_double_new"

tests/datadome_test.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os
2+
3+
import pytest
4+
5+
from capmonster_python import DataDomeTask, DataDomeMetadata, CapmonsterClient
6+
7+
API_KEY = os.getenv("API_KEY")
8+
WEBSITE_URL = "https://antoinevastel.com/bots/datadome"
9+
METADATA = DataDomeMetadata(
10+
captchaUrl="https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAJxx4dfgwjzwAQW0ctQ%3D%3D&hash"
11+
"=D66B23AC3F48A302A7654416846381&cid=d3k5rbDsu8cq0kmPHISS3hsC3f4qeL_K12~G33PrE4fbkmDYSul6l0Ze_aG5sUHLKG0676UpTv6GFvUgIActglZF33GTodOoRhEDkMMsuWTodlYa3YYQ9xKy9J89PAWh&t=fe&referer=https%3A%2F%2Fantoinevastel.com%2Fbots%2Fdatadome&s=21705&e=04fc682817ba89bf8fa4b18031fa53294fa0fb7449d95c036a1986413e6dfc7d",
12+
datadomeCookie="datadome=d3k5rbDsu8cq0kmPHISS3hsC3f4qeL_K12~G33PrE4fbkmDYSul6l0Ze_aG5sUHLKG0676UpTv6GFvUgIActglZF33GTodOoRhEDkMMsuWTodlYa3YYQ9xKy9J89PAWh"
13+
)
14+
15+
16+
def test_to_request():
17+
task = DataDomeTask(
18+
websiteURL="https://example.com",
19+
metadata=DataDomeMetadata(
20+
htmlPageBase64="base64_example",
21+
datadomeCookie="cookie1=value1; cookie2=value2;"
22+
)
23+
)
24+
result = task.to_request()
25+
assert result["type"] == "CustomTask"
26+
assert result["class"] == "DataDome"
27+
assert result["metadata"]["htmlPageBase64"] == "base64_example"
28+
assert result["metadata"]["datadomeCookie"] == "cookie1=value1; cookie2=value2;"
29+
30+
31+
@pytest.mark.skipif(API_KEY is None, reason="API_KEY is not set")
32+
async def test_create_task_async():
33+
client = CapmonsterClient(API_KEY, timeout=30.0)
34+
task_id = client.create_task(task=DataDomeTask(websiteURL=WEBSITE_URL, metadata=METADATA))
35+
assert task_id != 0
36+
assert task_id != 0
37+
38+
39+
@pytest.mark.asyncio
40+
@pytest.mark.skipif(API_KEY is None, reason="API_KEY is not set")
41+
async def test_create_task_async():
42+
client = CapmonsterClient(API_KEY, timeout=30.0)
43+
task_id = await client.create_task_async(task=DataDomeTask(websiteURL=WEBSITE_URL, metadata=METADATA))
44+
assert task_id != 0

tests/geetest_test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
3+
import pytest
4+
5+
from capmonster_python import CapmonsterClient, GeeTestV4Task
6+
7+
API_KEY = os.getenv("API_KEY")
8+
WEBSITE_URL = "https://faucetpay.io/account/logi"
9+
GT = "4eb8b0c2b27f3365b9244d9da81638c6"
10+
11+
12+
def test_to_request():
13+
task = GeeTestV4Task(
14+
websiteURL="https://example.com",
15+
gt="gt_example"
16+
)
17+
result = task.to_request()
18+
assert result["type"] == "GeeTestTask"
19+
assert result["gt"] == "gt_example"
20+
assert result["websiteURL"] == "https://example.com"
21+
22+
23+
@pytest.mark.skipif(API_KEY is None, reason="API_KEY is not set")
24+
async def test_create_task_async():
25+
client = CapmonsterClient(API_KEY, timeout=30.0)
26+
task_id = client.create_task(task=GeeTestV4Task(websiteURL=WEBSITE_URL, gt=GT))
27+
assert task_id != 0
28+
29+
30+
@pytest.mark.asyncio
31+
@pytest.mark.skipif(API_KEY is None, reason="API_KEY is not set")
32+
async def test_create_task_async():
33+
client = CapmonsterClient(API_KEY, timeout=30.0)
34+
task_id = await client.create_task_async(task=GeeTestV4Task(websiteURL=WEBSITE_URL, gt=GT))
35+
assert task_id != 0

0 commit comments

Comments
 (0)