feat: add math engine and puzzle services

This commit is contained in:
2026-08-09 01:52:20 +08:00
parent 6bcff55c4f
commit b99a22fc06
21 changed files with 1011 additions and 1 deletions
+25
View File
@@ -0,0 +1,25 @@
import pytest
@pytest.mark.django_db
def test_calculator_api_公开访问并返回精确值(client):
response = client.post(
"/api/v1/toolbox/calculate/",
{"operation": "factor", "expression": "x^2 - 1"},
content_type="application/json",
)
assert response.status_code == 200
assert response.json()["result"]["exact"] == "(x - 1)*(x + 1)"
@pytest.mark.django_db
def test_calculator_api_危险表达式返回四百(client):
response = client.post(
"/api/v1/toolbox/calculate/",
{"operation": "calculate", "expression": "__import__('os').system('id')"},
content_type="application/json",
)
assert response.status_code == 400
assert "error" in response.json()