Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lago_python_client/mixins.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from typing import Any, Generic, Optional, Type, TypeVar, Union

import httpx
Expand Down Expand Up @@ -157,9 +158,14 @@ def find_all(
self: _ClientMixin[_M],
resource_id: str,
options: QueryPairs = None,
timeout: Optional[httpx.Timeout] = DEFAULT_TIMEOUT,
*,
timetour: Optional[httpx.Timeout] = None,
) -> Mapping[str, Any]:
"""Execute `find_all` child command."""
if timetour is not None:
warnings.warn("timetour is deprecated, use timeout instead", DeprecationWarning, stacklevel=2)
timeout = timetour
# Send request and save response
if options is None:
options = {}
Expand All @@ -174,6 +180,7 @@ def find_all(
query_pairs=options,
),
headers=make_headers(api_key=self.api_key),
timeout=timeout,
rate_limit_retry_config=self.rate_limit_retry_config,
)

Expand Down
38 changes: 38 additions & 0 deletions tests/test_find_all_children.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import httpx
import pytest
from pytest_httpx import HTTPXMock

from lago_python_client.client import Client
from lago_python_client.mixins import DEFAULT_TIMEOUT


@pytest.mark.parametrize(
Expand Down Expand Up @@ -38,3 +40,39 @@ def test_find_all_children_sends_authentication_headers(
assert request.headers["Authorization"] == "Bearer test-api-key"
assert request.headers["Content-Type"] == "application/json"
assert response == response_data


def mock_invoices_response(httpx_mock: HTTPXMock):
httpx_mock.add_response(
method="GET",
url="https://api.getlago.com/api/v1/customers/parent-id/invoices",
json={"invoices": [], "meta": {"current_page": 1}},
)


def test_find_all_children_uses_default_timeout(httpx_mock: HTTPXMock):
client = Client(api_key="test-api-key")
mock_invoices_response(httpx_mock)

client.customer_invoices.find_all(resource_id="parent-id")

assert httpx_mock.get_request().extensions["timeout"] == DEFAULT_TIMEOUT.as_dict()


def test_find_all_children_with_custom_timeout(httpx_mock: HTTPXMock):
client = Client(api_key="test-api-key")
mock_invoices_response(httpx_mock)

client.customer_invoices.find_all(resource_id="parent-id", timeout=httpx.Timeout(30.0))

assert httpx_mock.get_request().extensions["timeout"] == httpx.Timeout(30.0).as_dict()


def test_find_all_children_with_deprecated_timetour(httpx_mock: HTTPXMock):
client = Client(api_key="test-api-key")
mock_invoices_response(httpx_mock)

with pytest.warns(DeprecationWarning, match="timetour is deprecated"):
client.customer_invoices.find_all(resource_id="parent-id", timetour=httpx.Timeout(30.0))

assert httpx_mock.get_request().extensions["timeout"] == httpx.Timeout(30.0).as_dict()
Loading