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): support Smartreach API version v3 (#74174)

Tom Owersc938d6bd07c3
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/smartreach.py b/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/smartreach.py
index 878c20051711..bab6fe9aea8d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/smartreach.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/smartreach.py
@@ -7,3 +7,4 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common imp
@config.config
class SmartreachSourceConfig(config.Config):
api_key: str
+ team_id: str | None = None
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/smartreach.py b/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/smartreach.py
index ba631a18e4cb..ad91c631276b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/smartreach.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/smartreach.py
@@ -1,5 +1,6 @@
import dataclasses
from typing import Any, Optional
+from urllib.parse import urlencode
from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import SourceResponse
from products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_session
@@ -10,17 +11,50 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
JSONResponsePaginator,
)
-from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import ApiKeyAuthConfig
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (
+ ApiKeyAuthConfig,
+ Endpoint,
+)
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.smartreach.settings import SMARTREACH_ENDPOINTS
-SMARTREACH_BASE_URL = "https://api.smartreach.io/api/v1"
+SMARTREACH_API_V1 = "v1"
+SMARTREACH_API_V3 = "v3"
+
+# Each version is served under its own base path; auth (X-API-KEY) and links.next pagination are
+# shared. v3 diverges in two request-shaping ways we branch on below: the base path, and where the
+# row list sits in the response envelope (root vs `data.*`). v3 also requires a `team_id` query
+# param on the list endpoints (see smartreach_source / check_access).
+SMARTREACH_BASE_URLS: dict[str, str] = {
+ SMARTREACH_API_V1: "https://api.smartreach.io/api/v1",
+ SMARTREACH_API_V3: "https://api.smartreach.io/api/v3",
+}
+
+# Kept for the several call sites and tests that reference the v1 origin directly.
+SMARTREACH_BASE_URL = SMARTREACH_BASE_URLS[SMARTREACH_API_V1]
+
# Cheap endpoint used to confirm an API key is genuine. The user key is account-wide, so one probe
# validates access to every list endpoint.
DEFAULT_PROBE_ENDPOINT = "campaigns"
+def _base_url(api_version: str) -> str:
+ try:
+ return SMARTREACH_BASE_URLS[api_version]
+ except KeyError:
+ # Never fall through to a default: silently syncing under an unmapped version is the drift
+ # the version framework exists to prevent.
+ raise ValueError(f"Unsupported SmartReach API version {api_version!r}")
+
+
+def _data_selector(data_key: str, api_version: str) -> str:
+ # v3 returns the row list at the envelope root (e.g. `prospects`); v1 nests it under `data`.
+ if api_version == SMARTREACH_API_V3:
+ return data_key
+ return f"data.{data_key}"
+
+
@dataclasses.dataclass
class SmartreachResumeConfig:
# Full URL of the next page, taken verbatim from `links.next`. None means "start at the
@@ -45,13 +79,26 @@ def smartreach_source(
team_id: int,
job_id: str,
resumable_source_manager: ResumableSourceManager[SmartreachResumeConfig],
+ api_version: str,
+ smartreach_team_id: str | None = None,
db_incremental_field_last_value: Optional[Any] = None,
) -> SourceResponse:
config = SMARTREACH_ENDPOINTS[endpoint]
+ endpoint_config: Endpoint = {
+ "path": config.path,
+ # A missing key yields an empty page (matching the previous behavior) rather than failing
+ # loud, so data_selector_required is left off.
+ "data_selector": _data_selector(config.data_key, api_version),
+ }
+ # v3 requires the SmartReach team id on every list request; v1 has no such param. Set it only on
+ # the first request — the paginator then follows links.next verbatim, which already carries it.
+ if api_version == SMARTREACH_API_V3 and smartreach_team_id:
+ endpoint_config["params"] = {"team_id": smartreach_team_id}
+
rest_config: RESTAPIConfig = {
"client": {
- "base_url": SMARTREACH_BASE_URL,
+ "base_url": _base_url(api_version),
"headers": _headers(),
"auth": _api_key_auth(api_key),
# SmartReach echoes the next page as a full URL in `links.next`, so it can't be trusted
@@ -69,13 +116,7 @@ def smartreach_source(
"resources": [
{
"name": endpoint,
- "endpoint": {
- "path": config.path,
- # SmartReach nests the list under `data.<data_key>` (e.g. data.prospects). A
- # missing key yields an empty page (matching the previous behavior) rather than
- # failing loud, so data_selector_required is left off.
- "data_selector": f"data.{config.data_key}",
- },
+ "endpoint": endpoint_config,
}
],
}
@@ -113,16 +154,25 @@ def smartreach_source(
)
-def check_access(api_key: str, endpoint: str = DEFAULT_PROBE_ENDPOINT) -> tuple[int, Optional[str]]:
+def check_access(
+ api_key: str,
+ api_version: str,
+ smartreach_team_id: str | None = None,
+ endpoint: str = DEFAULT_PROBE_ENDPOINT,
+) -> tuple[int, Optional[str]]:
"""Probe a single list endpoint to validate the user key.
Returns ``(status, message)``: ``200`` reachable, ``401``/``403`` auth failure, ``0`` for a
connection problem, other HTTP status otherwise.
"""
config = SMARTREACH_ENDPOINTS[endpoint]
+ url = f"{_base_url(api_version)}{config.path}"
+ # v3 list endpoints reject a request without team_id, so the probe must carry it too.
+ if api_version == SMARTREACH_API_V3 and smartreach_team_id:
+ url = f"{url}?{urlencode({'team_id': smartreach_team_id})}"
ok, status = validate_via_probe(
lambda: make_tracked_session(redact_values=(api_key,), allow_redirects=False),
- f"{SMARTREACH_BASE_URL}{config.path}",
+ url,
headers={"X-API-KEY": api_key, **_headers()},
)
if status is None:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/source.py
index c4934cf921ac..a1511a463ebb 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/source.py
@@ -32,6 +32,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.smartreach
SMARTREACH_ENDPOINTS,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.smartreach.smartreach import (
+ SMARTREACH_API_V1,
+ SMARTREACH_API_V3,
SmartreachResumeConfig,
check_access,
smartreach_source,
@@ -41,9 +43,9 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType
@SourceRegistry.register
class SmartreachSource(ResumableSource[SmartreachSourceConfig, SmartreachResumeConfig]):
- supported_versions = ("v1",)
- default_version = "v1"
- api_docs_url = "https://smartreach.io/api_docs"
+ supported_versions = (SMARTREACH_API_V1, SMARTREACH_API_V3)
+ default_version = SMARTREACH_API_V3
+ api_docs_url = "https://help.smartreach.io/reference/using-the-smartreach-api"
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
@@ -61,6 +63,8 @@ class SmartreachSource(ResumableSource[SmartreachSourceConfig, SmartreachResumeC
caption="""Enter your SmartReach API key to pull your SmartReach data into the PostHog Data warehouse.
You can find your API key under **Settings → Integrations** in the [SmartReach app](https://app.smartreach.io/). The key is scoped to your user and grants read access to your prospects and campaigns.
+
+Your team ID is required by the current SmartReach API. Find it in your SmartReach team settings; it starts with `team_`.
""",
iconPath="/static/services/smartreach.png",
docsUrl="https://posthog.com/docs/cdp/sources/smartreach",
@@ -75,6 +79,16 @@ You can find your API key under **Settings → Integrations** in the [SmartReach
placeholder="",
secret=True,
),
+ # Optional at the form level so pre-existing v1 sources (stored without it) still
+ # load; validate_credentials requires it when the resolved version is v3.
+ SourceFieldInputConfig(
+ name="team_id",
+ label="Team ID",
+ type=SourceFieldInputConfigType.TEXT,
+ required=False,
+ placeholder="team_...",
+ secret=False,
+ ),
],
),
)
@@ -104,8 +118,9 @@ You can find your API key under **Settings → Integrations** in the [SmartReach
force_refresh: bool = False,
api_version: str | None = None,
) -> list[SourceSchema]:
- # Every endpoint is full refresh only — we deliberately do not use SmartReach's
- # newer_than/older_than filters, so there is no incremental cursor to advance
+ # The table set (prospects, campaigns) is identical across v1 and v3, so discovery does not
+ # branch on api_version. Every endpoint is full refresh only — we deliberately do not use
+ # SmartReach's newer_than/older_than filters, so there is no incremental cursor to advance
# (INCREMENTAL_FIELDS is empty, so build_endpoint_schemas marks all endpoints full-refresh).
return build_endpoint_schemas(ENDPOINTS, INCREMENTAL_FIELDS, names)
@@ -116,9 +131,12 @@ You can find your API key under **Settings → Integrations** in the [SmartReach
schema_name: Optional[str] = None,
api_version: str | None = None,
) -> tuple[bool, str | None]:
+ resolved_version = self.resolve_api_version(api_version)
+ if resolved_version == SMARTREACH_API_V3 and not config.team_id:
+ return False, "Enter your SmartReach team ID. The current SmartReach API needs it to return your data."
# The user key is account-wide, so a single probe validates access to every schema; there is
# no per-endpoint scope to check.
- status, message = check_access(config.api_key)
+ status, message = check_access(config.api_key, resolved_version, config.team_id)
if status == 200:
return True, None
if status in (401, 403):
@@ -143,5 +161,7 @@ You can find your API key under **Settings → Integrations** in the [SmartReach
team_id=inputs.team_id,
job_id=inputs.job_id,
resumable_source_manager=resumable_source_manager,
+ api_version=self.resolve_api_version(inputs.api_version),
+ smartreach_team_id=config.team_id,
db_incremental_field_last_value=None, # every SmartReach endpoint is full refresh
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/tests/test_smartreach.py b/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/tests/test_smartreach.py
index 73bff665d391..266eae424b30 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/tests/test_smartreach.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/tests/test_smartreach.py
@@ -13,7 +13,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.smartreach
SMARTREACH_ENDPOINTS,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.smartreach.smartreach import (
+ SMARTREACH_API_V1,
+ SMARTREACH_API_V3,
SMARTREACH_BASE_URL,
+ SMARTREACH_BASE_URLS,
SmartreachResumeConfig,
check_access,
smartreach_source,
@@ -28,6 +31,7 @@ SMARTREACH_SESSION_PATCH = (
def _response(rows: list[dict[str, Any]] | None, data_key: str, next_url: str | None, status: int = 200) -> Response:
+ # v1 envelope: the row list is nested under `data.<data_key>`.
body: dict[str, Any] = {"data": {data_key: rows if rows is not None else []}, "links": {"next": next_url}}
resp = Response()
resp.status_code = status
@@ -36,6 +40,16 @@ def _response(rows: list[dict[str, Any]] | None, data_key: str, next_url: str |
return resp
+def _response_v3(rows: list[dict[str, Any]] | None, data_key: str, next_url: str | None, status: int = 200) -> Response:
+ # v3 envelope: the row list sits at the response root (e.g. `prospects`), not under `data`.
+ body: dict[str, Any] = {data_key: rows if rows is not None else [], "links": {"next": next_url}}
+ resp = Response()
+ resp.status_code = status
+ resp._content = json.dumps(body).encode()
+ resp.url = f"{SMARTREACH_BASE_URLS[SMARTREACH_API_V3]}/prospects"
+ return resp
+
+
def _make_manager(resume_state: SmartreachResumeConfig | None = None) -> mock.MagicMock:
manager = mock.MagicMock()
manager.can_resume.return_value = resume_state is not None
@@ -43,18 +57,23 @@ def _make_manager(resume_state: SmartreachResumeConfig | None = None) -> mock.Ma
return manager
-def _wire(session: mock.MagicMock, responses: list[Response]) -> list[str]:
+def _wire(
+ session: mock.MagicMock, responses: list[Response], params_out: list[dict[str, Any]] | None = None
+) -> list[str]:
"""Wire a mock session and return a list that captures each request's URL AT SEND TIME.
The paginator rewrites ``request.url`` in place across pages, so snapshot it as each request is
prepared. The prepared request must expose a real ``url`` string because the client's host-pinning
- guard (``allowed_hosts``) runs on ``prepared.url`` before every send.
+ guard (``allowed_hosts``) runs on ``prepared.url`` before every send. Pass ``params_out`` to also
+ capture each request's query params (the v3 ``team_id`` rides here, not in ``request.url``).
"""
session.headers = {}
url_snapshots: list[str] = []
def _prepare(request: Any) -> mock.MagicMock:
url_snapshots.append(request.url)
+ if params_out is not None:
+ params_out.append(dict(request.params or {}))
prepared = mock.MagicMock()
prepared.url = request.url
return prepared
@@ -68,13 +87,20 @@ def _rows(source_response: Any) -> list[dict[str, Any]]:
return [row for page in source_response.items() for row in page]
-def _source(manager: mock.MagicMock, endpoint: str = "prospects") -> Any:
+def _source(
+ manager: mock.MagicMock,
+ endpoint: str = "prospects",
+ api_version: str = SMARTREACH_API_V1,
+ smartreach_team_id: str | None = None,
+) -> Any:
return smartreach_source(
api_key="uk_test",
endpoint=endpoint,
team_id=1,
job_id="j",
resumable_source_manager=manager,
+ api_version=api_version,
+ smartreach_team_id=smartreach_team_id,
)
@@ -179,6 +205,35 @@ class TestPagination:
assert _rows(_source(_make_manager())) == []
+class TestVersionDispatch:
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_v3_uses_v3_base_root_envelope_and_team_id(self, MockSession: Any) -> None:
+ session = MockSession.return_value
+ params: list[dict[str, Any]] = []
+ urls = _wire(session, [_response_v3([{"id": "p_1"}], "prospects", next_url=None)], params_out=params)
+
+ rows = _rows(_source(_make_manager(), api_version=SMARTREACH_API_V3, smartreach_team_id="team_abc"))
+
+ # Rows come from the v3 root envelope; a leftover v1 `data.prospects` selector would yield none.
+ assert rows == [{"id": "p_1"}]
+ assert urls == [f"{SMARTREACH_BASE_URLS[SMARTREACH_API_V3]}/prospects"]
+ # v3 requires team_id on the first request; the paginator carries it forward via links.next.
+ assert params == [{"team_id": "team_abc"}]
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_v1_uses_v1_base_and_never_sends_team_id(self, MockSession: Any) -> None:
+ session = MockSession.return_value
+ params: list[dict[str, Any]] = []
+ urls = _wire(session, [_response([{"id": 1}], "prospects", next_url=None)], params_out=params)
+
+ # Even if a team_id is threaded through, v1 keeps its legacy base + `data.*` envelope untouched.
+ rows = _rows(_source(_make_manager(), api_version=SMARTREACH_API_V1, smartreach_team_id="team_abc"))
+
+ assert rows == [{"id": 1}]
+ assert urls == [f"{SMARTREACH_BASE_URL}/prospects"]
+ assert params == [{}]
+
+
class TestSSRFHostPinning:
@parameterized.expand(
[
@@ -246,22 +301,31 @@ class TestCheckAccess:
response = mock.MagicMock()
response.status_code = status
with self._patch_session(response):
- assert check_access("uk_test") == (expected_status, expected_message)
+ assert check_access("uk_test", SMARTREACH_API_V1) == (expected_status, expected_message)
def test_connection_error_maps_to_zero(self) -> None:
with self._patch_session(requests.ConnectionError("boom")):
- status, message = check_access("uk_test")
+ status, message = check_access("uk_test", SMARTREACH_API_V1)
assert status == 0
assert message == "Could not connect to SmartReach"
- def test_probes_campaigns_endpoint(self) -> None:
+ def test_v1_probes_campaigns_without_team_id(self) -> None:
response = mock.MagicMock()
response.status_code = 200
with self._patch_session(response) as patched:
- check_access("uk_test")
+ check_access("uk_test", SMARTREACH_API_V1)
session = patched.return_value
assert session.get.call_args.args[0] == f"{SMARTREACH_BASE_URL}/campaigns"
+ def test_v3_probes_campaigns_with_team_id_on_v3_base(self) -> None:
+ # v3 rejects a list request without team_id, so the probe URL must carry it against the v3 base.
+ response = mock.MagicMock()
+ response.status_code = 200
+ with self._patch_session(response) as patched:
+ check_access("uk_test", SMARTREACH_API_V3, smartreach_team_id="team_abc")
+ session = patched.return_value
+ assert session.get.call_args.args[0] == f"{SMARTREACH_BASE_URLS[SMARTREACH_API_V3]}/campaigns?team_id=team_abc"
+
class TestSmartreachSourceResponse:
@parameterized.expand([("prospects",), ("campaigns",)])
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/tests/test_smartreach_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/tests/test_smartreach_source.py
index 89e1183dd144..6fa79f7433d8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/tests/test_smartreach_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/smartreach/tests/test_smartreach_source.py
@@ -9,6 +9,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_
)
from products.warehouse_sources.backend.temporal.data_imports.sources.smartreach.settings import ENDPOINTS
from products.warehouse_sources.backend.temporal.data_imports.sources.smartreach.smartreach import (
+ SMARTREACH_API_V1,
+ SMARTREACH_API_V3,
SmartreachResumeConfig,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.smartreach.source import SmartreachSource
@@ -19,11 +21,16 @@ class TestSmartreachSource:
def setup_method(self) -> None:
self.source = SmartreachSource()
self.team_id = 123
- self.config = SmartreachSourceConfig(api_key="uk_test")
+ self.config = SmartreachSourceConfig(api_key="uk_test", team_id="team_abc")
def test_source_type(self) -> None:
assert self.source.source_type == ExternalDataSourceType.SMARTREACH
+ def test_supported_versions_and_default(self) -> None:
+ # v3 is the new default for freshly created sources; v1 stays supported so pinned rows keep working.
+ assert self.source.supported_versions == (SMARTREACH_API_V1, SMARTREACH_API_V3)
+ assert self.source.default_version == SMARTREACH_API_V3
+
def test_get_source_config(self) -> None:
config = self.source.get_source_config
assert config.name.value == "Smartreach"
@@ -34,7 +41,16 @@ class TestSmartreachSource:
assert config.docsUrl == "https://posthog.com/docs/cdp/sources/smartreach"
field_names = [f.name for f in config.fields if isinstance(f, SourceFieldInputConfig)]
- assert field_names == ["api_key"]
+ assert field_names == ["api_key", "team_id"]
+
+ def test_team_id_field_is_optional_non_secret(self) -> None:
+ # Optional at the form level so pre-existing v1 sources (stored without it) still load;
+ # validate_credentials enforces it for v3.
+ config = self.source.get_source_config
+ field = next(f for f in config.fields if isinstance(f, SourceFieldInputConfig) and f.name == "team_id")
+ assert field.type == SourceFieldInputConfigType.TEXT
+ assert field.required is False
+ assert field.secret is False
def test_api_key_field_is_secret_password(self) -> None:
config = self.source.get_source_config
@@ -44,8 +60,8 @@ class TestSmartreachSource:
assert field.required is True
def test_no_connection_host_fields(self) -> None:
- # The only field is the secret `api_key` itself; the base URL is hardcoded and the account is
- # implicit in the key. There is no non-secret field that retargets where the key is sent.
+ # The base URL is hardcoded per version and the account is implicit in the key; neither
+ # `api_key` nor `team_id` retargets the host where the key is sent.
assert self.source.connection_host_fields == []
def test_lists_tables_without_credentials(self) -> None:
@@ -126,20 +142,51 @@ class TestSmartreachSource:
@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.smartreach.source.check_access")
def test_validate_credentials_probes_the_user_key(self, mock_check: mock.MagicMock) -> None:
- # The user key is account-wide, so validation probes the key, not a per-schema scope.
+ # The user key is account-wide, so validation probes the key, not a per-schema scope. The
+ # resolved version (v3 by default) and the SmartReach team id ride along to the probe.
mock_check.return_value = (200, None)
self.source.validate_credentials(self.config, self.team_id, schema_name="campaigns")
- mock_check.assert_called_once_with("uk_test")
+ mock_check.assert_called_once_with("uk_test", SMARTREACH_API_V3, "team_abc")
+
+ @mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.smartreach.source.check_access")
+ def test_validate_credentials_v3_requires_team_id(self, mock_check: mock.MagicMock) -> None:
+ # v3 list endpoints reject requests without team_id, so fail fast (before probing) when it's
+ # missing on a v3-resolved source rather than letting every table 400 mid-sync.
+ config = SmartreachSourceConfig(api_key="uk_test")
+ is_valid, message = self.source.validate_credentials(config, self.team_id, api_version=SMARTREACH_API_V3)
+ assert is_valid is False
+ assert message == "Enter your SmartReach team ID. The current SmartReach API needs it to return your data."
+ mock_check.assert_not_called()
+
+ @mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.smartreach.source.check_access")
+ def test_validate_credentials_v1_does_not_require_team_id(self, mock_check: mock.MagicMock) -> None:
+ # A source pinned to v1 (no team_id in its stored config) still validates — v1 never sends one.
+ mock_check.return_value = (200, None)
+ config = SmartreachSourceConfig(api_key="uk_test")
+ is_valid, _ = self.source.validate_credentials(config, self.team_id, api_version=SMARTREACH_API_V1)
+ assert is_valid is True
+ mock_check.assert_called_once_with("uk_test", SMARTREACH_API_V1, None)
def test_get_resumable_source_manager_binds_resume_config(self) -> None:
manager = self.source.get_resumable_source_manager(mock.MagicMock())
assert isinstance(manager, ResumableSourceManager)
assert manager._data_class is SmartreachResumeConfig
+ @pytest.mark.parametrize(
+ "pinned_version, expected_version",
+ [
+ (None, SMARTREACH_API_V3), # unpinned resolves to the new default
+ (SMARTREACH_API_V1, SMARTREACH_API_V1), # a legacy pin keeps syncing under v1
+ (SMARTREACH_API_V3, SMARTREACH_API_V3),
+ ],
+ )
@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.smartreach.source.smartreach_source")
- def test_source_for_pipeline_plumbs_arguments(self, mock_smartreach_source: mock.MagicMock) -> None:
+ def test_source_for_pipeline_plumbs_arguments(
+ self, mock_smartreach_source: mock.MagicMock, pinned_version: str | None, expected_version: str
+ ) -> None:
inputs = mock.MagicMock()
inputs.schema_name = "prospects"
+ inputs.api_version = pinned_version
manager = mock.MagicMock()
self.source.source_for_pipeline(self.config, manager, inputs)
@@ -149,6 +196,9 @@ class TestSmartreachSource:
assert kwargs["api_key"] == "uk_test"
assert kwargs["endpoint"] == "prospects"
assert kwargs["resumable_source_manager"] is manager
+ # The resolved pin and the SmartReach team id reach the request layer.
+ assert kwargs["api_version"] == expected_version
+ assert kwargs["smartreach_team_id"] == "team_abc"
def test_source_for_pipeline_rejects_unknown_schema(self) -> None:
inputs = mock.MagicMock()