Exemplo n.º 1
0
 def test_response_description(self):
     doc = Doc()
     api = Api(title='test api', url='/test/', method='POST')
     api.response_description = 'return *user* info'
     doc.add_api(api)
     html = doc.build()
     self.assertIn('return <em>user</em> info', html)
Exemplo n.º 2
0
 def test_tips(self):
     doc = Doc()
     api = Api(title='test api', url='/test/', method='DELETE')
     api.tips = '## Be careful to destroy'
     doc.add_api(api)
     html = doc.build()
     self.assertIn('<div class="endpoint delete">', html)
     self.assertIn('<h2>Be careful to destroy</h2>', html)
Exemplo n.º 3
0
 def test_body_param(self):
     doc = Doc()
     api = Api(title='test api', url='/test/', method='POST')
     bp1 = BodyParam(name='username')
     bp2 = BodyParam()
     bp2.name = 'password'
     api.params = [bp1, bp2]
     doc.add_api(api)
     html = doc.build()
     self.assertIn('<div class="endpoint post">', html)
     self.assertIn('<td><code>username</code></td>', html)
     self.assertIn('<td><code>password</code></td>', html)
Exemplo n.º 4
0
 def test_query_param(self):
     doc = Doc()
     api = Api(title='test api', url='/test/', method='GET')
     qp1 = QueryParam()
     qp1.name = 'page'
     qp1.description = 'page number of list'
     qp1.default = 1
     api.params.append(qp1)
     doc.add_api(api)
     html = doc.build()
     self.assertIn('<td><code>page</code></td>', html)
     self.assertIn('<td>page number of list</td>', html)
     self.assertIn('<td>1</td>', html)
Exemplo n.º 5
0
 def test_path_param(self):
     doc = Doc()
     api = Api(title='test api', url='/test/<id>/', method='GET')
     pp1 = PathParam()
     pp1.name = 'id'
     pp1.description = 'resource id'
     pp1.example = 10
     api.params.append(pp1)
     doc.add_api(api)
     html = doc.build()
     self.assertIn('<td><code>id</code></td>', html)
     self.assertIn('<td>resource id</td>', html)
     self.assertIn('<td>10</td>', html)
Exemplo n.º 6
0
 def test_language(self):
     doc = Doc()
     api = Api(title='test api', url='/test/', method='POST')
     api.body_example = '{}'
     doc.apis.append(api)
     html_en = doc.build()
     html_zh = doc.build(language='zh')
     self.assertIn('Contents', html_en)
     self.assertIn('Request Body Example', html_en)
     self.assertIn('Print This Document', html_en)
     self.assertIn('接口目录', html_zh)
     self.assertIn('示例请求数据', html_zh)
     self.assertIn('打印本文档', html_zh)
Exemplo n.º 7
0
    def test_body_example(self):
        doc = Doc()
        api = Api(title='test api', url='/test/', method='POST')
        api.body_example = """
{
    "username": "******",
    "password": "******"
}
"""
        doc.add_api(api)
        html = doc.build()
        self.assertIn('"username": "******"', html)
        self.assertIn('"password": "******"', html)
Exemplo n.º 8
0
 def test_api(self):
     doc = Doc()
     api = Api()
     api.title = "first api"
     api.method = "GET"
     api.url = "/test1/<id>/"
     api.description = "this is the **first** api"
     doc.add_api(api)
     html = doc.build()
     self.assertIn('first api', html)
     self.assertIn('<div class="endpoint get">', html)
     self.assertIn('/test1/&lt;id&gt;/', html)
     self.assertNotIn('<id>', html)
     self.assertIn('<strong>first</strong>', html)
Exemplo n.º 9
0
 def test_note(self):
     doc = Doc()
     note1 = Note()
     note1.title = 'test note1'
     note1.content = 'This is the **first** test note'
     note2 = Note()
     note2.content = 'This note has no title'
     doc.add_note(note1)
     doc.add_note(note2)
     html = doc.build()
     self.assertIn('test note1', html)
     self.assertIn('This is the <strong>first</strong> test note', html)
     self.assertNotIn('note2', html)
     self.assertIn('This note has no title', html)
Exemplo n.º 10
0
    def test_doc(self):
        doc = Doc(title='Test Api Document', version='v2')
        doc.host = 'http://www.apitest.com'
        doc.description = """
this is a test document
- test1
- test2
"""
        html = doc.build()
        self.assertIn('<h1>Test Api Document</h1>', html)
        self.assertIn('<li>Version: <code>v2</code></li>', html)
        self.assertIn('<li>Host: <code>http://www.apitest.com</code></li>', html)
        self.assertIn('<li>test1</li>', html)
        self.assertIn('<li>test2</li>', html)
Exemplo n.º 11
0
# ======= Basic Usage ========

# 第1步,引入 eave 包内组件
from eave import Doc, Note, Api, PP, QP, BP

# 也可以使用 * 方式完全引入
from eave import *

# 第2步,创建一个 doc 对象,并指定文档的标题和接口调用地址
doc = Doc(title='My Api Document', host='www.myapi.com')

# 第3步,如果需要的话,为文档添加描述信息,描述信息会出现在标题下方(支持 markdown 语法)
doc.description = """
the content of description is **markdown** format
1. one point
2. two point
3. three point
"""

# 第4步,如果需要的话,为文档添加一些详细的说明,这些内容会出现在接口目录的下方(支持 markdown 语法)
doc.add_note(title="note title",
             content="the content of note is also **markdown** format")

# 第5步,添加一个接口,使用 url method params 等参数进行描述
doc.add_api(title='Get all orders of shop',
            url='/shop/<id>/orders/',
            method='GET',
            description='Get all orders of shop, shop admin login required',
            params=[
                PP(name='id', description='the id of shop'),
                QP(name='page', type='integer', default=1),
Exemplo n.º 12
0
    data = open('assets/' + src, 'rb').read()
    data = base64.b64encode(data).decode()
    src = f'data:image/png;base64,{data}'
    w = w or ''
    return f'<img src="{src}" width="{w}">'


def img2(src):
    s = img(src)
    s = s.replace('width=""',
                  'style="border: solid 1px gray;border-radius: 20px;"')
    return s


doc = Doc(title='OpenAPI 在 Django 项目中的应用',
          host='openapi.tslow.cn',
          version='2020-06-14')

doc.description = """
##### 主讲人: 陶佳元 [tslow.cn](https://tslow.cn)
"""

note = Note(title='先听个段子')
note.content = f"""
#### 说程序员最痛恨的 4 件事情
1. 写注释
2. 写文档
3. 别人不写注释
4. 别人不写文档
<br><br><br>
"""