|
6 | 6 | from typing import TYPE_CHECKING |
7 | 7 |
|
8 | 8 | 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 | +) |
10 | 17 | from apify_client._resource_clients import BuildClient, BuildClientAsync |
11 | 18 |
|
12 | 19 | if TYPE_CHECKING: |
@@ -172,3 +179,42 @@ async def test_actor_validate_input(client: ApifyClient | ApifyClientAsync) -> N |
172 | 179 | # Valid input (hello-world accepts empty input or simple input) |
173 | 180 | is_valid = await maybe_await(actor_client.validate_input({})) |
174 | 181 | 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 |
0 commit comments