e113374682
app.py:
侧边栏:会话管理(创建/切换/删除)、快捷操作(预览/撤销/重置)、
配置信息、JRXML下载
主区域:多轮聊天、8种意图差异化展示(JRXML代码/咨询回答/
错误解释/成功提示)
URL参数:?session_id= 会话分享
tests/:
test_validation.py: 验证服务6个单元测试(健康检查/空内容/
无效XML/缺少尺寸/有效JRXML/字段引用)
test_agent.py: 5个集成验收场景(简单生成/自动修正/
多轮修改/上下文感知修改/最大重试处理)
106 lines
4.1 KiB
Python
106 lines
4.1 KiB
Python
"""JRXML 验证服务的单元测试。"""
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from validation_service.main import app
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
class TestValidationService:
|
|
def test_health_endpoint(self):
|
|
resp = client.get("/health")
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["status"] == "ok"
|
|
|
|
def test_empty_jrxml(self):
|
|
resp = client.post("/validate", json={"jrxml": ""})
|
|
assert resp.status_code == 200
|
|
assert resp.json()["valid"] is False
|
|
assert "空" in resp.json()["error"]
|
|
|
|
def test_invalid_xml(self):
|
|
resp = client.post("/validate", json={"jrxml": "<not>xml<<<"})
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["valid"] is False
|
|
|
|
def test_missing_page_dimensions(self):
|
|
jrxml = """<?xml version="1.0" encoding="UTF-8"?>
|
|
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports"
|
|
name="TestReport" columnWidth="555"
|
|
leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
|
|
<queryString><![CDATA[SELECT * FROM test]]></queryString>
|
|
<field name="col1" class="java.lang.String"/>
|
|
<title><band height="30"/></title>
|
|
<detail>
|
|
<band height="20">
|
|
<textField>
|
|
<reportElement x="0" y="0" width="100" height="20"/>
|
|
<textFieldExpression><![CDATA[$F{col1}]]></textFieldExpression>
|
|
</textField>
|
|
</band>
|
|
</detail>
|
|
</jasperReport>"""
|
|
resp = client.post("/validate", json={"jrxml": jrxml})
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["valid"] is False
|
|
assert "pageWidth" in data["error"]
|
|
|
|
def test_valid_jrxml(self):
|
|
jrxml = """<?xml version="1.0" encoding="UTF-8"?>
|
|
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports"
|
|
name="ValidReport" pageWidth="595" pageHeight="842" columnWidth="555"
|
|
leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
|
|
<queryString><![CDATA[SELECT emp_id, emp_name FROM employees]]></queryString>
|
|
<field name="emp_id" class="java.lang.Integer"/>
|
|
<field name="emp_name" class="java.lang.String"/>
|
|
<title><band height="30">
|
|
<staticText>
|
|
<reportElement x="0" y="0" width="555" height="30"/>
|
|
<text><![CDATA[Report Title]]></text>
|
|
</staticText>
|
|
</band></title>
|
|
<detail>
|
|
<band height="20">
|
|
<textField>
|
|
<reportElement x="0" y="0" width="100" height="20"/>
|
|
<textFieldExpression><![CDATA[$F{emp_id}]]></textFieldExpression>
|
|
</textField>
|
|
<textField>
|
|
<reportElement x="110" y="0" width="200" height="20"/>
|
|
<textFieldExpression><![CDATA[$F{emp_name}]]></textFieldExpression>
|
|
</textField>
|
|
</band>
|
|
</detail>
|
|
</jasperReport>"""
|
|
resp = client.post("/validate", json={"jrxml": jrxml})
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["valid"] is True, f"验证应该通过,实际错误: {data.get('error')}"
|
|
|
|
def test_missing_field_declaration(self):
|
|
jrxml = """<?xml version="1.0" encoding="UTF-8"?>
|
|
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports"
|
|
name="BadReport" pageWidth="595" pageHeight="842" columnWidth="555"
|
|
leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
|
|
<queryString><![CDATA[SELECT id FROM t]]></queryString>
|
|
<field name="id" class="java.lang.Integer"/>
|
|
<detail>
|
|
<band height="20">
|
|
<textField>
|
|
<reportElement x="0" y="0" width="100" height="20"/>
|
|
<textFieldExpression><![CDATA[$F{missing_field}]]></textFieldExpression>
|
|
</textField>
|
|
</band>
|
|
</detail>
|
|
</jasperReport>"""
|
|
resp = client.post("/validate", json={"jrxml": jrxml})
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["valid"] is False
|
|
assert "missing_field" in data["error"]
|