Skip to main content
PyPI Version Supported Python versions

miaou 是 pyzentao 规格文件的自助生成工具。

宋朝的严羽在《沧浪诗话·诗辨》中说:”大抵禅道惟在妙悟,诗道亦在妙悟”,于是取名 “妙悟 (miaou)”。

安装

$ pip install -U miaou

使用

调用 miaou.generate() 方法生成规格文件

import miaou

miaou.generate(
    site_url="http://my.zentao.site/zentao",
    username="admin",
    password="123456",
    scanner="selenium",
    combined_print=True,
    output_path="."
)

结果放在 /output_path/pyzentao_specs_timestamp 下面

参数说明

  • site_url

    你家禅道的域名,一般需要加上 zentao 这个前缀,如 “http://my.zentao.site/zentao”, 注意在禅道 v18 版本后默认没有这个前缀

  • dev_url

    禅道二次开发页面,如 “http://my.zentao.site/zentao/dev-api.html”,默认会由 site_url 加上 dev-api.html 拼凑而成,但在禅道 v18 版本后改为 “http://my.zentao.site/dev-api-index.html”, 所以建议根据你的禅道二次开发页面显式赋值该参数

  • username

    登录用户名,用于禅道授权

  • password

    登录密码,用于禅道授权

  • scanner

    扫描器类型,目前自带扫描器支持 “selenium” 和 “api”,也可以自定义扫描器,详见下文

  • combined_print

    合并打印规格,默认是 True ,会将规格打印到一个 yaml 文件,否则按 module 打印到不同文件

  • output_path

    输出的目录,默认是当前目录

  • config

    传给 scanner 的配置参数,应为 dict 类型

扫描器

扫描禅道页面以获得规格,目前支持 selenium 和 api,也可以自定义扫描器。

selenium

使用 selenium 4.8.0 版本以上,默认使用 chromedriver,可根据你的 Chrome 版本,在 chromedriver 下载,并 添加到 path 中。如果要使用 firefox 可在参数中指定,例如

import miaou

miaou.generate(
    ...
    scanner="selenium",
    config={"driver": "firefox"},
)

api

使用禅道对应的 API 生成规格。调用时指定扫描器类型即可

import miaou

miaou.generate(
    ...
    scanner="api",
    ...
)

注意,使用此扫描器生成的规格与禅道文档有一些不同,比如禅道文档中描述的查询 testsuite 的 API 为

GET  /zentao/testsuite.json

使用 selenium 扫描器生成的规格即为

testsuite:
    method: GET
    path: testsuite

而禅道 API 查询到的格式类似于

GET  /zentao/testsuite-index.json

所以使用 api 扫描器生成的规格为

testsuite_index:
    method: GET
    path: testsuite-index

这两种 API 得到的数据是相同的,在转换成 pyzentao 方法时请以你使用的规格文件为准。

自定义扫描器

也可以自定义扫描器,从 miaou.Scanner 继承

import miaou

class MyScanner(miaou.Scanner):
    """doc string"""

    def __init__(self, config):
        ...

然后需要实现如下方法:

  • open(self, site_url, username, password)

    一般是获得禅道授权

  • close(self)

    清扫工作,没有就不写

  • get_module_groups(self, dev_url)

    获得 API 模块页面链接,也就是 后台 - 二次开发 - API 页面左边栏 模块列表 下的那些链接。返回模块链接数组 [url…]

  • get_apis(self, api_url)

    在指定的模块页面,即 api_url 中获取 API 规格,返回包含dict的数组类似 [{name, method, path, params}]

使用自定义扫描器

import miaou

miaou.generate(
    ...
    scanner=MyScanner(config),
    ...
)

另,此工具的功能仅在 Linux/Python3.10 环境下测试,使用其他环境的宝子请自娱自乐 ╮(╯▽╰)╭

Metadata

Release files for miaou 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for miaou 0.2.2
File Size Uploaded Provenance
miaou-0.2.2.tar.gz 12.1 kB Without provenance Details

Release files / miaou-0.2.2.tar.gz

Download URL miaou-0.2.2.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
97af8bd94520fc1ee7190c1263d952fdd442cb7a925f4ae6503b196f33abb5bf
BLAKE2b-256 checksum
How to use checksums
b8f36b2df2ace29d2dd5eef5c126c810bff5a12c78ca85d36f1ca2b6f8bb6c57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.10

Security for miaou 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page