Skip to content

Commit 34c6519

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 8387ab7 commit 34c6519

4 files changed

Lines changed: 128 additions & 10 deletions

File tree

‎src/apify_client/_literals.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
'expired-conference-token',
150150
'failed-to-charge-user',
151151
'final-invoice-negative',
152+
'full-permission-actor-not-approved',
152153
'github-branch-empty',
153154
'github-issue-already-exists',
154155
'github-public-key-not-found',
@@ -320,6 +321,7 @@
320321
'requested-dataset-view-does-not-exist',
321322
'resume-token-expired',
322323
'run-failed',
324+
'run-input-body-not-valid-json',
323325
'run-timeout-exceeded',
324326
'russia-is-evil',
325327
'same-user',

‎src/apify_client/_models.py‎

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,42 @@ class Actor(BaseModel):
7878

7979
@docs_group('Models')
8080
class ActorChargeEvent(BaseModel):
81+
"""Definition of a single chargeable event for a pay-per-event Actor.
82+
Each event is either flat-priced (`eventPriceUsd` is set) or
83+
tier-priced (`eventTieredPricingUsd` is set); the two are mutually
84+
exclusive.
85+
86+
"""
87+
8188
model_config = ConfigDict(
8289
extra='allow',
8390
populate_by_name=True,
8491
)
85-
event_price_usd: Annotated[float, Field(alias='eventPriceUsd')]
8692
event_title: Annotated[str, Field(alias='eventTitle')]
93+
"""
94+
Human-readable title shown to users in the billing UI.
95+
"""
8796
event_description: Annotated[str, Field(alias='eventDescription')]
97+
"""
98+
Human-readable description of what triggers this event.
99+
"""
100+
event_price_usd: Annotated[float | None, Field(alias='eventPriceUsd')] = None
101+
"""
102+
Flat price per event in USD. Present only for non-tiered events;
103+
mutually exclusive with `eventTieredPricingUsd`.
104+
105+
"""
106+
event_tiered_pricing_usd: Annotated[
107+
dict[str, TieredPricingPerEventEntry] | None, Field(alias='eventTieredPricingUsd')
108+
] = None
109+
is_primary_event: Annotated[bool | None, Field(alias='isPrimaryEvent')] = None
110+
"""
111+
Whether this event is the Actor's primary chargeable event.
112+
"""
113+
is_one_time_event: Annotated[bool | None, Field(alias='isOneTimeEvent')] = None
114+
"""
115+
Whether this event can only be charged once per Actor run.
116+
"""
88117

89118

90119
@docs_group('Models')
@@ -103,9 +132,9 @@ class ActorDefinition(BaseModel):
103132
"""
104133
The name of the Actor.
105134
"""
106-
version: Annotated[str | None, Field(pattern='^[0-9]+\\.[0-9]+$')] = None
135+
version: Annotated[str | None, Field(pattern='^[0-9]+(\\.[0-9]+)+$')] = None
107136
"""
108-
The version of the Actor, specified in the format [Number].[Number], e.g., 0.1, 1.0.
137+
The version of the Actor, typically a dot-separated sequence of numbers (e.g., `0.1`, `1.0`, or `0.0.1`).
109138
"""
110139
build_tag: Annotated[str | None, Field(alias='buildTag')] = None
111140
"""
@@ -530,6 +559,12 @@ class CommonActorPricingInfo(BaseModel):
530559
notified_about_future_change_at: Annotated[AwareDatetime | None, Field(alias='notifiedAboutFutureChangeAt')] = None
531560
notified_about_change_at: Annotated[AwareDatetime | None, Field(alias='notifiedAboutChangeAt')] = None
532561
reason_for_change: Annotated[str | None, Field(alias='reasonForChange')] = None
562+
is_price_change_notification_suppressed: Annotated[
563+
bool | None, Field(alias='isPriceChangeNotificationSuppressed')
564+
] = None
565+
force_contains_significant_price_change: Annotated[
566+
bool | None, Field(alias='forceContainsSignificantPriceChange')
567+
] = None
533568

534569

535570
@docs_group('Models')
@@ -1793,7 +1828,13 @@ class PricePerDatasetItemActorPricingInfo(CommonActorPricingInfo):
17931828
"""
17941829
Name of the unit that is being charged
17951830
"""
1796-
price_per_unit_usd: Annotated[float, Field(alias='pricePerUnitUsd')]
1831+
price_per_unit_usd: Annotated[float | None, Field(alias='pricePerUnitUsd')] = None
1832+
"""
1833+
Price per unit in USD. Mutually exclusive with `tieredPricing` —
1834+
exactly one of the two is present on a pricing record.
1835+
1836+
"""
1837+
tiered_pricing: Annotated[dict[str, TieredPricingPerDatasetItemEntry] | None, Field(alias='tieredPricing')] = None
17971838

17981839

17991840
@docs_group('Models')
@@ -3034,23 +3075,30 @@ class TestWebhookResponse(BaseModel):
30343075

30353076

30363077
@docs_group('Models')
3037-
class UnknownBuildTagError(BaseModel):
3078+
class TieredPricingPerDatasetItemEntry(BaseModel):
3079+
"""A single tier's price-per-dataset-item entry."""
3080+
30383081
model_config = ConfigDict(
30393082
extra='allow',
30403083
populate_by_name=True,
30413084
)
3042-
error: UnknownBuildTagErrorDetail | None = None
3085+
tiered_price_per_unit_usd: Annotated[float, Field(alias='tieredPricePerUnitUsd')]
3086+
"""
3087+
Price per unit in USD for this tier.
3088+
"""
30433089

30443090

30453091
@docs_group('Models')
3046-
class UnknownBuildTagErrorDetail(ErrorDetail):
3092+
class TieredPricingPerEventEntry(BaseModel):
3093+
"""A single tier's price-per-event entry."""
3094+
30473095
model_config = ConfigDict(
30483096
extra='allow',
30493097
populate_by_name=True,
30503098
)
3051-
type: Annotated[Literal['unknown-build-tag'], Field(title='ErrorType')] = 'unknown-build-tag'
3099+
tiered_event_price_usd: Annotated[float, Field(alias='tieredEventPriceUsd')]
30523100
"""
3053-
Machine-processable error type identifier.
3101+
Price per event in USD for this tier.
30543102
"""
30553103

30563104

‎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)