mirror of
https://github.com/langgenius/dify.git
synced 2026-06-23 12:31:13 +08:00
fix: bound OperationService billing requests (#37425)
Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com>
This commit is contained in:
parent
762e7f7e8a
commit
47ee9f7435
@ -3,6 +3,8 @@ from typing import TypedDict
|
||||
|
||||
import httpx
|
||||
|
||||
OPERATION_REQUEST_TIMEOUT = httpx.Timeout(10.0, connect=3.0)
|
||||
|
||||
|
||||
class UtmInfo(TypedDict, total=False):
|
||||
"""Expected shape of the utm_info dict passed to record_utm.
|
||||
@ -26,7 +28,9 @@ class OperationService:
|
||||
headers = {"Content-Type": "application/json", "Billing-Api-Secret-Key": cls.secret_key}
|
||||
|
||||
url = f"{cls.base_url}{endpoint}"
|
||||
response = httpx.request(method, url, json=json, params=params, headers=headers)
|
||||
response = httpx.request(
|
||||
method, url, json=json, params=params, headers=headers, timeout=OPERATION_REQUEST_TIMEOUT
|
||||
)
|
||||
|
||||
return response.json()
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ from unittest.mock import MagicMock, patch
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from services.operation_service import OperationService
|
||||
from services.operation_service import OPERATION_REQUEST_TIMEOUT, OperationService
|
||||
|
||||
|
||||
class TestOperationService:
|
||||
@ -44,6 +44,7 @@ class TestOperationService:
|
||||
assert kwargs["json"] == json_data
|
||||
assert kwargs["headers"]["Billing-Api-Secret-Key"] == "s3cr3t"
|
||||
assert kwargs["headers"]["Content-Type"] == "application/json"
|
||||
assert kwargs["timeout"] == OPERATION_REQUEST_TIMEOUT
|
||||
|
||||
@patch("httpx.request")
|
||||
def test_should_propagate_httpx_error_when__send_request_raises(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user