Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tests/integration/test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import json
from unittest import mock
from unittest.mock import Mock

Expand Down Expand Up @@ -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/'
Expand Down Expand Up @@ -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/'
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/test_key_value_store.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import json
from unittest import mock
from unittest.mock import Mock

Expand All @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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 ''
Expand Down Expand Up @@ -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:
Expand All @@ -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 ''
Expand Down
Loading