Skip to content

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

feat(warehouse-sources): add revolut merchant disputes, payouts and subscription tables (#127360)

Tom Owersb626e8a3835e
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index c75c14cc342f..38aea8562ae6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -10300,10 +10300,10 @@ Today (5): `customers`, `orders`, `payments`, `subscription_plans`, `subscriptio
Diffed against: <https://developer.revolut.com/docs/api/merchant.yaml>
-- [ ] `Payouts (GET /api/payouts)` — reconcile merchant receipts with transferred funds, currencies, and payout status (high)
-- [ ] `Disputes (GET /api/disputes)` — measure chargebacks, disputed amounts, and dispute outcomes linked to payments (high)
-- [ ] `Subscription cycles (GET /api/subscriptions/{subscription_id}/cycles)` — analyze recurring billing periods and connect subscription activity with collected revenue (high)
-- [ ] `Subscription usages (GET /api/subscription-usages)` — measure consumption recorded for usage-based subscriptions and their billing cycles (high)
+- [x] `Payouts (GET /api/payouts)` — reconcile merchant receipts with transferred funds, currencies, and payout status (high) → `payouts` (full refresh)
+- [x] `Disputes (GET /api/disputes)` — measure chargebacks, disputed amounts, and dispute outcomes linked to payments (high) → `disputes` (full refresh, Production only)
+- [x] `Subscription cycles (GET /api/subscriptions/{subscription_id}/cycles)` — analyze recurring billing periods and connect subscription activity with collected revenue (high) → `subscription_cycles` (full refresh, fan-out over `subscriptions`)
+- [x] `Subscription usages (GET /api/subscription-usages)` — measure consumption recorded for usage-based subscriptions and their billing cycles (high) → `subscription_usages` (full refresh)
- [ ] `Customer payment methods (GET /api/customers/{customer_id}/payment-methods)` — analyze stored payment method coverage across customers with recurring subscriptions (medium)
Note: The current official Merchant OpenAPI YAML and Legacy YAML were fetched with curl and parsed to enumerate GET operations. The source imports legacy order lists and requests payments for each order; billing cycles and saved methods need similar parent requests. Disputes are available only in production, and saved methods differ from payment transaction snapshots. Refund writes, webhooks, payment intents, and terminal discovery are excluded.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/canonical_descriptions.py
index bb79cea3252e..482346f0671e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/canonical_descriptions.py
@@ -61,4 +61,67 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"state": "Current state of the subscription plan.",
},
},
+ "subscription_cycles": {
+ "description": "Billing cycles for each subscription, including trial and finished cycles.",
+ "docs_url": "https://developer.revolut.com/docs/api/merchant#retrieve-subscription-cycle-list",
+ "columns": {
+ "id": "Unique identifier for the subscription cycle.",
+ "subscription_id": "Identifier of the subscription this cycle belongs to.",
+ "plan_variation_id": "Identifier of the plan variation billed in this cycle.",
+ "plan_variation_phase_id": "Identifier of the plan variation phase billed in this cycle.",
+ "number": "Sequence number of the cycle within the subscription.",
+ "previous_cycle_id": "Identifier of the cycle before this one.",
+ "state": "Current state of the cycle: pending, active, or finished.",
+ "start_date": "Time the cycle starts.",
+ "end_date": "Time the cycle ends.",
+ "usage_cutoff_date": "Last time that usage can be recorded for this cycle.",
+ "order_id": "Identifier of the order created to bill this cycle.",
+ "post_billing_order_id": "Identifier of the order created to bill usage after the cycle ends.",
+ "trial": "Whether the cycle is a trial period.",
+ },
+ },
+ "subscription_usages": {
+ "description": "Usage records for usage-based subscription items.",
+ "docs_url": "https://developer.revolut.com/docs/api/merchant#retrieve-subscription-usage-list",
+ "columns": {
+ "id": "Unique identifier for the usage record.",
+ "subscription_id": "Identifier of the subscription the usage belongs to.",
+ "subscription_cycle_id": "Identifier of the subscription cycle the usage is billed in.",
+ "subscription_item_code": "Code of the subscription item the usage is recorded for.",
+ "usage_date": "Time the usage happened.",
+ "quantity": "Quantity of usage recorded.",
+ "metadata": "Custom key-value data attached to the usage record.",
+ "created_at": "Time the usage record was created.",
+ "updated_at": "Time the usage record was last updated.",
+ },
+ },
+ "payouts": {
+ "description": "Payouts of funds from the Merchant account.",
+ "docs_url": "https://developer.revolut.com/docs/api/merchant#retrieve-payout-list",
+ "columns": {
+ "id": "Unique identifier for the payout.",
+ "state": "Current state of the payout: processing, completed, or failed.",
+ "created_at": "Time the payout was created.",
+ "destination_type": "Type of destination the funds were paid out to.",
+ "amount": "Payout amount in minor currency units. Can be empty while the payout is processing.",
+ "currency": "ISO 4217 currency code for the payout amount.",
+ },
+ },
+ "disputes": {
+ "description": "Disputes raised against payments. Revolut provides disputes only in the Production environment.",
+ "docs_url": "https://developer.revolut.com/docs/api/merchant#retrieve-dispute-list",
+ "columns": {
+ "id": "Unique identifier for the dispute.",
+ "state": "Current state of the dispute: needs_response, under_review, won, or lost.",
+ "substate": "Current stage of the dispute process, such as representment or arbitration.",
+ "created_at": "Time the dispute was created.",
+ "updated_at": "Time the dispute was last updated.",
+ "response_due_date": "Last time the merchant can respond before the dispute is lost.",
+ "reason_code": "Reason code of the dispute.",
+ "reason_description": "Description of the dispute reason.",
+ "amount": "Disputed amount in minor currency units.",
+ "currency": "ISO 4217 currency code for the disputed amount.",
+ "payment": "The disputed payment, including its ID, order ID, amount, and payment method.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/revolut_merchant.py b/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/revolut_merchant.py
index 309e3e224589..0031309905a3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/revolut_merchant.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/revolut_merchant.py
@@ -1,7 +1,8 @@
-from typing import Any
+from datetime import UTC, datetime
+from typing import Any, Optional
from urllib.parse import quote
-from requests import HTTPError
+from requests import HTTPError, Request, Response
from posthog.dataclasses import frozen
@@ -16,6 +17,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
rename_parent_fields,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
+ BasePaginator,
SinglePagePaginator,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (
@@ -27,6 +29,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.sch
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
from products.warehouse_sources.backend.temporal.data_imports.sources.revolut_merchant.settings import (
BASE_URLS,
+ CREATED_DATE_PAGE_SIZE,
ENDPOINTS,
)
@@ -37,6 +40,7 @@ PERMISSION_ERROR = (
"Your Secret API key cannot access this Revolut Merchant table. Check your Merchant account permissions."
)
VERSION_ERROR = "Revolut Merchant rejected the request. Check the selected API version and reconnect."
+SANDBOX_DISPUTES_ERROR = "Revolut Merchant only provides disputes in the Production environment."
@frozen
@@ -44,6 +48,77 @@ class RevolutMerchantResumeConfig:
paginator_state: dict[str, Any]
+class CreatedDatePaginator(BasePaginator):
+ """Pages by `from_created_date` or `to_created_date`, picked from the order of the first full page.
+
+ The API does not document the sort order, and both bounds include the boundary timestamp. The next
+ page repeats the rows at the boundary, so the paginator drops the IDs it already returned there.
+ """
+
+ def __init__(self, limit: int) -> None:
+ super().__init__()
+ self.limit = limit
+ self._param: str | None = None
+ self._value: str | None = None
+ self._boundary_ids: set[str] = set()
+
+ def init_request(self, request: Request) -> None:
+ self.update_request(request)
+
+ def update_state(self, response: Response, data: Optional[list[Any]] = None) -> None:
+ rows = data if data is not None else []
+ full_page = len(rows) >= self.limit
+ bound = _parse_created_at_value(self._value) if self._value is not None else None
+ # The client yields this same list after update_state, so filtering in place drops the repeats.
+ rows[:] = [
+ row for row in rows if not (_parse_created_at(row) == bound and str(row.get("id")) in self._boundary_ids)
+ ]
+ if not full_page:
+ self._has_next_page = False
+ return
+ if not rows:
+ raise ValueError("Revolut Merchant returned only rows from the previous page.")
+ first = _parse_created_at(rows[0])
+ last = _parse_created_at(rows[-1])
+ if first == last and self._param is None:
+ raise ValueError("Revolut Merchant returned a full page with one created date.")
+ param = self._param if first == last else ("to_created_date" if first > last else "from_created_date")
+ if self._param is not None and param != self._param:
+ raise ValueError("Revolut Merchant changed the sort order between pages.")
+ if bound is not None and (last >= bound if param == "to_created_date" else last <= bound):
+ raise ValueError("Revolut Merchant created date pagination is not advancing.")
+ self._param = param
+ self._value = last.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
+ self._boundary_ids = {str(row.get("id")) for row in rows if _parse_created_at(row) == last}
+ self._has_next_page = True
+
+ def update_request(self, request: Request) -> None:
+ if self._param is not None and self._value is not None:
+ if request.params is None:
+ request.params = {}
+ request.params[self._param] = self._value
+
+ def get_resume_state(self) -> Optional[dict[str, Any]]:
+ if self._has_next_page and self._param is not None and self._value is not None:
+ return {"param": self._param, "value": self._value, "boundary_ids": sorted(self._boundary_ids)}
+ return None
+
+ def set_resume_state(self, state: dict[str, Any]) -> None:
+ if state.get("param") in ("from_created_date", "to_created_date") and state.get("value"):
+ self._param = state["param"]
+ self._value = state["value"]
+ self._boundary_ids = set(state.get("boundary_ids") or [])
+ self._has_next_page = True
+
+
+def _parse_created_at(row: dict[str, Any]) -> datetime:
+ return _parse_created_at_value(row["created_at"])
+
+
+def _parse_created_at_value(value: str) -> datetime:
+ return datetime.fromisoformat(value).astimezone(UTC)
+
+
def client_config(api_key: str, environment: str, api_version: str) -> ClientConfig:
if environment not in BASE_URLS:
raise ValueError("Select Production or Sandbox for the Revolut Merchant environment.")
@@ -66,9 +141,11 @@ def get_resource(name: str) -> EndpointResource:
"write_disposition": "replace",
"endpoint": endpoint.endpoint,
}
- if endpoint.parent:
+ if endpoint.created_date_pagination:
+ resource["endpoint"] = {**endpoint.endpoint, "paginator": CreatedDatePaginator(CREATED_DATE_PAGE_SIZE)}
+ if endpoint.parent and endpoint.parent_id_column:
resource["include_from_parent"] = ["id"]
- resource["data_map"] = rename_parent_fields(endpoint.parent, {"id": "order_id"})
+ resource["data_map"] = rename_parent_fields(endpoint.parent, {"id": endpoint.parent_id_column})
return resource
@@ -132,6 +209,8 @@ def validate_credentials(
) -> tuple[bool, str | None]:
if not api_key or any(not 33 <= ord(char) <= 126 for char in api_key):
return False, "Enter a Revolut Merchant Secret API key without spaces or unsupported characters."
+ if schema_name == "disputes" and environment == "sandbox":
+ return False, SANDBOX_DISPUTES_ERROR
selected_endpoint = schema_for_resource(ENDPOINTS, schema_name or "customers")
endpoint = ENDPOINTS[selected_endpoint.parent] if selected_endpoint.parent else selected_endpoint
path = endpoint.endpoint.get("path")
@@ -157,10 +236,19 @@ def validate_credentials(
)
)
if selected_endpoint.parent and page:
+ child = selected_endpoint.endpoint
+ child_params = child.get("params") or {}
+ resolve_param = next(
+ name
+ for name, value in child_params.items()
+ if isinstance(value, dict) and value.get("type") == "resolve"
+ )
next(
client.paginate(
- path=f"/orders/{quote(str(page[0]['id']), safe='')}/payments",
+ path=str(child.get("path")).format(**{resolve_param: quote(str(page[0]["id"]), safe="")}),
+ params={"limit": 1} if "limit" in child_params else None,
paginator=SinglePagePaginator(),
+ data_selector=child.get("data_selector"),
data_selector_required=True,
)
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/settings.py
index 4e23d8708608..adc75e3ff18d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/settings.py
@@ -7,6 +7,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.typ
from products.warehouse_sources.backend.types import IncrementalField
API_VERSION = "2026-08-17"
+CREATED_DATE_PAGE_SIZE = 500
BASE_URLS = {
"production": "https://merchant.revolut.com/api",
"sandbox": "https://sandbox-merchant.revolut.com/api",
@@ -20,6 +21,8 @@ class RevolutMerchantEndpoint:
partition_key: str = "created_at"
sort_mode: SortMode | None = None
parent: str | None = None
+ parent_id_column: str | None = None
+ created_date_pagination: bool = False
incremental_fields: list[IncrementalField] = field(default_factory=list)
@@ -46,6 +49,7 @@ ENDPOINTS: dict[str, RevolutMerchantEndpoint] = {
},
primary_keys=["order_id", "id"],
parent="orders",
+ parent_id_column="order_id",
),
"customers": RevolutMerchantEndpoint(
endpoint={
@@ -74,6 +78,49 @@ ENDPOINTS: dict[str, RevolutMerchantEndpoint] = {
"paginator": {"type": "cursor", "cursor_path": "next_page_token", "cursor_param": "page_token"},
},
),
+ "subscription_cycles": RevolutMerchantEndpoint(
+ endpoint={
+ "path": "/subscriptions/{subscription_id}/cycles",
+ "params": {
+ "subscription_id": {"type": "resolve", "resource": "subscriptions", "field": "id"},
+ "limit": 500,
+ },
+ "data_selector": "cycles",
+ "data_selector_required": True,
+ "paginator": {"type": "cursor", "cursor_path": "next_page_token", "cursor_param": "page_token"},
+ },
+ primary_keys=["subscription_id", "id"],
+ partition_key="start_date",
+ parent="subscriptions",
+ parent_id_column="subscription_id",
+ ),
+ "subscription_usages": RevolutMerchantEndpoint(
+ endpoint={
+ "path": "/subscription-usages",
+ "params": {"limit": 500},
+ "data_selector": "subscription_usages",
+ "data_selector_required": True,
+ "paginator": {"type": "cursor", "cursor_path": "next_page_token", "cursor_param": "page_token"},
+ },
+ ),
+ "payouts": RevolutMerchantEndpoint(
+ endpoint={
+ "path": "/payouts",
+ "params": {"limit": CREATED_DATE_PAGE_SIZE},
+ "data_selector": None,
+ "data_selector_required": True,
+ },
+ created_date_pagination=True,
+ ),
+ "disputes": RevolutMerchantEndpoint(
+ endpoint={
+ "path": "/disputes",
+ "params": {"limit": CREATED_DATE_PAGE_SIZE},
+ "data_selector": None,
+ "data_selector_required": True,
+ },
+ created_date_pagination=True,
+ ),
}
INCREMENTAL_FIELDS = {name: endpoint.incremental_fields for name, endpoint in ENDPOINTS.items()}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/tests/test_revolut_merchant.py b/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/tests/test_revolut_merchant.py
index 288f5eb9213c..0ed49ce2c64e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/tests/test_revolut_merchant.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/revolut_merchant/tests/test_revolut_merchant.py
@@ -1,3 +1,5 @@
+from datetime import UTC, datetime, timedelta
+
import pytest
import requests_mock
@@ -14,7 +16,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.revolut_me
RevolutMerchantResumeConfig,
validate_credentials,
)
-from products.warehouse_sources.backend.temporal.data_imports.sources.revolut_merchant.settings import API_VERSION
+from products.warehouse_sources.backend.temporal.data_imports.sources.revolut_merchant.settings import (
+ API_VERSION,
+ CREATED_DATE_PAGE_SIZE,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.revolut_merchant.source import (
RevolutMerchantSource,
)
@@ -67,7 +72,90 @@ def test_payments_keep_parent_keys_and_resume_completed_orders(resume: bool) ->
]
[email protected]("endpoint", ["customers", "orders"])
+def created_rows(prefix: str, start: datetime, count: int, step: timedelta) -> list[dict[str, str]]:
+ return [{"id": f"{prefix}-{i}", "created_at": (start + step * i).isoformat()} for i in range(count)]
+
+
[email protected]("endpoint", ["disputes", "payouts"])
+ "step,param", [(timedelta(minutes=-1), "to_created_date"), (timedelta(minutes=1), "from_created_date")]
+)
[email protected]("resume", [False, True])
+def test_created_date_pages_keep_rows_that_share_the_boundary(
+ endpoint: str, step: timedelta, param: str, resume: bool
+) -> None:
+ boundary = datetime(2026, 1, 1, tzinfo=UTC)
+ first_page = [
+ *created_rows("a", boundary - step * (CREATED_DATE_PAGE_SIZE - 1), CREATED_DATE_PAGE_SIZE - 1, step),
+ {"id": "boundary-1", "created_at": boundary.isoformat()},
+ ]
+ last_page = [
+ {"id": "boundary-1", "created_at": boundary.isoformat()},
+ {"id": "boundary-2", "created_at": boundary.isoformat()},
+ {"id": "after", "created_at": (boundary + step).isoformat()},
+ ]
+ bound = "2026-01-01T00:00:00.000000Z"
+ result = run(
+ endpoint,
+ route(
+ {
+ f"/{endpoint}": [
+ ScriptedResponse(json=page) for page in ([last_page] if resume else [first_page, last_page])
+ ]
+ }
+ ),
+ RevolutMerchantResumeConfig(paginator_state={"param": param, "value": bound, "boundary_ids": ["boundary-1"]})
+ if resume
+ else None,
+ )
+
+ assert result.raised is None
+ assert result.rows == (last_page[1:] if resume else first_page + last_page[1:])
+ assert result.requests[-1].query == {"limit": ("500",), param: (bound,)}
+ assert len(result.requests) == (1 if resume else 2)
+
+
+def test_created_date_pagination_fails_when_the_window_does_not_move() -> None:
+ page = created_rows("a", datetime(2026, 1, 1, tzinfo=UTC), CREATED_DATE_PAGE_SIZE, timedelta(minutes=-1))
+ result = run("disputes", route({"/disputes": [ScriptedResponse(json=page), ScriptedResponse(json=page)]}))
+
+ assert isinstance(result.raised, ValueError)
+ assert len(result.requests) == 2
+
+
+def test_subscription_cycles_page_each_subscription_and_keep_parent_keys() -> None:
+ result = run(
+ "subscription_cycles",
+ route(
+ {
+ "/subscriptions": [
+ ScriptedResponse(
+ json={"subscriptions": [{"id": "sub-a"}, {"id": "sub-b"}], "next_page_token": None}
+ )
+ ],
+ "/subscriptions/sub-a/cycles": [
+ ScriptedResponse(
+ json={"cycles": [{"id": "cycle-1", "subscription_id": "sub-a"}], "next_page_token": "t"}
+ ),
+ ScriptedResponse(json={"cycles": [{"id": "cycle-2", "subscription_id": "sub-a"}]}),
+ ],
+ "/subscriptions/sub-b/cycles": [
+ ScriptedResponse(json={"cycles": [{"id": "cycle-1", "subscription_id": "sub-b"}]}),
+ ],
+ }
+ ),
+ )
+
+ assert result.raised is None
+ assert result.response is not None
+ assert result.response.primary_keys is not None
+ keys = [tuple(row[key] for key in result.response.primary_keys) for row in result.rows]
+ assert keys == [("sub-a", "cycle-1"), ("sub-a", "cycle-2"), ("sub-b", "cycle-1")]
+ cycle_queries = [request.query for request in result.requests if request.path.endswith("/cycles")]
+ assert cycle_queries == [{"limit": ("500",)}, {"limit": ("500",), "page_token": ("t",)}, {"limit": ("500",)}]
+
+
[email protected]("endpoint", ["customers", "orders", "payouts", "subscription_usages", "disputes"])
def test_changed_response_shape_fails_instead_of_replacing_with_empty_table(endpoint: str) -> None:
result = run(endpoint, [ScriptedResponse(json={"unexpected": []})])
@@ -97,24 +185,57 @@ def test_credential_probe_status_mapping(
assert requests_mock.call_count == 1
[email protected]("empty_orders,status,valid", [(True, 200, True), (False, 200, True), (False, 403, False)])
-def test_payment_permission_probe_uses_an_existing_order(
- requests_mock: requests_mock.Mocker, empty_orders: bool, status: int, valid: bool
+ "schema_name,parent_path,parent_page,child_path,child_page",
+ [
+ ("payments", "/1.0/orders", [{"id": "order-a"}], "/orders/order-a/payments", []),
+ (
+ "subscription_cycles",
+ "/subscriptions",
+ {"subscriptions": [{"id": "sub-a"}]},
+ "/subscriptions/sub-a/cycles",
+ {"cycles": []},
+ ),
+ ],
+)
[email protected]("empty_parent,status,valid", [(True, 200, True), (False, 200, True), (False, 403, False)])
+def test_child_permission_probe_uses_an_existing_parent(
+ requests_mock: requests_mock.Mocker,
+ schema_name: str,
+ parent_path: str,
+ parent_page: object,
+ child_path: str,
+ child_page: object,
+ empty_parent: bool,
+ status: int,
+ valid: bool,
) -> None:
- requests_mock.get(f"{BASE_URL}/1.0/orders", json=[] if empty_orders else [{"id": "order-a"}])
- child = requests_mock.get(f"{BASE_URL}/orders/order-a/payments", status_code=status, json=[])
- result, error = validate_credentials("test-secret-key", "production", API_VERSION, "payments")
+ empty_page = [] if isinstance(parent_page, list) else {"subscriptions": []}
+ requests_mock.get(f"{BASE_URL}{parent_path}", json=empty_page if empty_parent else parent_page)
+ child = requests_mock.get(f"{BASE_URL}{child_path}", status_code=status, json=child_page)
+ result, error = validate_credentials("test-secret-key", "production", API_VERSION, schema_name)
assert result is valid
- assert child.call_count == (0 if empty_orders else 1)
+ assert child.call_count == (0 if empty_parent else 1)
if not valid:
assert error and "permissions" in error
[email protected]("api_key", ["", "test key", "test\nkey", "test\u200bkey"])
-def test_invalid_header_key_is_rejected_without_http(requests_mock: requests_mock.Mocker, api_key: str) -> None:
- valid, error = validate_credentials(api_key, "production", API_VERSION)
+ "api_key,environment,schema_name,message",
+ [
+ ("", "production", None, "Secret API key"),
+ ("test key", "production", None, "Secret API key"),
+ ("test\nkey", "production", None, "Secret API key"),
+ ("test\u200bkey", "production", None, "Secret API key"),
+ ("test-secret-key", "sandbox", "disputes", "Production environment"),
+ ],
+)
+def test_unusable_setup_is_rejected_without_http(
+ requests_mock: requests_mock.Mocker, api_key: str, environment: str, schema_name: str | None, message: str
+) -> None:
+ valid, error = validate_credentials(api_key, environment, API_VERSION, schema_name)
assert not valid
- assert error and "Secret API key" in error
+ assert error and message in error
assert requests_mock.call_count == 0