feat: add math engine and puzzle services
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user