Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix(api): preserve explicit falsy response payloads

Rudy Celekli4a1fd3cf83d9
diff --git a/app/utils/utils.py b/app/utils/utils.py
index 7a672760..9184e78b 100644
--- a/app/utils/utils.py
+++ b/app/utils/utils.py
@@ -19,7 +19,7 @@ def get_response(status: int, data: Any = None, message: str = ""):
obj = {
"status": status,
}
- if data:
+ if data is not None:
obj["data"] = data
if message:
obj["message"] = message
diff --git a/test/services/test_response_payloads.py b/test/services/test_response_payloads.py
new file mode 100644
index 00000000..4a765daa
--- /dev/null
+++ b/test/services/test_response_payloads.py
@@ -0,0 +1,19 @@
+"""The shared API envelope must preserve explicit data values."""
+
+import json
+
+import pytest
+
+from app.utils import utils
+
+
[email protected]("data", [False, 0, "", [], {}])
+def test_response_preserves_explicit_falsy_payloads(data):
+ response = utils.get_response(200, data=data)
+ serialized = json.loads(json.dumps(response))
+ assert "data" in serialized
+ assert serialized["data"] == data
+
+
+def test_response_without_data_retains_status_only_contract():
+ assert utils.get_response(200) == {"status": 200}