Skip to content

Commit

Permalink
[tests]: update post multipart encoded files tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deedy5 committed Jan 7, 2025
1 parent 562ab23 commit 4c4e29d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
20 changes: 17 additions & 3 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from time import sleep

import pytest

import certifi
import primp # type: ignore

Expand Down Expand Up @@ -200,14 +202,26 @@ def test_client_post_json():
assert json_data["json"] == data


@retry()
def test_client_post_files():
@pytest.fixture(scope="session")
def test_files(tmp_path_factory):
tmp_path_factory.mktemp("data")
temp_file1 = tmp_path_factory.mktemp("data") / "img1.png"
with open(temp_file1, "w") as f:
f.write("aaa111")
temp_file2 = tmp_path_factory.mktemp("data") / "img2.png"
with open(temp_file2, "w") as f:
f.write("bbb222")
return str(temp_file1), str(temp_file2)


def test_client_post_files(test_files):
temp_file1, temp_file2 = test_files
client = primp.Client()
auth_bearer = "bearerXXXXXXXXXXXXXXXXXXXX"
headers = {"X-Test": "test"}
cookies = {"ccc": "ddd", "cccc": "dddd"}
params = {"x": "aaa", "y": "bbb"}
files = {"file1": b"aaa111", "file2": b"bbb222"}
files = {"file1": temp_file1, "file2": temp_file2}
response = client.post(
"https://httpbin.org/anything",
auth_bearer=auth_bearer,
Expand Down
22 changes: 18 additions & 4 deletions tests/test_defs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from time import sleep

import pytest

import certifi
import primp # type: ignore

Expand Down Expand Up @@ -196,13 +198,25 @@ def test_post_json():
assert json_data["json"] == data


@retry()
def test_client_post_files():
@pytest.fixture(scope="session")
def test_files(tmp_path_factory):
tmp_path_factory.mktemp("data")
temp_file1 = tmp_path_factory.mktemp("data") / "img1.png"
with open(temp_file1, "w") as f:
f.write("aaa111")
temp_file2 = tmp_path_factory.mktemp("data") / "img2.png"
with open(temp_file2, "w") as f:
f.write("bbb222")
return str(temp_file1), str(temp_file2)


def test_client_post_files(test_files):
temp_file1, temp_file2 = test_files
auth_bearer = "bearerXXXXXXXXXXXXXXXXXXXX"
headers = {"X-Test": "test"}
cookies = {"ccc": "ddd", "cccc": "dddd"}
params = {"x": "aaa", "y": "bbb"}
files = {"file1": b"aaa111", "file2": b"bbb222"}
files = {"file1": temp_file1, "file2": temp_file2}
response = primp.post(
"https://httpbin.org/anything",
auth_bearer=auth_bearer,
Expand Down Expand Up @@ -296,4 +310,4 @@ def test_get_impersonate_chrome131():
json_data = response.json()
assert json_data["ja4"] == "t13d1516h2_8daaf6152771_b1ff8ab2d16f"
assert json_data["akamai_hash"] == "90224459f8bf70b7d0a8797eb916dbc9"
assert json_data["peetprint_hash"] == "7466733991096b3f4e6c0e79b0083559"
assert json_data["peetprint_hash"] == "7466733991096b3f4e6c0e79b0083559"

0 comments on commit 4c4e29d

Please sign in to comment.