Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(warehouse-sources): add partnerize conversion items, advertisers and commissions (#124784)

Tom Owersb19b1f630843
diff --git a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt
index af11107a3d90..210138414af6 100644
--- a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt
+++ b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt
@@ -840,8 +840,6 @@
1 products/warehouse_sources/backend/temporal/data_imports/sources/papersign/settings.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/pardot/pardot.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/pardot/settings.py
-1 products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/partnerize.py
-1 products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/settings.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/partnerstack/partnerstack.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/partnerstack/settings.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/payfit/payfit.py
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index 2019eff02c3e..9214ba454813 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -9161,10 +9161,10 @@ Today (12): `campaigns`, `clicks`, `conversion_metrics`, `conversion_types`, `co
Diffed against: <https://api-docs.partnerize.com/partner/>
-- [ ] `/reporting/report_publisher/publisher/{publisher_id}/payable` — payable commission per conversion - the money side of the clicks/conversions already synced (high)
-- [ ] `/reporting/export/export/conversion_item.csv (conversion items)` — basket/line-item detail for conversions we already sync (high)
-- [ ] `/v2/campaigns/{campaignId}/publishers/{publisherId}/commissions/active (also /default, /campaign, /voucher, /promotion, /tier)` — commission rate card that resolves the campaign IDs carried on conversions (high)
-- [ ] `/v2/publishers/{publisherId}/discovery/advertisers (brands)` — advertiser/brand lookup resolving the campaign-to-brand relationship on synced campaigns (high)
+- [ ] `/reporting/report_publisher/publisher/{publisher_id}/payable` — payable commission per conversion - the money side of the clicks/conversions already synced (high); skipped: the spec documents it as per-currency totals with an untyped item list and no date window, and each `conversion_items` row already carries a `payable` flag
+- [x] `/reporting/export/export/conversion_item.csv (conversion items)` — basket/line-item detail for conversions we already sync (high). Added as `conversion_items`, read from the JSON conversion report's nested items rather than the CSV export, so it pages and syncs incrementally like `conversions`.
+- [x] `/v2/campaigns/{campaignId}/publishers/{publisherId}/commissions/active (also /default, /campaign, /voucher, /promotion, /tier)` — commission rate card that resolves the campaign IDs carried on conversions (high). Added as `commissions` (fan-out over `campaigns`). The per-type routes skipped: `/active` already returns all of their rows.
+- [x] `/v2/publishers/{publisherId}/discovery/advertisers (brands)` — advertiser/brand lookup resolving the campaign-to-brand relationship on synced campaigns (high). Added as `advertisers`.
- [ ] `/user/publisher/{publisher_id}/campaign/{campaign_id}/voucher` — voucher-code lookup for attributing conversions to promo codes (medium)
- [ ] `/user/publisher/{publisher_id}/selfbill` — self-billing invoices, the settlement layer over payable commission (medium)
- [ ] `/user/publisher/{publisher_id}/payment/summary` — payments summary for reconciling earnings against payouts (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/canonical_descriptions.py
index 54c33ea578ce..e7a93b3478e8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/canonical_descriptions.py
@@ -122,6 +122,55 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"ref_user_context_id": "Unique identifier for the user context.",
},
},
+ "conversion_items": {
+ "description": "Line items of the partner's conversions, one row per item, with the item's value, commission, and status.",
+ "docs_url": "https://api-docs.partnerize.com/partner/#operation/partner-conversions",
+ "columns": {
+ "conversion_item_id": "Unique identifier for the item within its conversion.",
+ "conversion_id": "Identifier of the conversion the item belongs to.",
+ "campaign_id": "Identifier of the campaign the conversion belongs to.",
+ "conversion_time": "Datetime the parent conversion occurred.",
+ "last_modified": "Datetime the parent conversion was last updated.",
+ "currency": "Currency of the item value and commission.",
+ "sku": "The brand's SKU for the item.",
+ "category": "The brand's product category for the item.",
+ "item_value": "Value of the item.",
+ "item_publisher_commission": "Commission the partner earns on the item.",
+ "item_status": "Status of the item (pending, approved, or rejected).",
+ "last_update": "Datetime the item was last updated.",
+ "approved_at": "Datetime the item was approved.",
+ "reject_reason": "Reason the brand gave for rejecting the item.",
+ "publisher_self_bill_id": "Identifier of the self-bill invoice that paid the item.",
+ "voucher_codes": "Voucher codes applied to the item.",
+ "payable": "Whether the item's commission is payable to the partner.",
+ },
+ },
+ "advertisers": {
+ "description": "Brands with campaigns the partner can join, with each campaign and the partner's status on it.",
+ "docs_url": "https://api-docs.partnerize.com/partner/#operation/getBrands",
+ "columns": {
+ "id": "Unique identifier for the brand (advertiser).",
+ "name": "Name of the brand.",
+ "display_name": "Display name of the brand.",
+ "network": "Network the brand belongs to.",
+ "campaigns": "Campaigns of the brand, each with the partner's status (AVAILABLE, REQUESTED, INVITED, or REJECTED).",
+ },
+ },
+ "commissions": {
+ "description": "Active commissions (default, campaign, voucher, promotional, and tier) for the partner on each approved campaign.",
+ "docs_url": "https://api-docs.partnerize.com/partner/#operation/get-active-publisher-commissions",
+ "columns": {
+ "id": "Identifier of the commission.",
+ "campaign_id": "Identifier of the campaign the commission applies to.",
+ "type": "Type of the commission (default, campaign, promotional, voucher, or tier).",
+ "start_date": "Datetime the commission starts.",
+ "end_date": "Datetime the commission ends.",
+ "status": "Status of the commission (ACTIVE, RETIRED, DELETED, or SCHEDULED).",
+ "commission_based_on_field": "Tracking field used to calculate the partner commission.",
+ "meta_fields": "Meta field rules that select the conversions the commission applies to.",
+ "rates": "Commission rates of the commission.",
+ },
+ },
"conversion_types": {
"description": "Reference list of conversion types (e.g. sale, lead) used by campaigns.",
"docs_url": "https://api-docs.partnerize.com/partner/#operation/List%20Conversion%20Type",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/partnerize.py b/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/partnerize.py
index 4bc865545d7f..888463134eb8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/partnerize.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/partnerize.py
@@ -1,7 +1,7 @@
import dataclasses
from collections.abc import Callable
from datetime import UTC, date, datetime
-from typing import Any, Optional
+from typing import Any, Optional, cast
from dateutil import parser as dateutil_parser
from requests import Request, Response
@@ -12,14 +12,22 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
RESTAPIConfig,
rest_api_resource,
)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ build_dependent_resource,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
BaseNextUrlPaginator,
BasePaginator,
)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.resource import Resource
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import ClientConfig
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probe
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
-from products.warehouse_sources.backend.temporal.data_imports.sources.partnerize.settings import PARTNERIZE_ENDPOINTS
+from products.warehouse_sources.backend.temporal.data_imports.sources.partnerize.settings import (
+ PARTNERIZE_ENDPOINTS,
+ PartnerizeEndpointConfig,
+)
PARTNERIZE_BASE_URL = "https://api.partnerize.com"
# The report endpoints page at a fixed server-side size of 300 rows (echoed in the response's
@@ -30,13 +38,15 @@ REPORT_PAGE_LIMIT = 300
DEFAULT_START_DATE = "2010-01-01T00:00:00Z"
[email protected](frozen=True)
class PartnerizeResumeConfig:
# Report endpoints resume from the row offset within the current date window; the window
# itself is recomputed deterministically from the job's incremental inputs.
offset: int | None = None
# List endpoints resume from the hypermedia next-page URL.
next_url: str | None = None
+ # Fan-out endpoints resume from the shared fan-out helper's checkpoint.
+ fanout_state: dict[str, Any] | None = None
def _format_start_date(value: Any) -> str:
@@ -156,6 +166,86 @@ def _make_unwrap(item_key: Optional[str]) -> Callable[[dict[str, Any]], dict[str
return unwrap
+def _make_row_map(
+ config: PartnerizeEndpointConfig,
+) -> Callable[[dict[str, Any]], dict[str, Any] | list[dict[str, Any]]]:
+ """Unwrap each item and, for endpoints with an ``explode_key``, emit one row per nested element."""
+ unwrap = _make_unwrap(config.item_key)
+ if config.explode_key is None:
+ return unwrap
+ explode_key = config.explode_key
+
+ def explode(item: dict[str, Any]) -> list[dict[str, Any]]:
+ inner = unwrap(item)
+ children = inner.get(explode_key)
+ if not isinstance(children, list):
+ return []
+ parent = {name: inner.get(name) for name in config.explode_parent_fields}
+ # Parent fields win so a nested field of the same name can't break the primary key.
+ return [{**child, **parent} for child in children if isinstance(child, dict)]
+
+ return explode
+
+
+def _client_config(application_key: str, user_api_key: str, paginator: BasePaginator) -> ClientConfig:
+ return {
+ "base_url": PARTNERIZE_BASE_URL,
+ # Auth (Basic) is supplied via the framework auth config so its secret is redacted from
+ # raised errors; only the non-secret Accept header is set here.
+ "headers": {"Accept": "application/json"},
+ "auth": {"type": "http_basic", "username": application_key, "password": user_api_key},
+ "paginator": paginator,
+ }
+
+
+def _fanout_resource(
+ application_key: str,
+ user_api_key: str,
+ publisher_id: str,
+ config: PartnerizeEndpointConfig,
+ team_id: int,
+ job_id: str,
+ resumable_source_manager: ResumableSourceManager[PartnerizeResumeConfig],
+) -> Resource:
+ assert config.fanout is not None
+ parent = PARTNERIZE_ENDPOINTS[config.fanout.parent_name]
+
+ resume = resumable_source_manager.load_state() if resumable_source_manager.can_resume() else None
+ initial_fanout_state = resume.fanout_state if resume is not None else None
+
+ def save_fanout_checkpoint(state: Optional[dict[str, Any]]) -> None:
+ if state:
+ resumable_source_manager.save_state(PartnerizeResumeConfig(fanout_state=state))
+
+ return cast(
+ Resource,
+ build_dependent_resource(
+ endpoint_configs={config.name: config, parent.name: parent},
+ child_endpoint=config.name,
+ fanout=config.fanout,
+ client_config=_client_config(application_key, user_api_key, _NextPagePaginator()),
+ path_format_values={"publisher_id": publisher_id},
+ team_id=team_id,
+ job_id=job_id,
+ db_incremental_field_last_value=None,
+ page_size_param=None,
+ parent_endpoint_extra={
+ "paginator": _NextPagePaginator(),
+ "data_selector": parent.data_key,
+ "data_selector_malformed_retryable": True,
+ },
+ parent_data_map=_make_row_map(parent),
+ child_endpoint_extra={
+ "paginator": _NextPagePaginator(),
+ "data_selector": config.data_key,
+ "data_selector_malformed_retryable": True,
+ },
+ resume_hook=save_fanout_checkpoint,
+ initial_paginator_state=initial_fanout_state,
+ ),
+ )
+
+
def partnerize_source(
application_key: str,
user_api_key: str,
@@ -170,6 +260,17 @@ def partnerize_source(
) -> SourceResponse:
config = PARTNERIZE_ENDPOINTS[endpoint]
+ if config.fanout is not None:
+ return SourceResponse(
+ name=endpoint,
+ items=lambda: _fanout_resource(
+ application_key, user_api_key, publisher_id, config, team_id, job_id, resumable_source_manager
+ ),
+ primary_keys=config.primary_keys,
+ partition_count=1,
+ partition_size=1,
+ )
+
resume = resumable_source_manager.load_state() if resumable_source_manager.can_resume() else None
params: dict[str, Any] = {}
paginator: BasePaginator
@@ -193,20 +294,13 @@ def partnerize_source(
initial_paginator_state = {"next_url": resume.next_url}
rest_config: RESTAPIConfig = {
- "client": {
- "base_url": PARTNERIZE_BASE_URL,
- # Auth (Basic) is supplied via the framework auth config so its secret is redacted from
- # raised errors; only the non-secret Accept header is set here.
- "headers": {"Accept": "application/json"},
- "auth": {"type": "http_basic", "username": application_key, "password": user_api_key},
- "paginator": paginator,
- },
+ "client": _client_config(application_key, user_api_key, paginator),
"resource_defaults": {},
"resources": [
{
"name": endpoint,
# Strip Partnerize's single-key item wrapper (e.g. {"campaign": {...}}) per row.
- "data_map": _make_unwrap(config.item_key),
+ "data_map": _make_row_map(config),
"endpoint": {
"path": config.path.format(publisher_id=publisher_id),
"params": params,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/settings.py
index 148a99f5012d..0afd2fc6a11b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/settings.py
@@ -1,10 +1,13 @@
from dataclasses import dataclass, field
from typing import Literal, Optional
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ DependentEndpointConfig,
+)
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
-@dataclass
+@dataclass(frozen=True)
class PartnerizeEndpointConfig:
name: str
# Path relative to the API base. `{publisher_id}` is substituted with the configured partner ID.
@@ -26,6 +29,16 @@ class PartnerizeEndpointConfig:
# endpoints filter on the conversion time by default; passing date_type=last_updated makes
# the start_date/end_date window apply to last_modified instead.
incremental_field_params: dict[str, dict[str, str]] = field(default_factory=dict)
+ # Nested list on each unwrapped item to emit as its own rows, one per element. Each row also
+ # carries `explode_parent_fields` copied from the item it was nested under.
+ explode_key: Optional[str] = None
+ explode_parent_fields: list[str] = field(default_factory=list)
+ # Set for per-campaign endpoints, which fan out over the parent endpoint's rows.
+ fanout: Optional[DependentEndpointConfig] = None
+ # Read by the shared fan-out helper only. No Partnerize endpoint takes a page-size param, so
+ # the helper is called with page_size_param=None and never sends it.
+ default_incremental_field: Optional[str] = None
+ page_size: int = 300
def _datetime_field(name: str) -> IncrementalField:
@@ -37,8 +50,8 @@ def _datetime_field(name: str) -> IncrementalField:
}
-# Partnerize Partner API endpoints (https://api-docs.partnerize.com/partner/). The conversions and
-# clicks reports accept a server-side start_date/end_date window, so they support incremental sync;
+# Partnerize Partner API endpoints (https://api-docs.partnerize.com/partner/). The conversions,
+# conversion items, and clicks reports accept a server-side start_date/end_date window, so they support incremental sync;
# campaigns and the reference catalogs expose no timestamp filter and are full refresh only.
PARTNERIZE_ENDPOINTS: dict[str, PartnerizeEndpointConfig] = {
"campaigns": PartnerizeEndpointConfig(
@@ -62,6 +75,29 @@ PARTNERIZE_ENDPOINTS: dict[str, PartnerizeEndpointConfig] = {
# (pending -> approved/rejected) on old conversions are picked up.
incremental_field_params={"last_modified": {"date_type": "last_updated"}},
),
+ "conversion_items": PartnerizeEndpointConfig(
+ name="conversion_items",
+ # The JSON conversion report nests each conversion's line items, so this is the same data as
+ # the conversion_item.csv export, paged and windowed like the conversions table.
+ path="/reporting/report_publisher/publisher/{publisher_id}/conversion.json",
+ data_key="conversions",
+ item_key="conversion_data",
+ explode_key="conversion_items",
+ explode_parent_fields=[
+ "conversion_id",
+ "campaign_id",
+ "publisher_id",
+ "conversion_time",
+ "last_modified",
+ "currency",
+ ],
+ # The docs don't state that conversion_item_id is unique outside its conversion.
+ primary_keys=["conversion_id", "conversion_item_id"],
+ kind="report",
+ partition_key="conversion_time",
+ incremental_fields=[_datetime_field("conversion_time"), _datetime_field("last_modified")],
+ incremental_field_params={"last_modified": {"date_type": "last_updated"}},
+ ),
"clicks": PartnerizeEndpointConfig(
name="clicks",
path="/reporting/report_publisher/publisher/{publisher_id}/click.json",
@@ -74,6 +110,36 @@ PARTNERIZE_ENDPOINTS: dict[str, PartnerizeEndpointConfig] = {
partition_key="set_time",
incremental_fields=[_datetime_field("set_time")],
),
+ "advertisers": PartnerizeEndpointConfig(
+ name="advertisers",
+ # Brands with campaigns the partner can join, each with its campaigns and the partner's
+ # status on them.
+ path="/v2/publishers/{publisher_id}/discovery/advertisers",
+ data_key="advertisers",
+ item_key=None,
+ primary_keys=["id"],
+ ),
+ "commissions": PartnerizeEndpointConfig(
+ name="commissions",
+ # Every active commission (default, campaign, voucher, promotional, and tier) for the partner
+ # on one campaign. The per-type /default, /campaign, /voucher, /promotion, and /tier routes
+ # return subsets of these rows.
+ path="/v2/campaigns/{campaign_id}/publishers/{publisher_id}/commissions/active",
+ data_key="active_commissions",
+ item_key=None,
+ # Commission ids are per campaign, and standard and tier commissions are separate objects.
+ primary_keys=["campaign_id", "type", "id"],
+ fanout=DependentEndpointConfig(
+ parent_name="campaigns",
+ resolve_param="campaign_id",
+ resolve_field="campaign_id",
+ include_from_parent=["campaign_id"],
+ parent_field_renames={"campaign_id": "campaign_id"},
+ # Partnerize answers 404 for an entity it can't find, so a campaign the partner leaves
+ # between the two requests drops its rows instead of failing the sync.
+ child_response_actions=[{"status_code": 404, "action": "ignore"}],
+ ),
+ ),
"countries": PartnerizeEndpointConfig(
name="countries",
path="/reference/country",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/source.py
index 91c3ff5f9780..e6fd06cc7180 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/source.py
@@ -118,9 +118,9 @@ You can find your **user application key** and **user API key** under **Account
force_refresh: bool = False,
api_version: str | None = None,
) -> list[SourceSchema]:
- # Conversions and clicks reports accept a server-side start_date/end_date window, so they
- # sync incrementally; campaigns and the reference catalogs expose no timestamp filter and
- # are full refresh only.
+ # The conversions, conversion items, and clicks reports accept a server-side
+ # start_date/end_date window, so they sync incrementally; every other endpoint exposes no
+ # timestamp filter and is full refresh only.
return build_endpoint_schemas(ENDPOINTS, INCREMENTAL_FIELDS, names)
def validate_credentials(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/tests/test_partnerize.py b/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/tests/test_partnerize.py
index 385e76bd84be..78776fe73e42 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/tests/test_partnerize.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/partnerize/tests/test_partnerize.py
@@ -105,6 +105,52 @@ class TestReportRows:
# The default window filters on the conversion time, no date_type override needed.
assert result.params("date_type") == [None]
+ @parameterized.expand(
+ [
+ ("conversion_time", "conversion_time", None),
+ ("last_modified", "last_modified", "last_updated"),
+ ]
+ )
+ def test_conversion_items_explode_one_row_per_item(
+ self, _name: str, incremental_field: str, expected_date_type: str | None
+ ) -> None:
+ conversion = {
+ "conversion_id": "c1",
+ "campaign_id": "10l1",
+ "conversion_time": "2024-05-02 10:00:00",
+ "last_modified": "2024-05-03 10:00:00",
+ "currency": "EUR",
+ "conversion_items": [
+ {"conversion_item_id": "i1", "item_value": 10, "conversion_id": "nested"},
+ {"conversion_item_id": "i2", "item_value": 20},
+ ],
+ }
+ result = _driver().run(
+ "conversion_items",
+ [
+ ScriptedResponse(
+ json={
+ "conversions": [
+ {"conversion_data": conversion},
+ {"conversion_data": {"conversion_id": "c2", "conversion_items": []}},
+ ],
+ "limit": 300,
+ }
+ )
+ ],
+ should_use_incremental_field=True,
+ db_incremental_field_last_value="2024-05-01 12:00:00",
+ incremental_field=incremental_field,
+ )
+
+ assert result.raised is None
+ assert result.params("date_type") == [expected_date_type]
+ assert [(row["conversion_id"], row["conversion_item_id"], row["item_value"]) for row in result.rows] == [
+ ("c1", "i1", 10),
+ ("c1", "i2", 20),
+ ]
+ assert all(row["conversion_time"] == "2024-05-02 10:00:00" for row in result.rows)
+
def test_missing_data_key_is_retried_then_reraises(self) -> None:
# A 200 body without the data key is an unexpected shape; the request is reissued and, if it
# never recovers, surfaces as a retryable error after the attempt cap.
@@ -222,11 +268,34 @@ class TestListRows:
assert result.urls == [resume_url]
+class TestFanOutRows:
+ def test_commissions_fan_out_over_campaigns(self) -> None:
+ result = _driver().run(
+ "commissions",
+ [
+ ScriptedResponse(
+ json={"campaigns": [{"campaign": {"campaign_id": "10l1"}}, {"campaign": {"campaign_id": "10l2"}}]}
+ ),
+ ScriptedResponse(json={"active_commissions": [{"id": "1", "type": "default"}]}),
+ ScriptedResponse(status=404, json={"error": "not found"}),
+ ],
+ )
+
+ assert result.raised is None
+ assert result.paths == [
+ "/user/publisher/111111l92/campaign/a",
+ "/v2/campaigns/10l1/publishers/111111l92/commissions/active",
+ "/v2/campaigns/10l2/publishers/111111l92/commissions/active",
+ ]
+ assert [(row["campaign_id"], row["type"], row["id"]) for row in result.rows] == [("10l1", "default", "1")]
+
+
class TestPartnerizeSourceResponse:
@parameterized.expand([(e,) for e in ENDPOINTS])
def test_source_response_shape(self, endpoint: str) -> None:
config = PARTNERIZE_ENDPOINTS[endpoint]
- result = _driver().run(endpoint, [ScriptedResponse(json={config.data_key: []})])
+ data_key = PARTNERIZE_ENDPOINTS[config.fanout.parent_name].data_key if config.fanout else config.data_key
+ result = _driver().run(endpoint, [ScriptedResponse(json={data_key: []})])
assert result.raised is None
response = result.response
assert response is not None
@@ -237,7 +306,7 @@ class TestPartnerizeSourceResponse:
assert response.sort_mode == "desc"
assert response.partition_mode == "datetime"
assert response.partition_keys == [config.partition_key]
- else:
+ elif config.fanout is None:
assert response.sort_mode == "asc"
assert response.partition_mode is None