From 4c4e29dfc89cd13d99b58c7eb377e0a98933ffa6 Mon Sep 17 00:00:00 2001 From: deedy5 <65482418+deedy5@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:29:01 +0300 Subject: [PATCH] [tests]: update post multipart encoded files tests --- tests/test_client.py | 20 +++++++++++++++++--- tests/test_defs.py | 22 ++++++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index 0c3faea..af21ff9 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,5 +1,7 @@ from time import sleep +import pytest + import certifi import primp # type: ignore @@ -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, diff --git a/tests/test_defs.py b/tests/test_defs.py index 14aff2c..0433fc9 100644 --- a/tests/test_defs.py +++ b/tests/test_defs.py @@ -1,5 +1,7 @@ from time import sleep +import pytest + import certifi import primp # type: ignore @@ -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, @@ -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" \ No newline at end of file + assert json_data["peetprint_hash"] == "7466733991096b3f4e6c0e79b0083559"