26 lines
741 B
Python
26 lines
741 B
Python
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()
|