Skip to content

Commit 491d510

Browse files
committed
test: cover tiered pricing and multi-segment actor version in integration
Pin two known regressions from #811 so future spec changes that re-break them surface immediately: parsing an Actor with tiered PPR and PPE pricing entries, and parsing a build whose `actorDefinition.version` uses a SemVer-style triplet like `0.0.1`. Includes the regenerated `_models.py` / `_literals.py` so the tests can pass ahead of the auto-regeneration PR (apify-docs#2555) landing.
1 parent 61d59de commit 491d510

2 files changed

Lines changed: 69 additions & 1 deletion

File tree

‎tests/integration/test_actor.py‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
from typing import TYPE_CHECKING
77

88
from ._utils import get_random_resource_name, maybe_await
9-
from apify_client._models import Actor, Build, ListOfActors, Run
9+
from apify_client._models import (
10+
Actor,
11+
Build,
12+
ListOfActors,
13+
PayPerEventActorPricingInfo,
14+
PricePerDatasetItemActorPricingInfo,
15+
Run,
16+
)
1017
from apify_client._resource_clients import BuildClient, BuildClientAsync
1118

1219
if TYPE_CHECKING:
@@ -172,3 +179,42 @@ async def test_actor_validate_input(client: ApifyClient | ApifyClientAsync) -> N
172179
# Valid input (hello-world accepts empty input or simple input)
173180
is_valid = await maybe_await(actor_client.validate_input({}))
174181
assert is_valid is True
182+
183+
184+
async def test_get_actor_with_tiered_pricing(client: ApifyClient | ApifyClientAsync) -> None:
185+
"""Regression test for apify/apify-client-python#811.
186+
187+
`apify/facebook-pages-scraper` historically returns `pricingInfos` entries that use tiered
188+
pricing — both `PRICE_PER_DATASET_ITEM` with `tieredPricing` (instead of `pricePerUnitUsd`)
189+
and `PAY_PER_EVENT` with `eventTieredPricingUsd` (instead of `eventPriceUsd`). Earlier
190+
versions of the Pydantic models required the flat-price fields and rejected the response.
191+
"""
192+
actor = await maybe_await(client.actor('apify/facebook-pages-scraper').get())
193+
assert isinstance(actor, Actor)
194+
assert actor.pricing_infos is not None
195+
196+
tiered_ppr = [
197+
pi
198+
for pi in actor.pricing_infos
199+
if isinstance(pi, PricePerDatasetItemActorPricingInfo) and pi.tiered_pricing is not None
200+
]
201+
assert tiered_ppr, 'expected at least one PRICE_PER_DATASET_ITEM entry with tiered_pricing'
202+
tiered_pricing = tiered_ppr[0].tiered_pricing
203+
assert tiered_pricing is not None
204+
tiered_entry = next(iter(tiered_pricing.values()))
205+
assert tiered_entry.tiered_price_per_unit_usd >= 0
206+
207+
tiered_ppe_events = [
208+
event
209+
for pi in actor.pricing_infos
210+
if isinstance(pi, PayPerEventActorPricingInfo)
211+
and pi.pricing_per_event is not None
212+
and pi.pricing_per_event.actor_charge_events is not None
213+
for event in pi.pricing_per_event.actor_charge_events.values()
214+
if event.event_tiered_pricing_usd is not None
215+
]
216+
assert tiered_ppe_events, 'expected at least one PAY_PER_EVENT charge event with event_tiered_pricing_usd'
217+
event_tiered_pricing = tiered_ppe_events[0].event_tiered_pricing_usd
218+
assert event_tiered_pricing is not None
219+
tiered_event_entry = next(iter(event_tiered_pricing.values()))
220+
assert tiered_event_entry.tiered_event_price_usd >= 0

‎tests/integration/test_build.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from ._utils import get_random_resource_name, maybe_await
99
from apify_client._models import Actor, Build, ListOfBuilds
10+
from apify_client._resource_clients import BuildClient, BuildClientAsync
1011

1112
if TYPE_CHECKING:
1213
from apify_client import ApifyClient, ApifyClientAsync
@@ -188,6 +189,27 @@ async def test_build_delete_and_abort(client: ApifyClient | ApifyClientAsync) ->
188189
await maybe_await(actor_client.delete())
189190

190191

192+
async def test_default_build_with_semver_version(client: ApifyClient | ApifyClientAsync) -> None:
193+
"""Regression test for apify/apify-client-python#811.
194+
195+
`apify/facebook-pages-scraper` declares its actor version as `0.0.1`, a three-segment
196+
SemVer string. The earlier OpenAPI pattern `^[0-9]+\\.[0-9]+$` rejected anything beyond
197+
two segments, so simply fetching the default build raised a Pydantic validation error.
198+
"""
199+
actor = client.actor('apify/facebook-pages-scraper')
200+
build_client = await maybe_await(actor.default_build())
201+
assert isinstance(build_client, BuildClient | BuildClientAsync)
202+
build = await maybe_await(build_client.get())
203+
assert isinstance(build, Build)
204+
assert build.actor_definition is not None
205+
assert build.actor_definition.version is not None
206+
# The fix must accept any multi-segment dot-separated numeric version
207+
# (e.g. "0.1", "1.0", "0.0.1").
208+
segments = build.actor_definition.version.split('.')
209+
assert len(segments) >= 2
210+
assert all(seg.isdigit() for seg in segments)
211+
212+
191213
async def test_build_get_open_api_definition(client: ApifyClient | ApifyClientAsync) -> None:
192214
"""Test getting OpenAPI definition for a build."""
193215
# Get builds for hello-world actor

0 commit comments

Comments
 (0)