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(data-warehouse): implement optimizely import source (#62913)

Tom Owersd9f71198e285
diff --git a/posthog/temporal/data_imports/sources/SOURCES.md b/posthog/temporal/data_imports/sources/SOURCES.md
index 981575f78959..60403ee5190c 100644
--- a/posthog/temporal/data_imports/sources/SOURCES.md
+++ b/posthog/temporal/data_imports/sources/SOURCES.md
@@ -115,6 +115,7 @@ the row lists both.
| notion | HTTP | requests | ✅ |
| omnisend | HTTP | requests | ✅ |
| paddle | HTTP | requests | ✅ |
+| optimizely | HTTP | requests | ✅ |
| pagerduty | HTTP | requests | ✅ |
| pandadoc | HTTP | requests | ✅ |
| pendo | HTTP | requests | ✅ |
@@ -268,7 +269,6 @@ doesn't conflict with concurrent PRs.
- netsuite
- onedrive
- opsgenie
-- optimizely
- oracle
- oracle_ebs
- oracle_fusion
diff --git a/posthog/temporal/data_imports/sources/generated_configs.py b/posthog/temporal/data_imports/sources/generated_configs.py
index 9ab11e8218cd..71cbccc72801 100644
--- a/posthog/temporal/data_imports/sources/generated_configs.py
+++ b/posthog/temporal/data_imports/sources/generated_configs.py
@@ -902,7 +902,7 @@ class OpsgenieSourceConfig(config.Config):
@config.config
class OptimizelySourceConfig(config.Config):
- pass
+ api_token: str
@config.config
diff --git a/posthog/temporal/data_imports/sources/optimizely/optimizely.py b/posthog/temporal/data_imports/sources/optimizely/optimizely.py
new file mode 100644
index 000000000000..be5bf6b93675
--- /dev/null
+++ b/posthog/temporal/data_imports/sources/optimizely/optimizely.py
@@ -0,0 +1,148 @@
+from collections.abc import Iterator
+from typing import Any
+from urllib.parse import urlencode, urlparse
+
+import requests
+from structlog.types import FilteringBoundLogger
+from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_exponential_jitter
+
+from posthog.temporal.data_imports.pipelines.pipeline.typings import SourceResponse
+from posthog.temporal.data_imports.sources.common.http import make_tracked_session
+from posthog.temporal.data_imports.sources.optimizely.settings import OPTIMIZELY_ENDPOINTS
+
+OPTIMIZELY_API_HOST = "api.optimizely.com"
+OPTIMIZELY_BASE_URL = f"https://{OPTIMIZELY_API_HOST}/v2"
+# Optimizely list pages cap at 100 items.
+PAGE_SIZE = 100
+# Safety bound per page chain — experiment config entities never come close.
+MAX_PAGES = 500
+REQUEST_TIMEOUT_SECONDS = 60
+MAX_RETRY_ATTEMPTS = 5
+
+
+class OptimizelyRetryableError(Exception):
+ pass
+
+
+def _is_optimizely_url(url: str) -> bool:
+ """Return True only for https URLs on the Optimizely API host."""
+ parsed = urlparse(url)
+ return parsed.scheme == "https" and parsed.netloc == OPTIMIZELY_API_HOST
+
+
+def _get_session(api_token: str) -> requests.Session:
+ return make_tracked_session(headers={"Authorization": f"Bearer {api_token}"}, redact_values=(api_token,))
+
+
+def validate_credentials(api_token: str) -> bool:
+ """Confirm the personal access token is valid with a cheap projects probe."""
+ try:
+ response = _get_session(api_token).get(
+ f"{OPTIMIZELY_BASE_URL}/projects?{urlencode({'per_page': 1})}",
+ timeout=10,
+ )
+ return response.status_code != 401
+ except Exception:
+ return False
+
+
+def _iterate_pages(
+ session: requests.Session,
+ path: str,
+ params: dict[str, Any],
+ logger: FilteringBoundLogger,
+) -> Iterator[list[dict[str, Any]]]:
+ """Page through one list endpoint via RFC 5988 Link headers."""
+
+ @retry(
+ retry=retry_if_exception_type((OptimizelyRetryableError, requests.ReadTimeout, requests.ConnectionError)),
+ stop=stop_after_attempt(MAX_RETRY_ATTEMPTS),
+ wait=wait_exponential_jitter(initial=1, max=60),
+ reraise=True,
+ )
+ def fetch(page_url: str) -> requests.Response:
+ response = session.get(page_url, timeout=REQUEST_TIMEOUT_SECONDS)
+
+ if response.status_code == 429 or response.status_code >= 500:
+ raise OptimizelyRetryableError(
+ f"Optimizely API error (retryable): status={response.status_code}, url={page_url}"
+ )
+
+ if not response.ok:
+ logger.error(f"Optimizely API error: status={response.status_code}, body={response.text}, url={page_url}")
+ response.raise_for_status()
+
+ return response
+
+ url = f"{OPTIMIZELY_BASE_URL}{path}?{urlencode({**params, 'per_page': PAGE_SIZE})}"
+ for _page_index in range(MAX_PAGES):
+ response = fetch(url)
+ data = response.json()
+ items = data if isinstance(data, list) else []
+
+ if items:
+ yield items
+
+ next_url = response.links.get("next", {}).get("url")
+ if not next_url:
+ return
+ # Only follow pagination URLs that stay on the Optimizely API host, so a
+ # tampered or compromised API response can't redirect our authenticated
+ # Bearer request to an internal address (SSRF) or external host (token theft).
+ if not _is_optimizely_url(next_url):
+ logger.error(f"Optimizely: unexpected next_url host, stopping pagination (url={next_url!r})")
+ return
+ url = next_url
+
+ logger.error(f"Optimizely: page cap ({MAX_PAGES}) reached for {path} with params {params}; output may be truncated")
+
+
+def get_rows(
+ api_token: str,
+ endpoint: str,
+ logger: FilteringBoundLogger,
+) -> Iterator[list[dict[str, Any]]]:
+ config = OPTIMIZELY_ENDPOINTS[endpoint]
+ session = _get_session(api_token)
+
+ if not config.project_scoped:
+ yield from _iterate_pages(session, config.path, {}, logger)
+ return
+
+ # Project-scoped endpoints fan out over every project. A project without
+ # access to the feature (e.g. campaigns on a non-Web project) can 400/403 —
+ # log and continue rather than failing the whole stream.
+ project_ids: list[int] = []
+ for page in _iterate_pages(session, "/projects", {}, logger):
+ project_ids.extend(item["id"] for item in page if item.get("id") is not None)
+
+ for project_id in project_ids:
+ try:
+ yield from _iterate_pages(session, config.path, {"project_id": project_id}, logger)
+ except requests.HTTPError as e:
+ status = e.response.status_code if e.response is not None else None
+ if status in (400, 403, 404):
+ logger.warning(f"Optimizely: skipping {endpoint} for project {project_id} (status={status})")
+ continue
+ raise
+
+
+def optimizely_source(
+ api_token: str,
+ endpoint: str,
+ logger: FilteringBoundLogger,
+) -> SourceResponse:
+ config = OPTIMIZELY_ENDPOINTS[endpoint]
+
+ return SourceResponse(
+ name=endpoint,
+ items=lambda: get_rows(
+ api_token=api_token,
+ endpoint=endpoint,
+ logger=logger,
+ ),
+ primary_keys=[config.primary_key],
+ partition_count=1,
+ partition_size=1,
+ sort_mode="asc",
+ )
diff --git a/posthog/temporal/data_imports/sources/optimizely/settings.py b/posthog/temporal/data_imports/sources/optimizely/settings.py
new file mode 100644
index 000000000000..7bae7b97dc01
--- /dev/null
+++ b/posthog/temporal/data_imports/sources/optimizely/settings.py
@@ -0,0 +1,39 @@
+from dataclasses import dataclass
+
+
+@dataclass
+class OptimizelyEndpointConfig:
+ path: str
+ # Most v2 list endpoints are project-scoped and need a project_id param,
+ # so the transport fans out over the projects list.
+ project_scoped: bool = True
+ primary_key: str = "id"
+
+
+# Optimizely's v2 list endpoints have no updated-since filters, and all the
+# entities are low-volume experiment configuration, so every stream is an
+# honest full refresh. Raw event-level data only exists in the separate S3
+# Enriched Events Export, which is out of scope for a REST connector.
+OPTIMIZELY_ENDPOINTS: dict[str, OptimizelyEndpointConfig] = {
+ "projects": OptimizelyEndpointConfig(
+ path="/projects",
+ project_scoped=False,
+ ),
+ "experiments": OptimizelyEndpointConfig(
+ path="/experiments",
+ ),
+ "audiences": OptimizelyEndpointConfig(
+ path="/audiences",
+ ),
+ "events": OptimizelyEndpointConfig(
+ path="/events",
+ ),
+ "pages": OptimizelyEndpointConfig(
+ path="/pages",
+ ),
+ "campaigns": OptimizelyEndpointConfig(
+ path="/campaigns",
+ ),
+}
+
+ENDPOINTS = tuple(OPTIMIZELY_ENDPOINTS.keys())
diff --git a/posthog/temporal/data_imports/sources/optimizely/source.py b/posthog/temporal/data_imports/sources/optimizely/source.py
index eaf83eabdcc5..d24fab423094 100644
--- a/posthog/temporal/data_imports/sources/optimizely/source.py
+++ b/posthog/temporal/data_imports/sources/optimizely/source.py
@@ -1,13 +1,23 @@
-from typing import cast
+from typing import Optional, cast
from posthog.schema import (
ExternalDataSourceType as SchemaExternalDataSourceType,
+ ReleaseStatus,
SourceConfig,
+ SourceFieldInputConfig,
+ SourceFieldInputConfigType,
)
+from posthog.temporal.data_imports.pipelines.pipeline.typings import SourceInputs, SourceResponse
from posthog.temporal.data_imports.sources.common.base import FieldType, SimpleSource
from posthog.temporal.data_imports.sources.common.registry import SourceRegistry
+from posthog.temporal.data_imports.sources.common.schema import SourceSchema
from posthog.temporal.data_imports.sources.generated_configs import OptimizelySourceConfig
+from posthog.temporal.data_imports.sources.optimizely.optimizely import (
+ optimizely_source,
+ validate_credentials as validate_optimizely_credentials,
+)
+from posthog.temporal.data_imports.sources.optimizely.settings import ENDPOINTS
from products.data_warehouse.backend.types import ExternalDataSourceType
@@ -18,12 +28,74 @@ class OptimizelySource(SimpleSource[OptimizelySourceConfig]):
def source_type(self) -> ExternalDataSourceType:
return ExternalDataSourceType.OPTIMIZELY
+ def get_non_retryable_errors(self) -> dict[str, str | None]:
+ return {
+ "401 Client Error: Unauthorized for url: https://api.optimizely.com": "Optimizely authentication failed. Please check your personal access token.",
+ }
+
@property
def get_source_config(self) -> SourceConfig:
return SourceConfig(
name=SchemaExternalDataSourceType.OPTIMIZELY,
label="Optimizely",
+ caption="""Enter your Optimizely personal access token to pull your experimentation data into the PostHog Data warehouse.
+
+An admin can generate a personal access token in Optimizely under Account Settings > API Access. Tokens are non-expiring. Project-scoped data (experiments, audiences, events, pages, campaigns) is synced across all projects the token can access.""",
iconPath="/static/services/optimizely.com.png",
- fields=cast(list[FieldType], []),
- unreleasedSource=True,
+ docsUrl="https://posthog.com/docs/cdp/sources/optimizely",
+ releaseStatus=ReleaseStatus.ALPHA,
+ fields=cast(
+ list[FieldType],
+ [
+ SourceFieldInputConfig(
+ name="api_token",
+ label="Personal access token",
+ type=SourceFieldInputConfigType.PASSWORD,
+ required=True,
+ placeholder="",
+ secret=True,
+ ),
+ ],
+ ),
+ )
+
+ def get_schemas(
+ self,
+ config: OptimizelySourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
+ ) -> list[SourceSchema]:
+ # No v2 list endpoint has an updated-since filter; the entities are
+ # low-volume experiment config, so full refresh is the honest mode.
+ schemas = [
+ SourceSchema(
+ name=endpoint,
+ supports_incremental=False,
+ supports_append=False,
+ incremental_fields=[],
+ )
+ for endpoint in ENDPOINTS
+ ]
+
+ if names is not None:
+ names_set = set(names)
+ schemas = [s for s in schemas if s.name in names_set]
+
+ return schemas
+
+ def validate_credentials(
+ self, config: OptimizelySourceConfig, team_id: int, schema_name: Optional[str] = None
+ ) -> tuple[bool, str | None]:
+ if validate_optimizely_credentials(config.api_token):
+ return True, None
+
+ return False, "Invalid Optimizely personal access token"
+
+ def source_for_pipeline(self, config: OptimizelySourceConfig, inputs: SourceInputs) -> SourceResponse:
+ return optimizely_source(
+ api_token=config.api_token,
+ endpoint=inputs.schema_name,
+ logger=inputs.logger,
)
diff --git a/posthog/temporal/data_imports/sources/optimizely/tests/test_optimizely.py b/posthog/temporal/data_imports/sources/optimizely/tests/test_optimizely.py
new file mode 100644
index 000000000000..3b604babddd0
--- /dev/null
+++ b/posthog/temporal/data_imports/sources/optimizely/tests/test_optimizely.py
@@ -0,0 +1,156 @@
+from typing import Any
+from urllib.parse import parse_qs, urlparse
+
+import pytest
+from unittest import mock
+
+import requests
+
+from posthog.temporal.data_imports.sources.optimizely.optimizely import (
+ PAGE_SIZE,
+ get_rows,
+ optimizely_source,
+ validate_credentials,
+)
+from posthog.temporal.data_imports.sources.optimizely.settings import ENDPOINTS, OPTIMIZELY_ENDPOINTS
+
+
+def _response(items: list[dict[str, Any]], next_url: str | None = None) -> mock.MagicMock:
+ resp = mock.MagicMock()
+ resp.json.return_value = items
+ resp.status_code = 200
+ resp.ok = True
+ resp.links = {"next": {"url": next_url}} if next_url else {}
+ return resp
+
+
+def _http_error(status: int) -> requests.HTTPError:
+ response = mock.MagicMock()
+ response.status_code = status
+ return requests.HTTPError(f"{status} Client Error", response=response)
+
+
+class TestValidateCredentials:
+ @pytest.mark.parametrize(
+ "status_code, expected",
+ [
+ (200, True),
+ (403, True),
+ (401, False),
+ ],
+ )
+ @mock.patch("posthog.temporal.data_imports.sources.optimizely.optimizely.make_tracked_session")
+ def test_validate_credentials_status_mapping(self, mock_session, status_code, expected):
+ response = mock.MagicMock()
+ response.status_code = status_code
+ mock_session.return_value.get.return_value = response
+
+ assert validate_credentials("token") is expected
+
+ @mock.patch("posthog.temporal.data_imports.sources.optimizely.optimizely.make_tracked_session")
+ def test_validate_credentials_swallows_exceptions(self, mock_session):
+ mock_session.return_value.get.side_effect = Exception("boom")
+ assert validate_credentials("token") is False
+
+
+class TestGetRows:
+ @mock.patch("posthog.temporal.data_imports.sources.optimizely.optimizely.make_tracked_session")
+ def test_projects_paginates_via_link_header(self, mock_session):
+ next_url = "https://api.optimizely.com/v2/projects?page=2&per_page=100"
+ mock_session.return_value.get.side_effect = [
+ _response([{"id": 1}], next_url=next_url),
+ _response([{"id": 2}]),
+ ]
+
+ batches = list(get_rows("token", "projects", mock.MagicMock()))
+
+ assert [item["id"] for batch in batches for item in batch] == [1, 2]
+ assert mock_session.return_value.get.call_args_list[1].args[0] == next_url
+
+ @mock.patch("posthog.temporal.data_imports.sources.optimizely.optimizely.make_tracked_session")
+ def test_project_scoped_endpoint_fans_out_over_projects(self, mock_session):
+ mock_session.return_value.get.side_effect = [
+ _response([{"id": 11}, {"id": 22}]), # projects list
+ _response([{"id": "exp-1", "project_id": 11}]),
+ _response([{"id": "exp-2", "project_id": 22}]),
+ ]
+
+ batches = list(get_rows("token", "experiments", mock.MagicMock()))
+
+ assert [item["id"] for batch in batches for item in batch] == ["exp-1", "exp-2"]
+ urls = [call.args[0] for call in mock_session.return_value.get.call_args_list]
+ assert urlparse(urls[0]).path == "/v2/projects"
+ assert parse_qs(urlparse(urls[1]).query)["project_id"] == ["11"]
+ assert parse_qs(urlparse(urls[2]).query)["project_id"] == ["22"]
+ assert all(parse_qs(urlparse(u).query)["per_page"] == [str(PAGE_SIZE)] for u in urls)
+
+ @mock.patch("posthog.temporal.data_imports.sources.optimizely.optimizely._iterate_pages")
+ @mock.patch("posthog.temporal.data_imports.sources.optimizely.optimizely.make_tracked_session")
+ def test_fan_out_skips_projects_without_feature_access(self, mock_session, mock_iterate):
+ def iterate(session, path, params, logger):
+ if path == "/projects":
+ yield [{"id": 11}, {"id": 22}]
+ return
+ if params.get("project_id") == 11:
+ raise _http_error(403)
+ yield [{"id": "camp-1"}]
+
+ mock_iterate.side_effect = iterate
+
+ logger = mock.MagicMock()
+ batches = list(get_rows("token", "campaigns", logger))
+
+ assert batches == [[{"id": "camp-1"}]]
+ logger.warning.assert_called_once()
+
+ @mock.patch("posthog.temporal.data_imports.sources.optimizely.optimizely._iterate_pages")
+ @mock.patch("posthog.temporal.data_imports.sources.optimizely.optimizely.make_tracked_session")
+ def test_fan_out_raises_on_unexpected_errors(self, mock_session, mock_iterate):
+ # 401 and other non-retried 4xx (not in the skip set 400/403/404) are the
+ # cases that actually reach the `raise` branch via requests.HTTPError.
+ # 5xx would arrive as OptimizelyRetryableError (after retries), bypassing
+ # the HTTPError handler entirely.
+ def iterate(session, path, params, logger):
+ if path == "/projects":
+ yield [{"id": 11}]
+ return
+ raise _http_error(401)
+
+ mock_iterate.side_effect = iterate
+
+ with pytest.raises(requests.HTTPError):
+ list(get_rows("token", "experiments", mock.MagicMock()))
+
+ @mock.patch("posthog.temporal.data_imports.sources.optimizely.optimizely.make_tracked_session")
+ def test_pagination_stops_on_foreign_next_url(self, mock_session):
+ # A next_url on an unexpected host must not be followed — it could
+ # redirect our authenticated Bearer request and leak the token.
+ evil_url = "https://evil.example.com/v2/projects?page=2&per_page=100"
+ mock_session.return_value.get.side_effect = [
+ _response([{"id": 1}], next_url=evil_url),
+ _response([{"id": 2}]),
+ ]
+
+ batches = list(get_rows("token", "projects", mock.MagicMock()))
+
+ assert [item["id"] for batch in batches for item in batch] == [1]
+ assert mock_session.return_value.get.call_count == 1
+
+ @mock.patch("posthog.temporal.data_imports.sources.optimizely.optimizely.make_tracked_session")
+ def test_empty_response_yields_nothing(self, mock_session):
+ mock_session.return_value.get.return_value = _response([])
+
+ assert list(get_rows("token", "projects", mock.MagicMock())) == []
+
+
+class TestOptimizelySourceResponse:
+ @pytest.mark.parametrize("endpoint", list(ENDPOINTS))
+ def test_response_metadata_per_endpoint(self, endpoint):
+ config = OPTIMIZELY_ENDPOINTS[endpoint]
+ response = optimizely_source("token", endpoint, mock.MagicMock())
+
+ assert response.name == endpoint
+ assert response.primary_keys == [config.primary_key]
+ assert response.sort_mode == "asc"
+ assert response.partition_mode is None
+ assert response.partition_keys is None
diff --git a/posthog/temporal/data_imports/sources/optimizely/tests/test_optimizely_source.py b/posthog/temporal/data_imports/sources/optimizely/tests/test_optimizely_source.py
new file mode 100644
index 000000000000..06d87e491af4
--- /dev/null
+++ b/posthog/temporal/data_imports/sources/optimizely/tests/test_optimizely_source.py
@@ -0,0 +1,102 @@
+import pytest
+from unittest import mock
+
+from posthog.schema import ReleaseStatus, SourceFieldInputConfig, SourceFieldInputConfigType
+
+from posthog.temporal.data_imports.sources.generated_configs import OptimizelySourceConfig
+from posthog.temporal.data_imports.sources.optimizely.settings import ENDPOINTS
+from posthog.temporal.data_imports.sources.optimizely.source import OptimizelySource
+
+from products.data_warehouse.backend.types import ExternalDataSourceType
+
+
+class TestOptimizelySource:
+ def setup_method(self):
+ self.source = OptimizelySource()
+ self.team_id = 123
+ self.config = OptimizelySourceConfig(api_token="api-token")
+
+ def test_source_type(self):
+ assert self.source.source_type == ExternalDataSourceType.OPTIMIZELY
+
+ def test_get_source_config(self):
+ config = self.source.get_source_config
+
+ assert config.name.value == "Optimizely"
+ assert config.label == "Optimizely"
+ assert config.releaseStatus == ReleaseStatus.ALPHA
+ assert config.unreleasedSource is None
+ assert config.iconPath == "/static/services/optimizely.com.png"
+
+ field_names = [f.name for f in config.fields if isinstance(f, SourceFieldInputConfig)]
+ assert field_names == ["api_token"]
+
+ def test_api_token_field_is_secret_password(self):
+ config = self.source.get_source_config
+ token_field = next(f for f in config.fields if isinstance(f, SourceFieldInputConfig) and f.name == "api_token")
+ assert token_field.type == SourceFieldInputConfigType.PASSWORD
+ assert token_field.secret is True
+ assert token_field.required is True
+
+ def test_non_retryable_errors_match_auth_failures(self):
+ non_retryable_errors = self.source.get_non_retryable_errors()
+ observed = "401 Client Error: Unauthorized for url: https://api.optimizely.com/v2/projects?per_page=100"
+ assert any(key in observed for key in non_retryable_errors)
+
+ @pytest.mark.parametrize(
+ "other_error",
+ [
+ "401 Client Error: Unauthorized for url: https://api.stripe.com/v1/customers",
+ "500 Server Error for url: https://api.optimizely.com/v2/projects",
+ # Per-project 403s are skipped in the fan-out, not fatal.
+ "403 Client Error: Forbidden for url: https://api.optimizely.com/v2/campaigns",
+ ],
+ )
+ def test_non_retryable_errors_does_not_match_unrelated(self, other_error):
+ non_retryable_errors = self.source.get_non_retryable_errors()
+ assert not any(key in other_error for key in non_retryable_errors)
+
+ def test_get_schemas_are_full_refresh_only(self):
+ schemas = self.source.get_schemas(self.config, self.team_id)
+
+ assert {schema.name for schema in schemas} == set(ENDPOINTS)
+ assert all(not schema.supports_incremental for schema in schemas)
+ assert all(not schema.supports_append for schema in schemas)
+ assert all(schema.incremental_fields == [] for schema in schemas)
+
+ def test_get_schemas_filtered_by_names(self):
+ schemas = self.source.get_schemas(self.config, self.team_id, names=["experiments"])
+ assert len(schemas) == 1
+ assert schemas[0].name == "experiments"
+
+ def test_get_schemas_filtered_unknown_name_returns_empty(self):
+ assert self.source.get_schemas(self.config, self.team_id, names=["nope"]) == []
+
+ @pytest.mark.parametrize(
+ "mock_return, expected_valid, expected_message",
+ [
+ (True, True, None),
+ (False, False, "Invalid Optimizely personal access token"),
+ ],
+ )
+ @mock.patch("posthog.temporal.data_imports.sources.optimizely.source.validate_optimizely_credentials")
+ def test_validate_credentials(self, mock_validate, mock_return, expected_valid, expected_message):
+ mock_validate.return_value = mock_return
+
+ is_valid, error_message = self.source.validate_credentials(self.config, self.team_id)
+
+ assert is_valid is expected_valid
+ assert error_message == expected_message
+ mock_validate.assert_called_once_with(self.config.api_token)
+
+ @mock.patch("posthog.temporal.data_imports.sources.optimizely.source.optimizely_source")
+ def test_source_for_pipeline_plumbs_arguments(self, mock_optimizely_source):
+ inputs = mock.MagicMock()
+ inputs.schema_name = "experiments"
+
+ self.source.source_for_pipeline(self.config, inputs)
+
+ mock_optimizely_source.assert_called_once()
+ kwargs = mock_optimizely_source.call_args.kwargs
+ assert kwargs["api_token"] == "api-token"
+ assert kwargs["endpoint"] == "experiments"