mirror of
https://github.com/langgenius/dify.git
synced 2026-05-13 08:57:28 +08:00
[autofix.ci] apply automated fixes
This commit is contained in:
parent
daa47c25bb
commit
b95cdabe26
@ -72,9 +72,7 @@ class TestQuotaType:
|
|||||||
patch("services.billing_service.BillingService") as mock_bs,
|
patch("services.billing_service.BillingService") as mock_bs,
|
||||||
):
|
):
|
||||||
mock_cfg.BILLING_ENABLED = True
|
mock_cfg.BILLING_ENABLED = True
|
||||||
mock_bs.quota_reserve.side_effect = QuotaExceededError(
|
mock_bs.quota_reserve.side_effect = QuotaExceededError(feature="trigger", tenant_id="t1", required=1)
|
||||||
feature="trigger", tenant_id="t1", required=1
|
|
||||||
)
|
|
||||||
|
|
||||||
with pytest.raises(QuotaExceededError):
|
with pytest.raises(QuotaExceededError):
|
||||||
QuotaType.TRIGGER.reserve("t1")
|
QuotaType.TRIGGER.reserve("t1")
|
||||||
@ -188,23 +186,17 @@ class TestQuotaType:
|
|||||||
|
|
||||||
def test_get_remaining_normal(self):
|
def test_get_remaining_normal(self):
|
||||||
with patch("services.billing_service.BillingService") as mock_bs:
|
with patch("services.billing_service.BillingService") as mock_bs:
|
||||||
mock_bs.get_tenant_feature_plan_usage_info.return_value = {
|
mock_bs.get_tenant_feature_plan_usage_info.return_value = {"trigger_event": {"limit": 100, "usage": 30}}
|
||||||
"trigger_event": {"limit": 100, "usage": 30}
|
|
||||||
}
|
|
||||||
assert QuotaType.TRIGGER.get_remaining("t1") == 70
|
assert QuotaType.TRIGGER.get_remaining("t1") == 70
|
||||||
|
|
||||||
def test_get_remaining_unlimited(self):
|
def test_get_remaining_unlimited(self):
|
||||||
with patch("services.billing_service.BillingService") as mock_bs:
|
with patch("services.billing_service.BillingService") as mock_bs:
|
||||||
mock_bs.get_tenant_feature_plan_usage_info.return_value = {
|
mock_bs.get_tenant_feature_plan_usage_info.return_value = {"trigger_event": {"limit": -1, "usage": 0}}
|
||||||
"trigger_event": {"limit": -1, "usage": 0}
|
|
||||||
}
|
|
||||||
assert QuotaType.TRIGGER.get_remaining("t1") == -1
|
assert QuotaType.TRIGGER.get_remaining("t1") == -1
|
||||||
|
|
||||||
def test_get_remaining_over_limit_returns_zero(self):
|
def test_get_remaining_over_limit_returns_zero(self):
|
||||||
with patch("services.billing_service.BillingService") as mock_bs:
|
with patch("services.billing_service.BillingService") as mock_bs:
|
||||||
mock_bs.get_tenant_feature_plan_usage_info.return_value = {
|
mock_bs.get_tenant_feature_plan_usage_info.return_value = {"trigger_event": {"limit": 10, "usage": 15}}
|
||||||
"trigger_event": {"limit": 10, "usage": 15}
|
|
||||||
}
|
|
||||||
assert QuotaType.TRIGGER.get_remaining("t1") == 0
|
assert QuotaType.TRIGGER.get_remaining("t1") == 0
|
||||||
|
|
||||||
def test_get_remaining_exception_returns_neg1(self):
|
def test_get_remaining_exception_returns_neg1(self):
|
||||||
@ -224,17 +216,13 @@ class TestQuotaType:
|
|||||||
|
|
||||||
def test_get_remaining_feature_not_in_response(self):
|
def test_get_remaining_feature_not_in_response(self):
|
||||||
with patch("services.billing_service.BillingService") as mock_bs:
|
with patch("services.billing_service.BillingService") as mock_bs:
|
||||||
mock_bs.get_tenant_feature_plan_usage_info.return_value = {
|
mock_bs.get_tenant_feature_plan_usage_info.return_value = {"other_feature": {"limit": 100, "usage": 0}}
|
||||||
"other_feature": {"limit": 100, "usage": 0}
|
|
||||||
}
|
|
||||||
remaining = QuotaType.TRIGGER.get_remaining("t1")
|
remaining = QuotaType.TRIGGER.get_remaining("t1")
|
||||||
assert remaining == 0
|
assert remaining == 0
|
||||||
|
|
||||||
def test_get_remaining_non_dict_feature_info(self):
|
def test_get_remaining_non_dict_feature_info(self):
|
||||||
with patch("services.billing_service.BillingService") as mock_bs:
|
with patch("services.billing_service.BillingService") as mock_bs:
|
||||||
mock_bs.get_tenant_feature_plan_usage_info.return_value = {
|
mock_bs.get_tenant_feature_plan_usage_info.return_value = {"trigger_event": "not_a_dict"}
|
||||||
"trigger_event": "not_a_dict"
|
|
||||||
}
|
|
||||||
assert QuotaType.TRIGGER.get_remaining("t1") == 0
|
assert QuotaType.TRIGGER.get_remaining("t1") == 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -517,9 +517,7 @@ class TestBillingServiceQuotaOperations:
|
|||||||
expected = {"reservation_id": "rid-1", "available": 99, "reserved": 1}
|
expected = {"reservation_id": "rid-1", "available": 99, "reserved": 1}
|
||||||
mock_send_request.return_value = expected
|
mock_send_request.return_value = expected
|
||||||
|
|
||||||
result = BillingService.quota_reserve(
|
result = BillingService.quota_reserve(tenant_id="t1", feature_key="trigger_event", request_id="req-1", amount=1)
|
||||||
tenant_id="t1", feature_key="trigger_event", request_id="req-1", amount=1
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result == expected
|
assert result == expected
|
||||||
mock_send_request.assert_called_once_with(
|
mock_send_request.assert_called_once_with(
|
||||||
@ -574,9 +572,7 @@ class TestBillingServiceQuotaOperations:
|
|||||||
expected = {"available": 100, "reserved": 0, "released": 1}
|
expected = {"available": 100, "reserved": 0, "released": 1}
|
||||||
mock_send_request.return_value = expected
|
mock_send_request.return_value = expected
|
||||||
|
|
||||||
result = BillingService.quota_release(
|
result = BillingService.quota_release(tenant_id="t1", feature_key="trigger_event", reservation_id="rid-1")
|
||||||
tenant_id="t1", feature_key="trigger_event", reservation_id="rid-1"
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result == expected
|
assert result == expected
|
||||||
mock_send_request.assert_called_once_with(
|
mock_send_request.assert_called_once_with(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user