Skip to content

Commit

Permalink
Merge pull request #253 from chinapnr/v1.1.16_develop
Browse files Browse the repository at this point in the history
V1.1.16 develop
  • Loading branch information
itaa committed Dec 5, 2019
2 parents 124b6ab + 65a2282 commit 3cf51ea
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 26 deletions.
20 changes: 14 additions & 6 deletions .travis.yml
Expand Up @@ -6,7 +6,10 @@ matrix:
python: "nightly"
- os: linux
dist: xenial
python: "3.8-dev"
python: "3.9-dev"
- os: linux
dist: xenial
python: "3.8"
- os: linux
dist: xenial
python: "3.7"
Expand All @@ -25,19 +28,24 @@ matrix:
- os: linux
dist: trusty
python: "pypy3.5"
- os: linux
dist: trusty
python: "pypy3.6"
allow_failures:
- python: nightly
- python: 3.8-dev
- python: "2.7"
- python: "3.6"
- python: 3.9-dev
- python: "3.5"
- python: "3.4"
- python: "2.7"
- python: "pypy3.6"
- python: "pypy3.5"

# command to install dependencies
install:
- pip install -r requirements.txt
# command to run tests
script:
- pytest
- pytest test/
after_success:
- pytest --cov=fishbase --ignore=fishbase/swagger test/
- pytest --cov=fishbase test/
- coveralls
16 changes: 8 additions & 8 deletions demo/swagger/demo_flask_blueprint_swagger.py
Expand Up @@ -18,16 +18,16 @@ class AddXxReqVo:
"""
新增 Xx 请求 Vo
"""
name: str
age: int
name = ""
age = 0


class UpdateXxReqVo:
"""
更新 Xx 请求 Vo
"""
name: str
age: int
name = ""
age = 0


@doc.summary("xx业务查询接口", group="xx业务")
Expand Down Expand Up @@ -61,10 +61,10 @@ def test_update():


# 定义路由信息, 并指定路由映射的方法,请求方式等
APPBlueprint.add_url_rule(f'/v1/query', view_func=test_query, methods=['GET'], endpoint='test_func1')
APPBlueprint.add_url_rule(f'/v1/add', view_func=test_add, methods=['POST'], endpoint='test_func2')
APPBlueprint.add_url_rule(f'/v1/del', view_func=test_del, methods=['DELETE'], endpoint='test_func3')
APPBlueprint.add_url_rule(f'/v1/update', view_func=test_update, methods=['PUT'], endpoint='test_func4')
APPBlueprint.add_url_rule('/v1/query', view_func=test_query, methods=['GET'], endpoint='test_func1')
APPBlueprint.add_url_rule('/v1/add', view_func=test_add, methods=['POST'], endpoint='test_func2')
APPBlueprint.add_url_rule('/v1/del', view_func=test_del, methods=['DELETE'], endpoint='test_func3')
APPBlueprint.add_url_rule('/v1/update', view_func=test_update, methods=['PUT'], endpoint='test_func4')

app.register_blueprint(APPBlueprint)
# 将 app 对象传递给 swagger 模块
Expand Down
16 changes: 8 additions & 8 deletions demo/swagger/demo_flask_swagger.py
Expand Up @@ -16,24 +16,24 @@ class AddXxReqVo:
"""
新增 Xx 请求 Vo
"""
name: str
age: int
name = ""
age = 0


class UpdateXxReqVo:
"""
更新 Xx 请求 Vo
"""
name: str
age: int
name = ""
age = 0


@app.route('/v1/query', methods=['GET'])
@doc.summary("xx业务查询接口", group="xx业务")
@doc.description("测试 Swagger 使用, 参数为 URL 参数 token, 且必传")
@doc.consumes("token", required=True)
def test_query():
pass
return "test_query"


@app.route('/v1/add', methods=['POST'])
Expand All @@ -42,15 +42,15 @@ def test_query():
@doc.consumes(AddXxReqVo, location="body")
@doc.consumes("token", required=True)
def test_add():
pass
return "test_add"


@app.route('/v1/del', methods=['DELETE'])
@doc.summary("xx业删除增接口", group="xx业务")
@doc.description("测试 Swagger 使用, 参数为 URL 参数 token, 且非必传")
@doc.consumes("token", required=False)
def test_del():
pass
return "test_del"


@app.route('/v1/update', methods=['PUT'])
Expand All @@ -59,7 +59,7 @@ def test_del():
@doc.consumes(UpdateXxReqVo, location="body")
@doc.consumes("token", required=True)
def test_update():
pass
return "test_update"


# 将 app 对象传递给 swagger 模块
Expand Down
6 changes: 3 additions & 3 deletions fishbase/swagger/swagger.py
Expand Up @@ -273,6 +273,6 @@ def swagger():
return render_template("index.html")


swagger_blueprint.add_url_rule(f'/swagger.json', view_func=swagger_json, methods=['GET'], endpoint='swagger_json')
swagger_blueprint.add_url_rule(f'/swagger-config', view_func=swagger_json, methods=['GET'], endpoint='swagger_config')
swagger_blueprint.add_url_rule(f'/', view_func=swagger, methods=['GET'], endpoint='swagger')
swagger_blueprint.add_url_rule('/swagger.json', view_func=swagger_json, methods=['GET'], endpoint='swagger_json')
swagger_blueprint.add_url_rule('/swagger-config', view_func=swagger_json, methods=['GET'], endpoint='swagger_config')
swagger_blueprint.add_url_rule('/', view_func=swagger, methods=['GET'], endpoint='swagger')
3 changes: 2 additions & 1 deletion requirements.txt
@@ -1,7 +1,8 @@
python-dateutil
coverage
pytest==4.0.2
pytest>=4.6.6
pytest-cov
coveralls
pyyaml
chardet
flask
33 changes: 33 additions & 0 deletions test/test_swagger.py
@@ -0,0 +1,33 @@
# coding=utf-8
# 2019.12.5 v1.1.16 #249 create by Jia ChunYing
from demo.swagger.demo_flask_swagger import app
import pytest


@pytest.fixture
def client():
app.config['TESTING'] = True

with app.test_client() as client:
yield client


# 2019.12.5 v1.1.16 #249 create by Jia ChunYing
@pytest.mark.usefixtures('client')
class TestSwagger(object):

def test_query(self, client):
response = client.get('/v1/query')
assert b'test_query' in response.data

def test_add(self, client):
response = client.post('/v1/add')
assert b'test_add' in response.data

def test_del(self, client):
response = client.delete('/v1/del')
assert b'test_del' in response.data

def test_update(self, client):
response = client.put('/v1/update')
assert b'test_update' in response.data

0 comments on commit 3cf51ea

Please sign in to comment.