From b8cd6957ac9738fdedeb074df913dea5fcd3f523 Mon Sep 17 00:00:00 2001 From: Max Bohomolov Date: Wed, 29 Oct 2025 13:24:34 +0000 Subject: [PATCH] update integrations test for impit --- tests/integration/test_dataset.py | 9 +++++++-- tests/integration/test_key_value_store.py | 16 ++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tests/integration/test_dataset.py b/tests/integration/test_dataset.py index 03a6e56f..6e3c8eab 100644 --- a/tests/integration/test_dataset.py +++ b/tests/integration/test_dataset.py @@ -1,5 +1,6 @@ from __future__ import annotations +import json from unittest import mock from unittest.mock import Mock @@ -80,7 +81,9 @@ def test_public_url(self, api_token: str, api_url: str, api_public_url: str) -> dataset = apify_client.dataset('someID') # Mock the API call to return predefined response - with mock.patch.object(apify_client.http_client, 'call', return_value=Mock(text=MOCKED_API_DATASET_RESPONSE)): + mock_response = Mock() + mock_response.json.return_value = json.loads(MOCKED_API_DATASET_RESPONSE) + with mock.patch.object(apify_client.http_client, 'call', return_value=mock_response): public_url = dataset.create_items_public_url() assert public_url == ( f'{(api_public_url or DEFAULT_API_URL).strip("/")}/v2/datasets/' @@ -135,7 +138,9 @@ async def test_public_url(self, api_token: str, api_url: str, api_public_url: st dataset = apify_client.dataset('someID') # Mock the API call to return predefined response - with mock.patch.object(apify_client.http_client, 'call', return_value=Mock(text=MOCKED_API_DATASET_RESPONSE)): + mock_response = Mock() + mock_response.json.return_value = json.loads(MOCKED_API_DATASET_RESPONSE) + with mock.patch.object(apify_client.http_client, 'call', return_value=mock_response): public_url = await dataset.create_items_public_url() assert public_url == ( f'{(api_public_url or DEFAULT_API_URL).strip("/")}/v2/datasets/' diff --git a/tests/integration/test_key_value_store.py b/tests/integration/test_key_value_store.py index ac205031..298e14a6 100644 --- a/tests/integration/test_key_value_store.py +++ b/tests/integration/test_key_value_store.py @@ -1,6 +1,5 @@ from __future__ import annotations -import json from unittest import mock from unittest.mock import Mock @@ -16,7 +15,7 @@ MOCKED_ID = 'someID' -def _get_mocked_api_kvs_response(signing_key: str | None = None) -> str: +def _get_mocked_api_kvs_response(signing_key: str | None = None) -> Mock: response_data = { 'data': { 'id': MOCKED_ID, @@ -37,7 +36,9 @@ def _get_mocked_api_kvs_response(signing_key: str | None = None) -> str: if signing_key: response_data['data']['urlSigningSecretKey'] = signing_key - return json.dumps(response_data) + mock_response = Mock() + mock_response.json.return_value = response_data + return mock_response class TestKeyValueStoreSync: @@ -87,7 +88,7 @@ def test_public_url(self, api_token: str, api_url: str, api_public_url: str, sig with mock.patch.object( apify_client.http_client, 'call', - return_value=Mock(text=_get_mocked_api_kvs_response(signing_key=signing_key)), + return_value=_get_mocked_api_kvs_response(signing_key=signing_key), ): public_url = kvs.create_keys_public_url() if signing_key: @@ -112,7 +113,7 @@ def test_record_public_url(self, api_token: str, api_url: str, api_public_url: s with mock.patch.object( apify_client.http_client, 'call', - return_value=Mock(text=_get_mocked_api_kvs_response(signing_key=signing_key)), + return_value=_get_mocked_api_kvs_response(signing_key=signing_key), ): public_url = kvs.get_record_public_url(key=key) expected_signature = f'?signature={create_hmac_signature(signing_key, key)}' if signing_key else '' @@ -170,13 +171,12 @@ async def test_key_value_store_should_create_public_keys_non_expiring_url( async def test_public_url(self, api_token: str, api_url: str, api_public_url: str, signing_key: str) -> None: apify_client = ApifyClientAsync(token=api_token, api_url=api_url, api_public_url=api_public_url) kvs = apify_client.key_value_store(MOCKED_ID) - mocked_response = _get_mocked_api_kvs_response(signing_key=signing_key) # Mock the API call to return predefined response with mock.patch.object( apify_client.http_client, 'call', - return_value=Mock(text=mocked_response), + return_value=_get_mocked_api_kvs_response(signing_key=signing_key), ): public_url = await kvs.create_keys_public_url() if signing_key: @@ -201,7 +201,7 @@ async def test_record_public_url(self, api_token: str, api_url: str, api_public_ with mock.patch.object( apify_client.http_client, 'call', - return_value=Mock(text=_get_mocked_api_kvs_response(signing_key=signing_key)), + return_value=_get_mocked_api_kvs_response(signing_key=signing_key), ): public_url = await kvs.get_record_public_url(key=key) expected_signature = f'?signature={create_hmac_signature(signing_key, key)}' if signing_key else ''