: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(batch-exports): run destination tests through the facade (#113810)
Ross2211f752303a
diff --git a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt b/posthog/test/repo_invariants/dataclass_frozen_baseline.txtindex 8e3c69e029a9..fb8773599f99 100644--- a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt+++ b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt@@ -82,7 +82,6 @@1 products/apm/backend/logic/anomaly_detection/types.py1 products/apm/backend/logic/anomaly_detection/validation/simulation.py1 products/approvals/backend/decorators.py-1 products/batch_exports/backend/presentation/views/destination_tests/base.py1 products/batch_exports/backend/debug/debugger.py1 products/batch_exports/backend/temporal/destinations/azure_blob_batch_export.py1 products/batch_exports/backend/temporal/destinations/bigquery_batch_export.pydiff --git a/products/batch_exports/backend/destination_tests/__init__.py b/products/batch_exports/backend/destination_tests/__init__.pynew file mode 100644index 000000000000..ad8d97aa47bd--- /dev/null+++ b/products/batch_exports/backend/destination_tests/__init__.py@@ -0,0 +1,43 @@+from products.batch_exports.backend.destination_tests.base import DestinationTest+from products.batch_exports.backend.facade.contracts import UnsupportedDestinationTestError+++def get_destination_test(+ destination: str,+) -> DestinationTest:+ """Resolve a destination to its corresponding `DestinationTest` implementation.++ Per-branch deferred imports: each destination test module pulls a heavy vendor SDK+ (databricks, google-cloud-bigquery, snowflake, etc.). Importing them lazily keeps the+ SDKs off the API import path — only the requested destination's SDK loads.+ """+ if destination == "S3Compatible":+ from products.batch_exports.backend.destination_tests.s3 import S3CompatibleDestinationTest # noqa: PLC0415++ return S3CompatibleDestinationTest()+ elif destination == "AwsS3":+ from products.batch_exports.backend.destination_tests.s3 import AwsS3DestinationTest # noqa: PLC0415++ return AwsS3DestinationTest()+ elif destination == "BigQuery":+ from products.batch_exports.backend.destination_tests.bigquery import BigQueryDestinationTest # noqa: PLC0415++ return BigQueryDestinationTest()+ elif destination == "Snowflake":+ from products.batch_exports.backend.destination_tests.snowflake import SnowflakeDestinationTest # noqa: PLC0415++ return SnowflakeDestinationTest()+ elif destination == "Databricks":+ from products.batch_exports.backend.destination_tests.databricks import ( # noqa: PLC0415+ DatabricksDestinationTest,+ )++ return DatabricksDestinationTest()+ elif destination == "AzureBlob":+ from products.batch_exports.backend.destination_tests.azure_blob import ( # noqa: PLC0415+ AzureBlobDestinationTest,+ )++ return AzureBlobDestinationTest()+ else:+ raise UnsupportedDestinationTestError(f"No connection test for destination {destination!r}")diff --git a/products/batch_exports/backend/presentation/views/destination_tests/azure_blob.py b/products/batch_exports/backend/destination_tests/azure_blob.pysimilarity index 97%rename from products/batch_exports/backend/presentation/views/destination_tests/azure_blob.pyrename to products/batch_exports/backend/destination_tests/azure_blob.pyindex 2c8a5df11bda..af00c22b9994 100644--- a/products/batch_exports/backend/presentation/views/destination_tests/azure_blob.py+++ b/products/batch_exports/backend/destination_tests/azure_blob.py@@ -2,7 +2,7 @@ import collections.abcfrom posthog.models.integration.azure_blob import strip_leading_whitespace, validate_azure_blob_connection_string-from products.batch_exports.backend.presentation.views.destination_tests.base import (+from products.batch_exports.backend.destination_tests.base import (DestinationTest,DestinationTestStep,DestinationTestStepResult,diff --git a/products/batch_exports/backend/presentation/views/destination_tests/base.py b/products/batch_exports/backend/destination_tests/base.pysimilarity index 80%rename from products/batch_exports/backend/presentation/views/destination_tests/base.pyrename to products/batch_exports/backend/destination_tests/base.pyindex c8d28c1cae8f..c21e6f278906 100644--- a/products/batch_exports/backend/presentation/views/destination_tests/base.py+++ b/products/batch_exports/backend/destination_tests/base.py@@ -1,10 +1,11 @@import abcimport enum-import dataclassesimport collections.abcfrom asgiref.sync import async_to_sync+from posthog.dataclasses import frozen+class Status(enum.StrEnum):PASSED = "Passed"@@ -12,10 +13,7 @@ class Status(enum.StrEnum):SKIPPED = "Skipped"-DestinationTestStepResultDict = dict[str, str | None]--+@frozenclass DestinationTestStepResult:"""The result of a test step.@@ -28,16 +26,6 @@ class DestinationTestStepResult:status: Statusmessage: str | None = None- def as_dict(self) -> DestinationTestStepResultDict:- """Serialize this as a dictionary."""- return {- "status": str(self.status),- "message": self.message,- }---DestinationTestStepDict = dict[str, str | DestinationTestStepResultDict | None]-class DestinationTestStep:"""A single step in a destination test.@@ -89,18 +77,6 @@ class DestinationTestStep:)return result- def as_dict(self) -> DestinationTestStepDict:- """Serialize this as a dictionary."""- base: dict[str, str | DestinationTestStepResultDict | None] = {- "name": self.name,- "description": self.description,- }- if self.result:- base["result"] = self.result.as_dict()- else:- base["result"] = None- return base-class DestinationTest:"""Interface representing a test executed for a particular destination.@@ -147,7 +123,3 @@ class DestinationTest:test_step.result = step_resultreturn test_step-- def as_dict(self) -> dict[str, list[DestinationTestStepDict]]:- """Serialize this as a dictionary."""- return {"steps": [step.as_dict() for step in self.steps]}diff --git a/products/batch_exports/backend/presentation/views/destination_tests/bigquery.py b/products/batch_exports/backend/destination_tests/bigquery.pysimilarity index 99%rename from products/batch_exports/backend/presentation/views/destination_tests/bigquery.pyrename to products/batch_exports/backend/destination_tests/bigquery.pyindex c812e05fcdaf..ad14ab1eb978 100644--- a/products/batch_exports/backend/presentation/views/destination_tests/bigquery.py+++ b/products/batch_exports/backend/destination_tests/bigquery.py@@ -7,7 +7,7 @@ from google.cloud import bigquery, iam_admin_v1from posthog.models.integration import GoogleCloudServiceAccountIntegration-from products.batch_exports.backend.presentation.views.destination_tests.base import (+from products.batch_exports.backend.destination_tests.base import (DestinationTest,DestinationTestStep,DestinationTestStepResult,diff --git a/products/batch_exports/backend/presentation/views/destination_tests/databricks.py b/products/batch_exports/backend/destination_tests/databricks.pysimilarity index 99%rename from products/batch_exports/backend/presentation/views/destination_tests/databricks.pyrename to products/batch_exports/backend/destination_tests/databricks.pyindex 2919e31306b0..8114f165515c 100644--- a/products/batch_exports/backend/presentation/views/destination_tests/databricks.py+++ b/products/batch_exports/backend/destination_tests/databricks.py@@ -2,7 +2,7 @@ import contextlibimport collections.abcfrom collections.abc import AsyncGenerator-from products.batch_exports.backend.presentation.views.destination_tests.base import (+from products.batch_exports.backend.destination_tests.base import (DestinationTest,DestinationTestStep,DestinationTestStepResult,diff --git a/products/batch_exports/backend/presentation/views/destination_tests/s3.py b/products/batch_exports/backend/destination_tests/s3.pysimilarity index 99%rename from products/batch_exports/backend/presentation/views/destination_tests/s3.pyrename to products/batch_exports/backend/destination_tests/s3.pyindex 8f888072d22c..da20f33070ae 100644--- a/products/batch_exports/backend/presentation/views/destination_tests/s3.py+++ b/products/batch_exports/backend/destination_tests/s3.py@@ -1,6 +1,6 @@import collections.abc-from products.batch_exports.backend.presentation.views.destination_tests.base import (+from products.batch_exports.backend.destination_tests.base import (DestinationTest,DestinationTestStep,DestinationTestStepResult,diff --git a/products/batch_exports/backend/presentation/views/destination_tests/snowflake.py b/products/batch_exports/backend/destination_tests/snowflake.pysimilarity index 99%rename from products/batch_exports/backend/presentation/views/destination_tests/snowflake.pyrename to products/batch_exports/backend/destination_tests/snowflake.pyindex f9c78b7d69f3..03e780457cbf 100644--- a/products/batch_exports/backend/presentation/views/destination_tests/snowflake.py+++ b/products/batch_exports/backend/destination_tests/snowflake.py@@ -1,7 +1,7 @@import asyncioimport collections.abc-from products.batch_exports.backend.presentation.views.destination_tests.base import (+from products.batch_exports.backend.destination_tests.base import (DestinationTest,DestinationTestStep,DestinationTestStepResult,diff --git a/products/batch_exports/backend/facade/api.py b/products/batch_exports/backend/facade/api.pyindex eedfdf22f06a..52c2f136f42c 100644--- a/products/batch_exports/backend/facade/api.py+++ b/products/batch_exports/backend/facade/api.py@@ -30,6 +30,9 @@ from django.db.models.functions import Coalesceimport structlog+from posthog.models.integration import Integration++from products.batch_exports.backend import destination_testsfrom products.batch_exports.backend.billing import exclude_non_billable_runsfrom products.batch_exports.backend.filters import validate_batch_export_filtersfrom products.batch_exports.backend.models.batch_export import (@@ -55,6 +58,7 @@ __all__ = ["create_workflows_backfill_export","delete_batch_export","delete_batch_exports_for_teams",+ "describe_destination_test","get_batch_export_by_name","get_latest_completed_run","get_latest_run",@@ -65,6 +69,7 @@ __all__ = ["list_batch_exports_using_integration","list_latest_failed_runs","list_supported_intervals",+ "run_destination_test_step",]logger = structlog.get_logger(__name__)@@ -135,6 +140,15 @@ def _to_detail(batch_export: BatchExport) -> contracts.BatchExportDetail:)+def _to_destination_test_step(+ step: destination_tests.base.DestinationTestStep,+) -> contracts.DestinationTestStep:+ result = None+ if step.result is not None:+ result = contracts.DestinationTestStepResult(status=str(step.result.status), message=step.result.message)+ return contracts.DestinationTestStep(name=step.name, description=step.description, result=result)++def _to_backfill_summary(backfill: BatchExportBackfill) -> contracts.BatchExportBackfillSummary:return contracts.BatchExportBackfillSummary(id=backfill.id,@@ -414,3 +428,39 @@ def backfill_batch_export(def list_supported_intervals() -> tuple[str, ...]:"""Return the intervals a batch export may be scheduled on."""return tuple(interval for interval, _ in BATCH_EXPORT_INTERVALS)+++def describe_destination_test(destination_type: str) -> contracts.DestinationTest:+ """Return the steps of a destination's connection test, with no step run."""+ destination_test = destination_tests.get_destination_test(destination=destination_type)+ return contracts.DestinationTest(steps=tuple(_to_destination_test_step(step) for step in destination_test.steps))+++def run_destination_test_step(+ team_id: int,+ *,+ destination_type: str,+ config: Mapping[str, object],+ integration_id: int | None,+ step: int,+) -> contracts.DestinationTestStep:+ """Run one step of a destination's connection test, and return that step with its result.++ ``config`` is a destination config that already passed validation. The step reaches the+ destination over the network. When the destination authenticates through an integration,+ the integration's config and secrets override any key of the same name in ``config``.+ """+ destination_test = destination_tests.get_destination_test(destination=destination_type)++ test_configuration = dict(config)+ if integration_id is not None:+ integration = Integration.objects.get(id=integration_id, team_id=team_id)+ test_configuration = {+ **test_configuration,+ **integration.config,+ **integration.sensitive_config,+ "integration": integration,+ }++ destination_test.configure(**test_configuration)+ return _to_destination_test_step(destination_test.run_step(step))diff --git a/products/batch_exports/backend/facade/contracts.py b/products/batch_exports/backend/facade/contracts.pyindex 77b576d17499..f1e2d0e966ee 100644--- a/products/batch_exports/backend/facade/contracts.py+++ b/products/batch_exports/backend/facade/contracts.py@@ -33,6 +33,10 @@ class InvalidBatchExportFilters(ValueError):"""Raised when event filters are not a list of filters a batch export can apply."""+class UnsupportedDestinationTestError(ValueError):+ """Raised when a destination type has no connection test."""++@dataclass(frozen=True)class BatchExportRef:"""The bare identity of a batch export, for listing it by name."""@@ -117,6 +121,33 @@ class TeamTotal:total: int+@dataclass(frozen=True)+class DestinationTestStepResult:+ """The outcome of one destination test step. ``message`` explains a failure."""++ status: str+ message: str | None+++@dataclass(frozen=True)+class DestinationTestStep:+ """One check in a destination's connection test. ``result`` is None until the step runs."""++ name: str+ description: str+ result: DestinationTestStepResult | None+++@dataclass(frozen=True)+class DestinationTest:+ """The ordered checks that test a connection to a destination.++ Each step depends on the steps before it, so a client runs them in order.+ """++ steps: tuple[DestinationTestStep, ...]++@stdlib_dataclass(frozen=True)class AWSCredentials:"""An AWS key pair, optionally temporary.diff --git a/products/batch_exports/backend/presentation/views/batch_export/exports.py b/products/batch_exports/backend/presentation/views/batch_export/exports.pyindex 92bdbfb127bf..f508337d902a 100644--- a/products/batch_exports/backend/presentation/views/batch_export/exports.py+++ b/products/batch_exports/backend/presentation/views/batch_export/exports.py@@ -42,7 +42,8 @@ from posthog.security.url_validation import (from posthog.temporal.common.client import sync_connectfrom products.access_control.backend.facade.api import get_restricted_properties_with_group_type_index_for_team-from products.batch_exports.backend.facade.contracts import InvalidBatchExportFilters+from products.batch_exports.backend.facade import api as batch_exports_api+from products.batch_exports.backend.facade.contracts import InvalidBatchExportFilters, UnsupportedDestinationTestErrorfrom products.batch_exports.backend.filters import SUPPORTED_FILTER_TYPES_DISPLAY, validate_batch_export_filtersfrom products.batch_exports.backend.hogql_source import (UnsupportedHogQLQueryError,@@ -58,7 +59,6 @@ from products.batch_exports.backend.models.batch_export import (BatchExportDestination,BatchExportSource,)-from products.batch_exports.backend.presentation.views.destination_tests import get_destination_testfrom products.batch_exports.backend.presentation.views.utils import (HOGQL_MODIFIERS_HELP_TEXT,HogQLModifiersField,@@ -106,6 +106,13 @@ class BatchExportUnpauseRequestSerializer(serializers.Serializer):)+class DestinationTestStepRequestSerializer(serializers.Serializer):+ step = serializers.IntegerField(+ default=0,+ help_text="Index of the connection test step to run. Steps start at 0.",+ )++class BatchExportRequestSerializer(serializers.Serializer):"""Request body for create/partial_update on BatchExportViewSet.@@ -1152,6 +1159,27 @@ class BatchExportViewSet(TeamAndOrgViewSetMixin, LogEntryMixin, viewsets.ModelVi"""delete_batch_export(instance)+ def _parse_destination_test_step(self, request: request.Request) -> int:+ step_serializer = DestinationTestStepRequestSerializer(data=request.data)+ step_serializer.is_valid(raise_exception=True)+ request.data.pop("step", None)+ return step_serializer.validated_data["step"]++ def _run_destination_test_step(self, serializer: serializers.BaseSerializer, step: int) -> response.Response:+ destination = serializer.validated_data["destination"]+ integration: Integration | None = destination.get("integration")+ try:+ result = batch_exports_api.run_destination_test_step(+ self.team_id,+ destination_type=destination["type"],+ config=destination["config"],+ integration_id=integration.id if integration else None,+ step=step,+ )+ except UnsupportedDestinationTestError:+ raise ValidationError(f"Connection tests aren't available for {destination['type']} destinations.")+ return response.Response(dataclasses.asdict(result))+@action(methods=["GET"], detail=False, required_scopes=["batch_export:read"])def test(self, request: request.Request, *args, **kwargs) -> response.Response:destination = request.query_params.get("destination", None)@@ -1159,42 +1187,24 @@ class BatchExportViewSet(TeamAndOrgViewSetMixin, LogEntryMixin, viewsets.ModelVireturn response.Response(status=status.HTTP_400_BAD_REQUEST)try:- destination_test = get_destination_test(destination=destination)- except ValueError:+ destination_test = batch_exports_api.describe_destination_test(destination)+ except UnsupportedDestinationTestError:return response.Response(status=status.HTTP_404_NOT_FOUND)- return response.Response(destination_test.as_dict())+ return response.Response(dataclasses.asdict(destination_test))@action(methods=["POST"], detail=False, required_scopes=["batch_export:write"])def run_test_step_new(self, request: request.Request, *args, **kwargs) -> response.Response:- test_step = request.data.pop("step", 0)+ test_step = self._parse_destination_test_step(request)serializer = self.get_serializer(data=request.data)_ = serializer.is_valid(raise_exception=True)- destination_test = get_destination_test(- destination=serializer.validated_data["destination"]["type"],- )- test_configuration = serializer.validated_data["destination"]["config"]-- # if we have an integration, add its config and sensitive_config to test_configuration- integration: Integration | None = serializer.validated_data["destination"].get("integration")- if integration:- test_configuration = {- **test_configuration,- **integration.config,- **integration.sensitive_config,- "integration": integration,- }-- destination_test.configure(**test_configuration)-- result = destination_test.run_step(test_step)- return response.Response(result.as_dict())+ return self._run_destination_test_step(serializer, test_step)@action(methods=["POST"], detail=True, required_scopes=["batch_export:write"])def run_test_step(self, request: request.Request, *args, **kwargs) -> response.Response:- test_step = request.data.pop("step", 0)+ test_step = self._parse_destination_test_step(request)batch_export = self.get_object()@@ -1211,22 +1221,4 @@ class BatchExportViewSet(TeamAndOrgViewSetMixin, LogEntryMixin, viewsets.ModelViserializer = self.get_serializer(data=data)_ = serializer.is_valid(raise_exception=True)- destination_test = get_destination_test(- destination=serializer.validated_data["destination"]["type"],- )- test_configuration = serializer.validated_data["destination"]["config"]-- # if we have an integration, add its config and sensitive_config to test_configuration- integration: Integration | None = serializer.validated_data["destination"].get("integration")- if integration:- test_configuration = {- **test_configuration,- **integration.config,- **integration.sensitive_config,- "integration": integration,- }-- destination_test.configure(**test_configuration)-- result = destination_test.run_step(test_step)- return response.Response(result.as_dict())+ return self._run_destination_test_step(serializer, test_step)diff --git a/products/batch_exports/backend/presentation/views/destination_tests/__init__.py b/products/batch_exports/backend/presentation/views/destination_tests/__init__.pydeleted file mode 100644index 2106e7fb1680..000000000000--- a/products/batch_exports/backend/presentation/views/destination_tests/__init__.py+++ /dev/null@@ -1,50 +0,0 @@-from products.batch_exports.backend.presentation.views.destination_tests.base import DestinationTest---def get_destination_test(- destination: str,-) -> DestinationTest:- """Resolve a destination to its corresponding `DestinationTest` implementation.-- Per-branch deferred imports: each destination test module pulls a heavy vendor SDK- (databricks, google-cloud-bigquery, snowflake, etc.). Importing them lazily keeps the- SDKs off the API import path — only the requested destination's SDK loads.- """- if destination == "S3Compatible":- from products.batch_exports.backend.presentation.views.destination_tests.s3 import ( # noqa: PLC0415- S3CompatibleDestinationTest,- )-- return S3CompatibleDestinationTest()- elif destination == "AwsS3":- from products.batch_exports.backend.presentation.views.destination_tests.s3 import ( # noqa: PLC0415- AwsS3DestinationTest,- )-- return AwsS3DestinationTest()- elif destination == "BigQuery":- from products.batch_exports.backend.presentation.views.destination_tests.bigquery import ( # noqa: PLC0415- BigQueryDestinationTest,- )-- return BigQueryDestinationTest()- elif destination == "Snowflake":- from products.batch_exports.backend.presentation.views.destination_tests.snowflake import ( # noqa: PLC0415- SnowflakeDestinationTest,- )-- return SnowflakeDestinationTest()- elif destination == "Databricks":- from products.batch_exports.backend.presentation.views.destination_tests.databricks import ( # noqa: PLC0415- DatabricksDestinationTest,- )-- return DatabricksDestinationTest()- elif destination == "AzureBlob":- from products.batch_exports.backend.presentation.views.destination_tests.azure_blob import ( # noqa: PLC0415- AzureBlobDestinationTest,- )-- return AzureBlobDestinationTest()- else:- raise ValueError(f"Unsupported destination: {destination}")diff --git a/products/batch_exports/backend/tests/api/test_test.py b/products/batch_exports/backend/tests/api/test_destination_tests.pysimilarity index 83%rename from products/batch_exports/backend/tests/api/test_test.pyrename to products/batch_exports/backend/tests/api/test_destination_tests.pyindex 70a1b6a6d159..7563d7e086d2 100644--- a/products/batch_exports/backend/tests/api/test_test.py+++ b/products/batch_exports/backend/tests/api/test_destination_tests.py@@ -13,13 +13,13 @@ from rest_framework import statusfrom posthog.models import Integration-from products.batch_exports.backend.models.batch_export import BatchExportDestination-from products.batch_exports.backend.presentation.views.destination_tests.base import DestinationTestStepResult, Status-from products.batch_exports.backend.presentation.views.destination_tests.bigquery import BigQueryProjectTestStep-from products.batch_exports.backend.presentation.views.destination_tests.databricks import (+from products.batch_exports.backend.destination_tests.base import DestinationTestStepResult, Status+from products.batch_exports.backend.destination_tests.bigquery import BigQueryProjectTestStep+from products.batch_exports.backend.destination_tests.databricks import (DatabricksDestinationTest,DatabricksEstablishConnectionTestStep,)+from products.batch_exports.backend.models.batch_export import BatchExportDestinationfrom products.batch_exports.backend.tests.api.operations import create_batch_export_okpytestmark = [@@ -48,6 +48,35 @@ def test_can_get_test_for_destination(client: HttpClient, destination: str, orgaassert all("name" in step and "description" in step for step in destination_test["steps"])+def test_get_test_for_destination_without_a_test_is_not_found(client: HttpClient, organization, team, user) -> None:+ client.force_login(user)++ response = client.get(f"/api/projects/{team.pk}/batch_exports/test", {"destination": "Postgres"})++ assert response.status_code == status.HTTP_404_NOT_FOUND+++def test_run_test_step_for_destination_without_a_test_is_rejected(client: HttpClient, organization, team, user) -> None:+ client.force_login(user)++ response = client.post(+ f"/api/projects/{team.pk}/batch_exports/run_test_step_new",+ {+ "step": 0,+ "name": "my-http-destination",+ "destination": {+ "type": "HTTP",+ "config": {"url": "https://us.i.posthog.com/batch/", "token": "fake-token"},+ },+ "interval": "hour",+ },+ content_type="application/json",+ )++ assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()+ assert response.json()["detail"] == "Connection tests aren't available for HTTP destinations."++TEST_ROOT_BUCKET = "test-destination-tests"SESSION = aioboto3.Session()create_test_client = functools.partial(SESSION.client, endpoint_url=settings.OBJECT_STORAGE_ENDPOINT)@@ -219,7 +248,7 @@ def test_run_test_step_rejects_destination_type_change(}with unittest.mock.patch(- "products.batch_exports.backend.presentation.views.batch_export.exports.get_destination_test"+ "products.batch_exports.backend.destination_tests.get_destination_test") as mock_get_destination_test:response = client.post(f"/api/projects/{team.pk}/batch_exports/{batch_export['id']}/run_test_step",@@ -348,7 +377,7 @@ def test_can_run_bigquery_test_step_with_castable_type()with unittest.mock.patch(- "products.batch_exports.backend.presentation.views.destination_tests.base.DestinationTest.run_step"+ "products.batch_exports.backend.destination_tests.base.DestinationTest.run_step") as run_step_mocked:fake_test_step = BigQueryProjectTestStep()fake_test_step.result = DestinationTestStepResult(status=Status.PASSED, message=None)@@ -404,7 +433,7 @@ def test_can_run_databricks_test_step_for_new_destination(client.force_login(user)with unittest.mock.patch(- "products.batch_exports.backend.presentation.views.batch_export.exports.get_destination_test"+ "products.batch_exports.backend.destination_tests.get_destination_test") as mock_get_destination_test:test_step = DatabricksEstablishConnectionTestStep()test_step.result = DestinationTestStepResult(status=Status.PASSED, message=None)@@ -433,10 +462,41 @@ def test_can_run_databricks_test_step_for_new_destination(assert response.status_code == status.HTTP_200_OK, response.json()- destination_test = response.json()+ assert response.json() == {+ "name": DatabricksEstablishConnectionTestStep.name,+ "description": DatabricksEstablishConnectionTestStep.description,+ "result": {"status": "Passed", "message": None},+ }- assert destination_test["result"]["status"] == "Passed", destination_test- assert destination_test["result"]["message"] is None+[email protected]("step", [True, "first", 1.5])+def test_run_test_step_rejects_a_step_that_is_not_an_integer(+ client: HttpClient, organization, team, user, databricks_integration, step: object+) -> None:+ client.force_login(user)++ response = client.post(+ f"/api/projects/{team.pk}/batch_exports/run_test_step_new",+ {+ "step": step,+ "name": "my-databricks-batch-export",+ "destination": {+ "type": "Databricks",+ "integration": databricks_integration.id,+ "config": {+ "http_path": "my-http-path",+ "catalog": "my-catalog",+ "schema": "my-schema",+ "table_name": "my-table-name",+ },+ },+ "interval": "hour",+ },+ content_type="application/json",+ )++ assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()+ assert response.json()["attr"] == "step"def test_integration_is_required_for_databricks_destination_tests(diff --git a/products/batch_exports/backend/tests/api/destination_tests/__init__.py b/products/batch_exports/backend/tests/destination_tests/__init__.pysimilarity index 100%rename from products/batch_exports/backend/tests/api/destination_tests/__init__.pyrename to products/batch_exports/backend/tests/destination_tests/__init__.pydiff --git a/products/batch_exports/backend/tests/api/destination_tests/conftest.py b/products/batch_exports/backend/tests/destination_tests/conftest.pysimilarity index 100%rename from products/batch_exports/backend/tests/api/destination_tests/conftest.pyrename to products/batch_exports/backend/tests/destination_tests/conftest.pydiff --git a/products/batch_exports/backend/tests/api/destination_tests/test_azure_blob_destination_tests.py b/products/batch_exports/backend/tests/destination_tests/test_azure_blob_destination_tests.pysimilarity index 95%rename from products/batch_exports/backend/tests/api/destination_tests/test_azure_blob_destination_tests.pyrename to products/batch_exports/backend/tests/destination_tests/test_azure_blob_destination_tests.pyindex 482dc0a2d856..f5bf782b6232 100644--- a/products/batch_exports/backend/tests/api/destination_tests/test_azure_blob_destination_tests.py+++ b/products/batch_exports/backend/tests/destination_tests/test_azure_blob_destination_tests.py@@ -5,10 +5,7 @@ import pytestfrom azure.storage.blob.aio import BlobServiceClient-from products.batch_exports.backend.presentation.views.destination_tests.azure_blob import (- AzureBlobContainerTestStep,- Status,-)+from products.batch_exports.backend.destination_tests.azure_blob import AzureBlobContainerTestStep, Statusfrom products.batch_exports.backend.tests.temporal.destinations.azure_blob.conftest import AZURITE_CONNECTION_STRINGpytestmark = [pytest.mark.asyncio]diff --git a/products/batch_exports/backend/tests/api/destination_tests/test_bigquery_destination_tests.py b/products/batch_exports/backend/tests/destination_tests/test_bigquery_destination_tests.pysimilarity index 99%rename from products/batch_exports/backend/tests/api/destination_tests/test_bigquery_destination_tests.pyrename to products/batch_exports/backend/tests/destination_tests/test_bigquery_destination_tests.pyindex a574f744c14d..63c8f04e2d71 100644--- a/products/batch_exports/backend/tests/api/destination_tests/test_bigquery_destination_tests.py+++ b/products/batch_exports/backend/tests/destination_tests/test_bigquery_destination_tests.py@@ -12,7 +12,7 @@ from google.cloud import bigquery, exceptionsfrom posthog.models.integration import GoogleCloudServiceAccountIntegration-from products.batch_exports.backend.presentation.views.destination_tests.bigquery import (+from products.batch_exports.backend.destination_tests.bigquery import (BigQueryDatasetTestStep,BigQueryImpersonateServiceAccountTestStep,BigQueryProjectTestStep,diff --git a/products/batch_exports/backend/tests/api/destination_tests/test_databricks_destination_tests.py b/products/batch_exports/backend/tests/destination_tests/test_databricks_destination_tests.pysimilarity index 97%rename from products/batch_exports/backend/tests/api/destination_tests/test_databricks_destination_tests.pyrename to products/batch_exports/backend/tests/destination_tests/test_databricks_destination_tests.pyindex 5f3956d2bcd3..a51a0ace91c0 100644--- a/products/batch_exports/backend/tests/api/destination_tests/test_databricks_destination_tests.py+++ b/products/batch_exports/backend/tests/destination_tests/test_databricks_destination_tests.py@@ -7,8 +7,8 @@ from unittest.mock import patchfrom databricks import sqlfrom databricks.sdk.core import Config, oauth_service_principal-from products.batch_exports.backend.presentation.views.destination_tests.base import Status-from products.batch_exports.backend.presentation.views.destination_tests.databricks import (+from products.batch_exports.backend.destination_tests.base import Status+from products.batch_exports.backend.destination_tests.databricks import (DatabricksCatalogTestStep,DatabricksEstablishConnectionTestStep,DatabricksSchemaTestStep,@@ -247,7 +247,7 @@ class TestDatabricksVolumeTestStep:and one where it doesn't."""with patch(- "products.batch_exports.backend.presentation.views.destination_tests.databricks.DatabricksClient.acreate_volume",+ "products.batch_exports.backend.destination_tests.databricks.DatabricksClient.acreate_volume",side_effect=DatabricksInsufficientPermissionsError("CREATE VOLUME", "Insufficient permissions"),):test_step = DatabricksVolumeTestStep(diff --git a/products/batch_exports/backend/tests/api/destination_tests/test_s3_destination_tests.py b/products/batch_exports/backend/tests/destination_tests/test_s3_destination_tests.pysimilarity index 91%rename from products/batch_exports/backend/tests/api/destination_tests/test_s3_destination_tests.pyrename to products/batch_exports/backend/tests/destination_tests/test_s3_destination_tests.pyindex a52fccf9f61f..647b0b380207 100644--- a/products/batch_exports/backend/tests/api/destination_tests/test_s3_destination_tests.py+++ b/products/batch_exports/backend/tests/destination_tests/test_s3_destination_tests.py@@ -5,8 +5,8 @@ import pytestfrom django.conf import settingsfrom django.test import override_settings-from products.batch_exports.backend.presentation.views.destination_tests import get_destination_test-from products.batch_exports.backend.presentation.views.destination_tests.s3 import (+from products.batch_exports.backend.destination_tests import get_destination_test+from products.batch_exports.backend.destination_tests.s3 import (AwsS3DestinationTest,S3AssumeRoleTestStep,S3CompatibleDestinationTest,@@ -131,20 +131,14 @@ def test_get_destination_test_resolves_s3_family(destination, expected_test, expassert [type(step) for step in destination_test.steps] == expected_steps-def test_aws_s3_destination_test_serializes_without_integration():- """AwsS3 configured with inline credentials (no integration) must not raise.-- Its steps reference `organization_id` and each step needs an initialized- `result`, so building the steps and serializing them exercises both.- """+def test_aws_s3_destination_test_builds_steps_without_integration() -> None:+ # The AwsS3 steps read organization_id, which an inline-credential config never sets.destination_test = AwsS3DestinationTest()destination_test.configure(bucket_name="b", region="us-east-1", aws_access_key_id="a", aws_secret_access_key="s")- assert destination_test.as_dict() == {- "steps": [- {"name": step.name, "description": step.description, "result": None} for step in destination_test.steps- ]- }+ steps = destination_test.steps+ assert len(steps) > 0+ assert all(step.result is None for step in steps)async def test_assume_role_step_passes_with_assumable_role(diff --git a/products/batch_exports/backend/tests/api/destination_tests/test_snowflake_destination_tests.py b/products/batch_exports/backend/tests/destination_tests/test_snowflake_destination_tests.pysimilarity index 99%rename from products/batch_exports/backend/tests/api/destination_tests/test_snowflake_destination_tests.pyrename to products/batch_exports/backend/tests/destination_tests/test_snowflake_destination_tests.pyindex a32dd42f4c13..a3a052854fc0 100644--- a/products/batch_exports/backend/tests/api/destination_tests/test_snowflake_destination_tests.py+++ b/products/batch_exports/backend/tests/destination_tests/test_snowflake_destination_tests.py@@ -5,7 +5,7 @@ import pytestimport snowflake.connector-from products.batch_exports.backend.presentation.views.destination_tests.snowflake import (+from products.batch_exports.backend.destination_tests.snowflake import (SnowflakeDatabaseTestStep,SnowflakeEstablishConnectionTestStep,SnowflakeSchemaTestStep,diff --git a/products/batch_exports/backend/tests/test_facade.py b/products/batch_exports/backend/tests/test_facade.pyindex 87e43e569a37..2b35e3b27500 100644--- a/products/batch_exports/backend/tests/test_facade.py+++ b/products/batch_exports/backend/tests/test_facade.py@@ -10,7 +10,7 @@ from temporalio.client import Clientfrom posthog.api.test.test_organization import create_organizationfrom posthog.api.test.test_team import create_team-from posthog.models import User+from posthog.models import Integration, Userfrom posthog.temporal.common.client import sync_connectfrom products.batch_exports.backend.facade import api, contracts, testing@@ -361,3 +361,26 @@ def test_creating_and_deleting_a_batch_export_manages_its_temporal_schedule(teamassert BatchExport.objects.get(id=detail.id).deleted is Truewith pytest.raises(temporalio.service.RPCError):_describe_schedule(temporal, str(detail.id))+++def test_destination_test_step_refuses_an_integration_from_another_team(team, organization):+ other_team = create_team(organization=organization)+ integration = Integration.objects.create(+ team=other_team,+ kind=Integration.IntegrationKind.DATABRICKS,+ integration_id="example-server-hostname",+ config={"server_hostname": "example-server-hostname"},+ sensitive_config={"client_id": "fake-client-id", "client_secret": "fake-client-secret"},+ )++ with (+ mock.patch("products.batch_exports.backend.destination_tests.get_destination_test"),+ pytest.raises(Integration.DoesNotExist),+ ):+ api.run_destination_test_step(+ team.pk,+ destination_type="Databricks",+ config={"http_path": "fake-http-path", "catalog": "catalog", "schema": "schema", "table_name": "events"},+ integration_id=integration.id,+ step=0,+ )diff --git a/pyproject.toml b/pyproject.tomlindex 073cd8798288..537055760a7e 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -736,10 +736,6 @@ ignore_imports = ["products.batch_exports.backend.presentation.views.batch_export.exports -> products.batch_exports.backend.temporal.sql.events","products.batch_exports.backend.presentation.views.batch_export.runs -> products.batch_exports.backend.models.batch_export","products.batch_exports.backend.presentation.views.batch_export.runs -> products.batch_exports.backend.service",- "products.batch_exports.backend.presentation.views.destination_tests.bigquery -> products.batch_exports.backend.temporal.destinations.bigquery_batch_export",- "products.batch_exports.backend.presentation.views.destination_tests.databricks -> products.batch_exports.backend.temporal.destinations.databricks_batch_export",- "products.batch_exports.backend.presentation.views.destination_tests.s3 -> products.batch_exports.backend.temporal.destinations.s3_batch_export",- "products.batch_exports.backend.presentation.views.destination_tests.snowflake -> products.batch_exports.backend.temporal.destinations.snowflake_batch_export","products.batch_exports.backend.presentation.views.file_download -> products.batch_exports.backend.hogql_source","products.batch_exports.backend.presentation.views.file_download -> products.batch_exports.backend.models.batch_export","products.batch_exports.backend.presentation.views.file_download -> products.batch_exports.backend.service",