Files
DjangoAdmin_Tornado_AntdVue/tests/integration/test_api.py
T
2026-09-16 12:00:58 +08:00

35 lines
969 B
Python

"""API 集成测试。"""
import json
import pytest
from tornado.testing import AsyncHTTPTestCase
# 使用 src 包路径导入工厂,避免与根目录入口 app.py 同名冲突
from src.app import create_app
pytestmark = pytest.mark.integration
class ApiSmokeTest(AsyncHTTPTestCase):
def get_app(self):
return create_app()
def test_health(self):
resp = self.fetch("/api/v1/health")
assert resp.code == 200
body = json.loads(resp.body)
assert body["code"] == 0
assert body["data"]["status"] == "ok"
def test_captcha(self):
resp = self.fetch("/api/v1/captcha")
assert resp.code == 200
body = json.loads(resp.body)
assert body["code"] == 0
assert body["data"].startswith("data:image/png;base64,")
def test_protected_requires_token(self):
resp = self.fetch("/api/v1/user/list")
body = json.loads(resp.body)
assert body["code"] == 401