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 Clockodo API version v3 (#74175)

Tom Owers8f9c4049744b
diff --git a/products/warehouse_sources/backend/migrations/0106_repin_clockodo_api_version.py b/products/warehouse_sources/backend/migrations/0106_repin_clockodo_api_version.py
new file mode 100644
index 000000000000..b9ac77b3b09e
--- /dev/null
+++ b/products/warehouse_sources/backend/migrations/0106_repin_clockodo_api_version.py
@@ -0,0 +1,37 @@
+from django.db import migrations
+
+# Clockodo decommissions the v2 endpoints behind six of this source's tables on 2026-05-01
+# (customers, projects, services, lumpsum_services, users, teams), replacing them with
+# individually-versioned v3/v4 successors; surcharges and entries stay on v2. The source now
+# defaults new instances to "v3", whose endpoint map routes each table to its non-deprecated
+# successor. This repins existing source-level pins from "v2" to "v3" so their next sync reads
+# the live endpoints. Every Clockodo table is full refresh only and the successors keep the
+# integer `id` primary key, so the next full-refresh sync auto-infers the v3/v4 columns; the pin
+# is the only thing that needs to move.
+CLOCKODO_SOURCE_TYPE = "Clockodo"
+OLD_VERSION = "v2"
+NEW_VERSION = "v3"
+
+
+def repin_clockodo_v2_to_v3(apps, schema_editor):
+ ExternalDataSource = apps.get_model("warehouse_sources", "ExternalDataSource")
+
+ # Only source-level pins still on the deprecated version move. NULL pins already resolve to
+ # the source's default_version (now "v3"), so they need no update. Filtering on the exact old
+ # value keeps this idempotent — a re-run matches nothing. Schema-level overrides
+ # (ExternalDataSchema.api_version) are intentionally customer-pinned and are left untouched;
+ # the schema-level deprecation warning prompts the user to migrate those.
+ ExternalDataSource.objects.filter(source_type=CLOCKODO_SOURCE_TYPE, api_version=OLD_VERSION).update(
+ api_version=NEW_VERSION
+ )
+
+
+class Migration(migrations.Migration):
+ dependencies = [("warehouse_sources", "0105_repin_harvey_api_version_v2")]
+
+ operations = [
+ # Reverse is a no-op: once repinned, these rows are indistinguishable from natively-created
+ # v3 rows, so a blanket downgrade would clobber legitimate v3 pins and move customers back
+ # onto endpoints that 404 after the sunset.
+ migrations.RunPython(repin_clockodo_v2_to_v3, migrations.RunPython.noop, elidable=False),
+ ]
diff --git a/products/warehouse_sources/backend/migrations/max_migration.txt b/products/warehouse_sources/backend/migrations/max_migration.txt
index ae11522abf23..f81ed632653c 100644
--- a/products/warehouse_sources/backend/migrations/max_migration.txt
+++ b/products/warehouse_sources/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0105_repin_harvey_api_version_v2
+0106_repin_clockodo_api_version
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/clockodo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/clockodo.py
index df4ff10c4e28..9a2948345c1d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/clockodo.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/clockodo.py
@@ -4,8 +4,9 @@ from typing import Any, Optional
from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import SourceResponse
from products.warehouse_sources.backend.temporal.data_imports.sources.clockodo.settings import (
- CLOCKODO_ENDPOINTS,
ENTRIES_TIME_SINCE,
+ ClockodoEndpointConfig,
+ endpoints_for_version,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_session
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source import (
@@ -50,8 +51,7 @@ def _format_z(dt: datetime) -> str:
return utc_dt.strftime("%Y-%m-%dT%H:%M:%SZ")
-def _endpoint_params(endpoint: str) -> dict[str, Any]:
- config = CLOCKODO_ENDPOINTS[endpoint]
+def _endpoint_params(endpoint: str, config: ClockodoEndpointConfig) -> dict[str, Any]:
params: dict[str, Any] = dict(config.extra_params)
if endpoint == "entries":
# Send a wide window so every entry is in range. time_until is pushed a year past now
@@ -68,8 +68,9 @@ def clockodo_source(
team_id: int,
job_id: str,
resumable_source_manager: ResumableSourceManager[ClockodoResumeConfig],
+ api_version: str,
) -> SourceResponse:
- config = CLOCKODO_ENDPOINTS[endpoint]
+ config = endpoints_for_version(api_version)[endpoint]
# Clockodo only paginates a subset of resources; paginated responses carry the total
# page count at paging.count_pages, so we stop after the last page. An empty page also
@@ -92,7 +93,7 @@ def clockodo_source(
"name": endpoint,
"endpoint": {
"path": config.path,
- "params": _endpoint_params(endpoint),
+ "params": _endpoint_params(endpoint, config),
"data_selector": config.data_key,
},
}
@@ -128,11 +129,16 @@ def clockodo_source(
)
-def validate_credentials(api_user: str, api_key: str) -> bool:
- """Cheap probe to confirm the API user/key pair is genuine."""
+def validate_credentials(api_user: str, api_key: str, api_version: str) -> bool:
+ """Cheap probe to confirm the API user/key pair is genuine.
+
+ Probes the users endpoint for the resolved version so a new source (default v3) does not
+ validate against `v2/users`, which is decommissioned on 2026-05-01.
+ """
+ users_path = endpoints_for_version(api_version)["users"].path
ok, _status = validate_via_probe(
lambda: make_tracked_session(redact_values=(api_key,)),
- f"{CLOCKODO_BASE_URL}/v2/users",
+ f"{CLOCKODO_BASE_URL}/{users_path}",
headers={"X-ClockodoApiKey": api_key, **_build_headers(api_user)},
)
return ok
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/settings.py
index c2cbac11c67d..0f38c0840f9c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/settings.py
@@ -1,7 +1,19 @@
+import dataclasses
from dataclasses import dataclass, field
from products.warehouse_sources.backend.types import IncrementalField
+# Clockodo versions its endpoints per resource rather than per account, so the source-level
+# label is opaque: "v2" is the pre-2026-05 endpoint set; "v3" is the post-deprecation set that
+# routes each resource to its non-deprecated successor (a mix of the vendor's v3 and v4 routes).
+# On 2026-05-01 Clockodo decommissions the v2 endpoints behind six of our tables
+# (https://www.clockodo.com/en/blog/deprecation-of-legacy-api-endpoints-on-may-1-2026/), so a
+# "v2"-pinned source keeps working only until then; "v3" is the migration target.
+CLOCKODO_API_VERSION_V2 = "v2"
+CLOCKODO_API_VERSION_V3 = "v3"
+CLOCKODO_SUPPORTED_VERSIONS = (CLOCKODO_API_VERSION_V2, CLOCKODO_API_VERSION_V3)
+CLOCKODO_DEFAULT_API_VERSION = CLOCKODO_API_VERSION_V3
+
@dataclass
class ClockodoEndpointConfig:
@@ -10,6 +22,7 @@ class ClockodoEndpointConfig:
data_key: str # key in the JSON response body that holds the list of rows
# Clockodo only paginates a subset of resources (entries, entriesTexts, customers,
# projects). The rest return the full collection in a single response with no paging block.
+ # Every v3/v4 collection paginates, so the successor configs flip this on.
paginated: bool = False
# Static query params required by the endpoint (e.g. the entries time window).
extra_params: dict[str, str] = field(default_factory=dict)
@@ -24,7 +37,7 @@ class ClockodoEndpointConfig:
ENTRIES_TIME_SINCE = "2000-01-01T00:00:00Z"
-CLOCKODO_ENDPOINTS: dict[str, ClockodoEndpointConfig] = {
+CLOCKODO_ENDPOINTS_V2: dict[str, ClockodoEndpointConfig] = {
"customers": ClockodoEndpointConfig(
name="customers",
path="v2/customers",
@@ -72,8 +85,54 @@ CLOCKODO_ENDPOINTS: dict[str, ClockodoEndpointConfig] = {
),
}
-ENDPOINTS = tuple(CLOCKODO_ENDPOINTS.keys())
+
+def _v3(config: ClockodoEndpointConfig, path: str) -> ClockodoEndpointConfig:
+ """Successor config for a resource whose v2 endpoint is decommissioned on 2026-05-01.
+
+ The v3/v4 collections return their rows under a uniform "data" key (v2 used the resource
+ name) and paginate every collection, so only the wire fields change; the table name,
+ primary key, description, and sync default carry over from the v2 config.
+ """
+ return dataclasses.replace(config, path=path, data_key="data", paginated=True)
+
+
+# v3 reuses the v2 configs for the two resources Clockodo did not decommission (surcharges,
+# entries) and points the other six at their v3/v4 successors from the deprecation notice.
+CLOCKODO_ENDPOINTS_V3: dict[str, ClockodoEndpointConfig] = {
+ **CLOCKODO_ENDPOINTS_V2,
+ "customers": _v3(CLOCKODO_ENDPOINTS_V2["customers"], "v3/customers"),
+ "projects": _v3(CLOCKODO_ENDPOINTS_V2["projects"], "v4/projects"),
+ "services": _v3(CLOCKODO_ENDPOINTS_V2["services"], "v4/services"),
+ "lumpsum_services": _v3(CLOCKODO_ENDPOINTS_V2["lumpsum_services"], "v4/lumpSumServices"),
+ "users": _v3(CLOCKODO_ENDPOINTS_V2["users"], "v3/users"),
+ "teams": _v3(CLOCKODO_ENDPOINTS_V2["teams"], "v3/teams"),
+}
+
+CLOCKODO_ENDPOINTS_BY_VERSION: dict[str, dict[str, ClockodoEndpointConfig]] = {
+ CLOCKODO_API_VERSION_V2: CLOCKODO_ENDPOINTS_V2,
+ CLOCKODO_API_VERSION_V3: CLOCKODO_ENDPOINTS_V3,
+}
+
+
+def endpoints_for_version(api_version: str) -> dict[str, ClockodoEndpointConfig]:
+ """Per-resource endpoint map for a supported version.
+
+ Raises on a label outside `CLOCKODO_SUPPORTED_VERSIONS` rather than falling through to a
+ default, because silently routing an unknown pin to the wrong paths is the drift this
+ framework prevents. Callers resolve None to the default before this, so an unknown label
+ here means a deliberate but undeclared DB pin, which is a misconfiguration to surface.
+ """
+ try:
+ return CLOCKODO_ENDPOINTS_BY_VERSION[api_version]
+ except KeyError as e:
+ raise ValueError(
+ f"Unsupported Clockodo API version {api_version!r}; supported: {CLOCKODO_SUPPORTED_VERSIONS}"
+ ) from e
+
+
+# The table set is identical across versions, so discovery never orphans a table on repin.
+ENDPOINTS = tuple(CLOCKODO_ENDPOINTS_V2.keys())
# Clockodo exposes no server-side "modified since" filter on any resource (time_last_change is
# returned but not filterable), so every table is full refresh only — no incremental fields.
-INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {name: [] for name in CLOCKODO_ENDPOINTS}
+INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {name: [] for name in ENDPOINTS}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/source.py
index bc56d2c449b0..d927688b5e3b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/source.py
@@ -1,3 +1,4 @@
+from datetime import date
from typing import Optional, cast
from posthog.schema import (
@@ -19,11 +20,18 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.clockodo.c
validate_credentials as validate_clockodo_credentials,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.clockodo.settings import (
- CLOCKODO_ENDPOINTS,
+ CLOCKODO_API_VERSION_V2,
+ CLOCKODO_DEFAULT_API_VERSION,
+ CLOCKODO_SUPPORTED_VERSIONS,
ENDPOINTS,
INCREMENTAL_FIELDS,
+ endpoints_for_version,
+)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import (
+ FieldType,
+ ResumableSource,
+ VersionDeprecation,
)
-from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldType, ResumableSource
from products.warehouse_sources.backend.temporal.data_imports.sources.common.canonical_descriptions import (
CanonicalDescriptions,
)
@@ -42,9 +50,12 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType
@SourceRegistry.register
class ClockodoSource(ResumableSource[ClockodoSourceConfig, ClockodoResumeConfig]):
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
- supported_versions = ("v2",)
- default_version = "v2"
+ supported_versions = CLOCKODO_SUPPORTED_VERSIONS
+ default_version = CLOCKODO_DEFAULT_API_VERSION
api_docs_url = "https://docs.clockodo.com/"
+ # Clockodo decommissions the v2 endpoints behind six of this source's tables on 2026-05-01;
+ # the generic in-product warning banner keys off this metadata.
+ deprecated_versions = (VersionDeprecation(version=CLOCKODO_API_VERSION_V2, sunset_at=date(2026, 5, 1)),)
@property
def source_type(self) -> ExternalDataSourceType:
@@ -75,19 +86,16 @@ class ClockodoSource(ResumableSource[ClockodoSourceConfig, ClockodoResumeConfig]
force_refresh: bool = False,
api_version: str | None = None,
) -> list[SourceSchema]:
+ endpoints = endpoints_for_version(self.resolve_api_version(api_version))
# Clockodo exposes no server-side modified-since filter, so every table is full refresh only.
return build_endpoint_schemas(
ENDPOINTS,
INCREMENTAL_FIELDS,
names,
descriptions={
- endpoint: config.description
- for endpoint, config in CLOCKODO_ENDPOINTS.items()
- if config.description is not None
- },
- should_sync_default={
- endpoint: config.should_sync_default for endpoint, config in CLOCKODO_ENDPOINTS.items()
+ endpoint: config.description for endpoint, config in endpoints.items() if config.description is not None
},
+ should_sync_default={endpoint: config.should_sync_default for endpoint, config in endpoints.items()},
)
def validate_credentials(
@@ -97,7 +105,7 @@ class ClockodoSource(ResumableSource[ClockodoSourceConfig, ClockodoResumeConfig]
schema_name: Optional[str] = None,
api_version: str | None = None,
) -> tuple[bool, str | None]:
- if validate_clockodo_credentials(config.api_user, config.api_key):
+ if validate_clockodo_credentials(config.api_user, config.api_key, self.resolve_api_version(api_version)):
return True, None
return False, "Invalid Clockodo credentials"
@@ -118,6 +126,7 @@ class ClockodoSource(ResumableSource[ClockodoSourceConfig, ClockodoResumeConfig]
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),
)
@property
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/tests/test_clockodo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/tests/test_clockodo.py
index c0806c65d57d..a6328ebbf51e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/tests/test_clockodo.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/tests/test_clockodo.py
@@ -2,6 +2,7 @@ import json
from datetime import UTC, datetime
from typing import Any
+import pytest
from freezegun import freeze_time
from unittest import mock
@@ -16,6 +17,14 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.clockodo.c
clockodo_source,
validate_credentials,
)
+from products.warehouse_sources.backend.temporal.data_imports.sources.clockodo.settings import (
+ CLOCKODO_API_VERSION_V2,
+ CLOCKODO_API_VERSION_V3,
+ CLOCKODO_ENDPOINTS_V2,
+ CLOCKODO_SUPPORTED_VERSIONS,
+ ENDPOINTS,
+ endpoints_for_version,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.auth import APIKeyAuth
# RESTClient builds its session via make_tracked_session in the rest_client module.
@@ -51,8 +60,8 @@ def _make_manager(resume_state: ClockodoResumeConfig | None = None) -> mock.Magi
return manager
-def _wire(session: mock.MagicMock, responses: list[Response]) -> tuple[list[dict[str, Any]], list[Any]]:
- """Wire a mock session; capture each request's params and auth AT SEND TIME.
+def _wire(session: mock.MagicMock, responses: list[Response]) -> tuple[list[dict[str, Any]], list[Any], list[str]]:
+ """Wire a mock session; capture each request's params, auth, and URL AT SEND TIME.
``request.params`` is a single dict mutated in place across pages, so inspecting it after the
run shows only the final state — snapshot a copy when each request is prepared instead.
@@ -60,22 +69,24 @@ def _wire(session: mock.MagicMock, responses: list[Response]) -> tuple[list[dict
session.headers = {}
param_snapshots: list[dict[str, Any]] = []
auth_snapshots: list[Any] = []
+ url_snapshots: list[str] = []
def _prepare(request: Any) -> mock.MagicMock:
param_snapshots.append(dict(request.params or {}))
auth_snapshots.append(request.auth)
+ url_snapshots.append(request.url)
return mock.MagicMock()
session.prepare_request.side_effect = _prepare
session.send.side_effect = responses
- return param_snapshots, auth_snapshots
+ return param_snapshots, auth_snapshots, url_snapshots
def _rows(source_response) -> list[dict[str, Any]]:
return [row for page in source_response.items() for row in page]
-def _source(endpoint: str, manager: mock.MagicMock):
+def _source(endpoint: str, manager: mock.MagicMock, api_version: str = CLOCKODO_API_VERSION_V2):
return clockodo_source(
api_user="[email protected]",
api_key="key123",
@@ -83,6 +94,7 @@ def _source(endpoint: str, manager: mock.MagicMock):
team_id=1,
job_id="j",
resumable_source_manager=manager,
+ api_version=api_version,
)
@@ -100,7 +112,7 @@ class TestFormatZ:
class TestEndpointParams:
@freeze_time("2026-06-29T12:00:00Z")
def test_entries_requires_time_window(self) -> None:
- params = _endpoint_params("entries")
+ params = _endpoint_params("entries", CLOCKODO_ENDPOINTS_V2["entries"])
# Listing entries without a time range is rejected by the API.
assert params["time_since"] == "2000-01-01T00:00:00Z"
# time_until is pushed a year past now to also capture planned (future) entries.
@@ -108,7 +120,7 @@ class TestEndpointParams:
@parameterized.expand([("customers",), ("projects",), ("services",), ("users",)])
def test_non_entries_have_no_time_window(self, endpoint: str) -> None:
- params = _endpoint_params(endpoint)
+ params = _endpoint_params(endpoint, CLOCKODO_ENDPOINTS_V2[endpoint])
assert "time_since" not in params
assert "time_until" not in params
@@ -117,7 +129,7 @@ class TestHeadersAndAuth:
@mock.patch(CLIENT_SESSION_PATCH)
def test_identification_headers_and_api_key_auth(self, MockSession) -> None:
session = MockSession.return_value
- _params, auths = _wire(session, [_response([{"id": 1}], count_pages=1)])
+ _params, auths, _urls = _wire(session, [_response([{"id": 1}], count_pages=1)])
_rows(_source("customers", _make_manager()))
@@ -136,7 +148,7 @@ class TestPagination:
@mock.patch(CLIENT_SESSION_PATCH)
def test_paginated_walks_all_pages_and_saves_state(self, MockSession) -> None:
session = MockSession.return_value
- params, _auths = _wire(
+ params, _auths, _urls = _wire(
session,
[
_response([{"id": 1}, {"id": 2}], count_pages=2),
@@ -187,7 +199,7 @@ class TestPagination:
@mock.patch(CLIENT_SESSION_PATCH)
def test_resumes_from_saved_page(self, MockSession) -> None:
session = MockSession.return_value
- params, _auths = _wire(session, [_response([{"id": 3}], count_pages=2)])
+ params, _auths, _urls = _wire(session, [_response([{"id": 3}], count_pages=2)])
manager = _make_manager(ClockodoResumeConfig(next_page=2))
rows = _rows(_source("customers", manager))
@@ -199,7 +211,7 @@ class TestPagination:
@mock.patch(CLIENT_SESSION_PATCH)
def test_non_paginated_single_fetch(self, MockSession) -> None:
session = MockSession.return_value
- params, _auths = _wire(session, [_response([{"id": 1}, {"id": 2}], data_key="services")])
+ params, _auths, _urls = _wire(session, [_response([{"id": 1}, {"id": 2}], data_key="services")])
manager = _make_manager()
rows = _rows(_source("services", manager))
@@ -214,7 +226,7 @@ class TestPagination:
@freeze_time("2026-06-29T12:00:00Z")
def test_entries_sends_time_window(self, MockSession) -> None:
session = MockSession.return_value
- params, _auths = _wire(session, [_response([{"id": 1}], data_key="entries", count_pages=1)])
+ params, _auths, _urls = _wire(session, [_response([{"id": 1}], data_key="entries", count_pages=1)])
_rows(_source("entries", _make_manager()))
@@ -249,23 +261,87 @@ class TestClockodoSourceResponse:
assert response.primary_keys == ["id"]
+class TestVersionDispatch:
+ @parameterized.expand(
+ [
+ # v2 serves each resource under its own key; the successors return rows under "data".
+ (CLOCKODO_API_VERSION_V2, "customers", "customers", "/api/v2/customers"),
+ (CLOCKODO_API_VERSION_V3, "customers", "data", "/api/v3/customers"),
+ (CLOCKODO_API_VERSION_V3, "projects", "data", "/api/v4/projects"),
+ (CLOCKODO_API_VERSION_V3, "lumpsum_services", "data", "/api/v4/lumpSumServices"),
+ (CLOCKODO_API_VERSION_V3, "teams", "data", "/api/v3/teams"),
+ # surcharges is not decommissioned, so it stays on the v2 path under either pin.
+ (CLOCKODO_API_VERSION_V3, "surcharges", "surcharges", "/api/v2/surcharges"),
+ ]
+ )
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_pin_routes_to_versioned_path_and_envelope(
+ self, api_version: str, endpoint: str, data_key: str, expected_path: str, MockSession
+ ) -> None:
+ session = MockSession.return_value
+ _params, _auths, urls = _wire(session, [_response([{"id": 1}], data_key=data_key, count_pages=1)])
+
+ rows = _rows(_source(endpoint, _make_manager(), api_version=api_version))
+
+ # Wrong path hits a decommissioned endpoint; wrong envelope key yields zero rows.
+ assert [r["id"] for r in rows] == [1]
+ assert expected_path in urls[0]
+
+ def test_every_supported_version_covers_all_tables(self) -> None:
+ # clockodo_source indexes the version map by table name, so a table missing from any
+ # version map would KeyError mid-sync instead of routing to a path.
+ for version in CLOCKODO_SUPPORTED_VERSIONS:
+ assert set(endpoints_for_version(version)) == set(ENDPOINTS)
+
+ def test_unknown_version_raises(self) -> None:
+ with pytest.raises(ValueError):
+ endpoints_for_version("v99")
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_v3_paginates_a_resource_v2_served_in_one_page(self, MockSession) -> None:
+ # v2/users returns the whole collection in one response; v3/users paginates, so a
+ # single-page fetch would silently drop every user past the first page.
+ session = MockSession.return_value
+ params, _auths, _urls = _wire(
+ session,
+ [
+ _response([{"id": 1}], data_key="data", count_pages=2),
+ _response([{"id": 2}], data_key="data", count_pages=2),
+ ],
+ )
+
+ rows = _rows(_source("users", _make_manager(), api_version=CLOCKODO_API_VERSION_V3))
+
+ assert [r["id"] for r in rows] == [1, 2]
+ assert params[0]["page"] == 1
+ assert params[1]["page"] == 2
+
+
class TestValidateCredentials:
@parameterized.expand([("ok", 200, True), ("unauthorized", 401, False), ("forbidden", 403, False)])
@mock.patch(CLOCKODO_SESSION_PATCH)
def test_validate_credentials_status_mapping(self, _name: str, status: int, expected: bool, mock_session) -> None:
mock_session.return_value.get.return_value = mock.MagicMock(status_code=status)
- assert validate_credentials("u", "k") is expected
+ assert validate_credentials("u", "k", CLOCKODO_API_VERSION_V3) is expected
@mock.patch(CLOCKODO_SESSION_PATCH)
def test_validate_credentials_swallows_transport_errors(self, mock_session) -> None:
mock_session.return_value.get.side_effect = Exception("boom")
- assert validate_credentials("u", "k") is False
+ assert validate_credentials("u", "k", CLOCKODO_API_VERSION_V3) is False
+ @parameterized.expand(
+ [
+ (CLOCKODO_API_VERSION_V2, "https://my.clockodo.com/api/v2/users"),
+ # A new source defaults to v3; probing v2/users would fail once it is decommissioned.
+ (CLOCKODO_API_VERSION_V3, "https://my.clockodo.com/api/v3/users"),
+ ]
+ )
@mock.patch(CLOCKODO_SESSION_PATCH)
- def test_probe_sends_credentials(self, mock_session) -> None:
+ def test_probe_targets_version_users_path(self, api_version: str, expected_url: str, mock_session) -> None:
mock_session.return_value.get.return_value = mock.MagicMock(status_code=200)
- validate_credentials("[email protected]", "key123")
- _args, kwargs = mock_session.return_value.get.call_args
+ validate_credentials("[email protected]", "key123", api_version)
+ args, kwargs = mock_session.return_value.get.call_args
+ assert args[0] == expected_url
headers = kwargs["headers"]
assert headers["X-ClockodoApiUser"] == "[email protected]"
assert headers["X-ClockodoApiKey"] == "key123"
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/tests/test_clockodo_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/tests/test_clockodo_source.py
index 9510eed96e50..8e9eb15defd4 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/tests/test_clockodo_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clockodo/tests/test_clockodo_source.py
@@ -76,10 +76,14 @@ class TestClockodoSource:
assert isinstance(manager, ResumableSourceManager)
assert manager._data_class is ClockodoResumeConfig
- def test_source_for_pipeline_plumbs_arguments(self) -> None:
+ @parameterized.expand([("unpinned", None, "v3"), ("legacy_pin", "v2", "v2"), ("new_pin", "v3", "v3")])
+ def test_source_for_pipeline_threads_resolved_api_version(
+ self, _name: str, pin: str | None, expected_version: str
+ ) -> None:
inputs = MagicMock()
inputs.schema_name = "customers"
inputs.logger = MagicMock()
+ inputs.api_version = pin
manager = MagicMock()
with patch(
"products.warehouse_sources.backend.temporal.data_imports.sources.clockodo.source.clockodo_source"
@@ -91,3 +95,5 @@ class TestClockodoSource:
assert kwargs["api_key"] == "secret"
assert kwargs["endpoint"] == "customers"
assert kwargs["resumable_source_manager"] is manager
+ # An unpinned source resolves to the default (v3); a pin is honored verbatim.
+ assert kwargs["api_version"] == expected_version