Skip to content

Commit b69faed

Browse files
committed
Final polishment
1 parent e4c924d commit b69faed

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

tests/integration/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ uv run poe integration-tests
1313

1414
To run against a different environment, also set `APIFY_INTEGRATION_TESTS_API_URL`.
1515

16+
## Structure
17+
18+
| File | Description |
19+
| --- | --- |
20+
| `test_dataset.py` | Dataset operations |
21+
| `test_key_value_store.py` | Key-value store operations |
22+
| `test_request_queue.py` | Request queue operations |
23+
| `test_storages.py` | Cross-storage tests (aliases, unnamed defaults, explicit init) |
24+
1625
## Key fixtures
1726

1827
- **`apify_client_async`** — A session-scoped `ApifyClientAsync` instance configured with the test token and API URL.
28+
- **`request_queue_apify`** — Creates a parametrized (`single`/`shared` access mode) Apify request queue on the platform, yields it, and drops it after the test. Defined in `conftest.py`.
1929
- **`prepare_test_env`** / **`_isolate_test_environment`** (autouse) — Resets global state and sets `APIFY_LOCAL_STORAGE_DIR` to a temporary directory before each test.

tests/integration/conftest.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
from crawlee import service_locator
1111

1212
import apify._actor
13+
from apify import Actor
14+
from apify.storage_clients import ApifyStorageClient
1315
from apify.storage_clients._apify._alias_resolving import AliasResolver
16+
from apify.storages import RequestQueue
1417

1518
if TYPE_CHECKING:
16-
from collections.abc import Callable
19+
from collections.abc import AsyncGenerator, Callable
1720
from pathlib import Path
1821

1922
_TOKEN_ENV_VAR = 'APIFY_TEST_USER_API_TOKEN'
@@ -78,6 +81,19 @@ def _prepare_test_env() -> None:
7881
return _prepare_test_env
7982

8083

84+
@pytest.fixture(params=['single', 'shared'])
85+
async def request_queue_apify(
86+
apify_token: str, monkeypatch: pytest.MonkeyPatch, request: pytest.FixtureRequest
87+
) -> AsyncGenerator[RequestQueue]:
88+
"""Create an instance of the Apify request queue on the platform and drop it when the test is finished."""
89+
monkeypatch.setenv(ApifyEnvVars.TOKEN, apify_token)
90+
91+
async with Actor:
92+
rq = await RequestQueue.open(storage_client=ApifyStorageClient(request_queue_access=request.param))
93+
yield rq
94+
await rq.drop()
95+
96+
8197
@pytest.fixture(autouse=True)
8298
def _isolate_test_environment(prepare_test_env: Callable[[], None]) -> None:
8399
"""Isolate the testing environment by resetting global state before each test.

tests/integration/test_key_value_store.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ._utils import generate_unique_resource_name
1111
from apify import Actor
1212
from apify.storage_clients import ApifyStorageClient
13+
from apify.storage_clients._apify._alias_resolving import AliasResolver
1314
from apify.storages import KeyValueStore
1415

1516
if TYPE_CHECKING:
@@ -87,6 +88,8 @@ async def test_set_value_in_one_context_and_get_value_in_another(
8788
service_locator._event_manager = None
8889
service_locator._storage_client = None
8990
service_locator.storage_instance_manager.clear_cache()
91+
AliasResolver._alias_map = {}
92+
AliasResolver._alias_init_lock = None
9093

9194
# Second context: get the value
9295
try:
@@ -102,6 +105,8 @@ async def test_set_value_in_one_context_and_get_value_in_another(
102105
service_locator._event_manager = None
103106
service_locator._storage_client = None
104107
service_locator.storage_instance_manager.clear_cache()
108+
AliasResolver._alias_map = {}
109+
AliasResolver._alias_init_lock = None
105110
async with Actor:
106111
kvs3 = await Actor.open_key_value_store(id=kvs_id, force_cloud=True)
107112
await kvs3.drop()

tests/integration/test_request_queue.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,12 @@
2020
from apify.storages import RequestQueue
2121

2222
if TYPE_CHECKING:
23-
from collections.abc import AsyncGenerator
24-
2523
from apify_client import ApifyClientAsync
2624
from crawlee._types import BasicCrawlingContext
2725

2826
from apify.storage_clients._apify._models import ApifyRequestQueueMetadata
2927

3028

31-
@pytest.fixture(params=['single', 'shared'])
32-
async def request_queue_apify(
33-
apify_token: str, monkeypatch: pytest.MonkeyPatch, request: pytest.FixtureRequest
34-
) -> AsyncGenerator[RequestQueue]:
35-
"""Create an instance of the Apify request queue on the platform and drop it when the test is finished."""
36-
monkeypatch.setenv(ApifyEnvVars.TOKEN, apify_token)
37-
38-
async with Actor:
39-
rq = await RequestQueue.open(storage_client=ApifyStorageClient(request_queue_access=request.param))
40-
yield rq
41-
await rq.drop()
42-
43-
4429
async def test_add_and_fetch_requests(request_queue_apify: RequestQueue) -> None:
4530
"""Test basic functionality of adding and fetching requests."""
4631

@@ -976,6 +961,7 @@ async def test_request_queue_has_stats(request_queue_apify: RequestQueue) -> Non
976961

977962

978963
async def test_rq_long_url(request_queue_apify: RequestQueue) -> None:
964+
"""Test handling of requests with long URLs and extended unique keys."""
979965
rq = request_queue_apify
980966
request = Request.from_url(
981967
'https://portal.isoss.gov.cz/irj/portal/anonymous/mvrest?path=/eosm-public-offer&officeLabels=%7B%7D&page=1&pageSize=100000&sortColumn=zdatzvsm&sortOrder=-1',
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24

35
import pytest

0 commit comments

Comments
 (0)