|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING |
| 4 | + |
| 5 | +if TYPE_CHECKING: |
| 6 | + from apify_client import ApifyClientAsync |
| 7 | + |
| 8 | + |
| 9 | +async def test_get_public_actor(apify_client_async: ApifyClientAsync) -> None: |
| 10 | + """Test getting a public actor by ID.""" |
| 11 | + # Use a well-known public actor (Apify's web scraper) |
| 12 | + actor = await apify_client_async.actor('apify/web-scraper').get() |
| 13 | + |
| 14 | + assert actor is not None |
| 15 | + assert actor.id is not None |
| 16 | + assert actor.name == 'web-scraper' |
| 17 | + assert actor.username == 'apify' |
| 18 | + |
| 19 | + |
| 20 | +async def test_get_actor_by_full_name(apify_client_async: ApifyClientAsync) -> None: |
| 21 | + """Test getting an actor using username/actorname format.""" |
| 22 | + actor = await apify_client_async.actor('apify/hello-world').get() |
| 23 | + |
| 24 | + assert actor is not None |
| 25 | + assert actor.name == 'hello-world' |
| 26 | + assert actor.username == 'apify' |
| 27 | + |
| 28 | + |
| 29 | +async def test_list_actors_my(apify_client_async: ApifyClientAsync) -> None: |
| 30 | + """Test listing actors created by the user.""" |
| 31 | + actors_page = await apify_client_async.actors().list(my=True, limit=10) |
| 32 | + |
| 33 | + assert actors_page is not None |
| 34 | + assert actors_page.items is not None |
| 35 | + # User may have 0 actors |
| 36 | + assert isinstance(actors_page.items, list) |
| 37 | + |
| 38 | + |
| 39 | +async def test_list_actors_pagination(apify_client_async: ApifyClientAsync) -> None: |
| 40 | + """Test listing actors with pagination parameters.""" |
| 41 | + # List all actors (public + owned), should return some results |
| 42 | + actors_page = await apify_client_async.actors().list(limit=5, offset=0) |
| 43 | + |
| 44 | + assert actors_page is not None |
| 45 | + assert actors_page.items is not None |
| 46 | + assert isinstance(actors_page.items, list) |
| 47 | + # Should have at least some actors (public ones exist) |
| 48 | + assert len(actors_page.items) >= 0 |
| 49 | + |
| 50 | + |
| 51 | +async def test_list_actors_sorting(apify_client_async: ApifyClientAsync) -> None: |
| 52 | + """Test listing actors with sorting.""" |
| 53 | + actors_page = await apify_client_async.actors().list(limit=10, desc=True, sort_by='createdAt') |
| 54 | + |
| 55 | + assert actors_page is not None |
| 56 | + assert actors_page.items is not None |
| 57 | + assert isinstance(actors_page.items, list) |
0 commit comments