Token导航 LogoToken导航TokenDH.com
Datakwip Functional Tests logo
开发工具stdio官方级别未说明来源级核验

Datakwip Functional Tests

MCP Server

DataKwip平台的全面功能测试套件,涵盖API端点、MCP工具、UI自动化和Keycloak认证等主要组件。

工具数

0

提示词数

0

GitHub Stars

0

资源数

0
Python自动化测试API测试

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

dk-csperdue

提供方

dk-csperdue

最后核验

2026/5/17 20:19

运行时

Python

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

python -m venv .venv

详细介绍

DataKwip功能测试

铁路部署的DataKwip平台的综合功能测试套件。测试所有主要组件,包括API端点、MCP工具、UI自动化和Keycloak认证。

概述

这个测试套件用于验证完整的DataKwip平台栈:

  • Keycloak 认证OAuth2 流程、域配置、客户端/用户管理
  • DataKwip API(中文可译为“DataKwip应用程序编程接口”)带有OAuth2认证的REST端点,数据库健康状态
  • MCP 工具JSON-RPC 2.0 协议,查询实体,获取当前值
  • 管理界面(Admin UI)Playwright浏览器自动化,登录流程,导航

先决条件

所需软件

  • Python 3.11或更高版本从……下载 python.org
  • Playwright 浏览器单独安装(见安装部分)
  • Git用于版本控制

铁路服务

所有测试要求以下铁路服务正在运行:

  • datakwip认证服务 (Keycloak): (可译为)(关键密钥): https://datakwip-ai.up.railway.app
  • datakwip-api 翻译成中文可以是“Datakwip 接口”或“Datakwip API(应用程序编程接口)”,具体取决于上下文和使用场景。这里,“datakwip”可能是一个特定服务或平台的名称,而“-api”则表示这是该服务或平台提供的应用程序编程接口。https://datakwip-api-dev.up.railway.app
  • datakwip-mcp-connector 翻译为中文是:“DataKwip MCP 连接器”https://datakwip-mcp-connector-dev.up.railway.app
  • datakwip-ai-ui 可以翻译为“数据插件-人工智能用户界面”。不过,这里的“datakwip”可能是一个特定产品或项目名称,如果它没有官方的中文译名,通常会保留原英文形式或根据上下文进行适当解释。因此,一个更通用的翻译可能是“(特定数据插件名)- 人工智能用户界面”。如果“datakwip”有特定的中文含义或官方译名,建议使用那个译名。https://datakwip-ai-ui-dev.up.railway.app

测试数据

测试假定模拟器已加载测试数据:

  • 组织ID: 1
  • 在 TimescaleDB 中测试实体和标签
  • 在Keycloak中创建的功能测试用户

安装

1. 克隆仓库

cd C:\Users\csper\datakwip-projects\datakwip-platform
# Repository is already in datakwip-functional-tests/

2. 创建虚拟环境

cd datakwip-functional-tests
python -m venv .venv

3. 激活虚拟环境

Windows(PowerShell):

.venv\Scripts\Activate.ps1

Windows(CMD):

.venv\Scripts\activate.bat

Linux/macOS:

source .venv/bin/activate

4. 安装Python依赖项

pip install -e .

这会安装:

  • pytest(测试框架)
  • pytest-asyncio(异步测试支持)
  • httpx(HTTP 客户端)
  • 网页自动化工具(用于浏览器自动化)
  • python-keycloak(Keycloak管理API)
  • python-dotenv(环境变量)
  • pydantic(配置验证)

5. 安装 Playwright 浏览器

重要这是一个 单独步骤 并且必须手动运行:

playwright install chromium

对于其他浏览器:

playwright install firefox
playwright install webkit

安装所有浏览器:

playwright install

每个浏览器的安装大小约为300MB。建议使用Chromium进行最快的测试。

配置

1. 复制环境模板

cp .env.example .env

2. 编辑 .env 文件

如果与默认值不同,请更新以下值:

# Railway URLs (should match your Railway deployment)
RAILWAY_API_URL=https://datakwip-api-dev.up.railway.app
RAILWAY_MCP_URL=https://datakwip-mcp-connector-dev.up.railway.app
RAILWAY_UI_URL=https://datakwip-ai-ui-dev.up.railway.app
RAILWAY_AUTH_URL=https://datakwip-ai.up.railway.app

# OAuth2 Client (must match Keycloak configuration)
FUNCTIONAL_TESTS_CLIENT_ID=functional-tests
FUNCTIONAL_TESTS_CLIENT_SECRET=functional-tests-secret-2025

# Test User (must exist in Keycloak)
FUNCTIONAL_TEST_USER_EMAIL=functional-test-user@datakwip.local
FUNCTIONAL_TEST_USER_PASSWORD=FunctionalTest2025!

# Keycloak Admin (for admin API tests)
KEYCLOAK_ADMIN=admin
KEYCLOAK_ADMIN_PASSWORD=admin123

安全提示永远不要提交(代码/更改等) .env 用于版本控制。其中包含机密信息。

运行测试

运行所有测试

pytest

运行特定测试类别

# API tests only
pytest -m api

# MCP tests only
pytest -m mcp

# UI tests only (requires Playwright browsers)
pytest -m ui

# Authentication tests only
pytest -m auth

# Integration tests only
pytest -m integration

运行特定测试文件

pytest tests/test_api.py
pytest tests/test_mcp.py
pytest tests/test_ui.py
pytest tests/test_auth.py
pytest tests/test_integration.py

运行特定测试功能

pytest tests/test_api.py::test_database_health
pytest tests/test_integration.py::test_full_integration_suite

冗长的输出

pytest -v
pytest -vv  # Extra verbose

显示打印语句

pytest -s

并行运行测试

pip install pytest-xdist
pytest -n auto  # Use all CPU cores

跳过慢速测试

pytest -m "not slow"

仅运行集成套件

pytest -m integration -v -s

这运行了全面的集成测试,按顺序验证了所有组件。

测试输出

成功的试运行

========== test session starts ==========
platform win32 -- Python 3.11.0
collected 25 items

tests/test_api.py::test_database_health PASSED        [ 4%]
tests/test_api.py::test_list_entities PASSED          [ 8%]
tests/test_api.py::test_list_entity_tags PASSED       [12%]
...
tests/test_integration.py::test_full_integration_suite PASSED [100%]

========== 25 passed in 45.32s ==========

测试失败

tests/test_api.py::test_database_health FAILED

FAILED tests/test_api.py::test_database_health - httpx.ConnectError: Connection refused

集成套件输出

================================================================================
DATAKWIP PLATFORM FUNCTIONAL TEST SUITE
================================================================================

[1/4] Testing Keycloak Authentication...
✓ Keycloak authentication tests passed (2.34s)

[2/4] Testing API Endpoints...
✓ API endpoint tests passed (1.87s)
  - Retrieved 10 entities
  - Retrieved 20 tags

[3/4] Testing MCP Tools...
✓ MCP tool tests passed (1.52s)
  - Available tools: 5
  - Retrieved 10 entities via MCP

[4/4] Testing UI Automation...
✓ UI automation tests passed (8.21s)
  - Login: ✓
  - Page title: DataKwip Admin
  - Data Explorer: Not available

================================================================================
TEST SUITE SUMMARY
================================================================================
✓ PASS   Keycloak Auth          2.34s
✓ PASS   API Endpoints          1.87s
✓ PASS   MCP Tools              1.52s
✓ PASS   UI Automation          8.21s
--------------------------------------------------------------------------------
Total execution time: 13.94s

🎉 ALL TESTS PASSED!
================================================================================

测试覆盖率

API测试(tests/test_api.py)

  • ✅ 数据库健康检查(无需认证)
  • ✅ 实体列表,支持OAuth2认证
  • ✅ 带有OAuth2认证的实体标签列表
  • ✅ OAuth2令牌缓存验证
  • API压力测试(10次快速请求)

预期响应时间:

  • 数据库健康状态:\_`

示例:

import pytest

@pytest.mark.api
def test_new_endpoint(api_client, config):
    """Test description."""
    result = api_client.some_method()
    assert result is not None

添加新设备

编辑 conftest.py

@pytest.fixture(scope="session")
def my_fixture(config):
    """Fixture description."""
    # Setup
    resource = create_resource(config)
    yield resource
    # Teardown
    resource.close()

在本地运行测试

你也可以通过更新来测试本地服务 .env

RAILWAY_API_URL=http://localhost:8000
RAILWAY_MCP_URL=http://localhost:9090
RAILWAY_UI_URL=http://localhost:3000
RAILWAY_AUTH_URL=http://localhost:8081

CI/CD 集成

GitHub Actions 示例

name: Functional Tests

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.11'
      - name: Install dependencies
        run: |
          pip install -e .
          playwright install chromium
      - name: Run tests
        env:
          RAILWAY_API_URL: ${{ secrets.RAILWAY_API_URL }}
          FUNCTIONAL_TESTS_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
        run: pytest -v

最佳实践

  1. 始终使用 .env 文件不要在代码中硬编码凭证
  2. 在部署前运行集成套件验证整个平台
  3. 检查用户界面故障的截图可视化调试极为宝贵
  4. 使用标记来组织测试在开发过程中运行子集
  5. 保持测试的幂等性测试不应依赖于顺序或状态
  6. 使用描述性断言让失败变得易于理解
  7. 更新 .env.example 文件当添加新配置时

项目结构

datakwip-functional-tests/
├── clients/                    # API client implementations
│   ├── __init__.py
│   ├── api_client.py          # DataKwip API client (OAuth2)
│   ├── mcp_client.py          # MCP JSON-RPC 2.0 client
│   ├── ui_client.py           # Playwright automation client
│   └── auth_client.py         # Keycloak admin client
├── tests/                     # Test modules
│   ├── __init__.py
│   ├── test_api.py           # API endpoint tests
│   ├── test_mcp.py           # MCP tool tests
│   ├── test_ui.py            # UI automation tests
│   ├── test_auth.py          # Keycloak auth tests
│   └── test_integration.py   # Full integration suite
├── fixtures/                  # Test fixtures and helpers
│   └── __init__.py
├── screenshots/               # Playwright screenshots (on failure)
├── conftest.py               # Pytest configuration and fixtures
├── pyproject.toml            # Python dependencies and config
├── .env.example              # Environment variable template
├── .env                      # Local configuration (DO NOT COMMIT)
├── .gitignore               # Git ignore patterns
└── README.md                # This file

已知的局限性

  1. Playwright 浏览器安装需要单独的手动安装步骤(约300MB)
  2. 铁路服务必须正常运行如果任何铁路服务中断,测试将失败
  3. 测试数据依赖性测试假设模拟器已使用测试数据为组织ID 1进行了初始化
  4. UI测试脆弱性UI测试依赖于DOM结构,可能会因UI更改而失效
  5. 网络延迟铁路响应时间可能有所不同;请调整超时设置 .env 如需

下一步

功能测试通过后:

  1. GitHub 仓库主要代理将创建GitHub仓库
  2. Keycloak 生产环境部署主代理将在铁路系统中部署Keycloak
  3. 持续集成/持续交付(CI/CD)集成为自动化测试添加GitHub Actions工作流
  4. 生产测试为生产环境创建单独的测试套件
  5. 性能测试使用 Locust 或 k6 添加负载测试
  6. 监测将测试结果与监控仪表板集成

支持

对于问题或疑问:

  1. 检查铁路服务日志
  2. 审查Keycloak配置
  3. 验证测试用户和客户端是否存在
  4. 检查截图以确认UI测试失败情况
  5. 使用以下工具运行测试 -v -s 用于详细输出

许可证

这个测试套件是DataKwip平台项目的一部分。

______________________________________________________________________

最后更新时间2025年10月21日 版本0.1.0 python3.11及以上版本 Pytest8.0+

目录标签

目录标签

Python自动化测试API测试功能测试本地部署UI测试认证测试

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

session

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdiosession部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP