Skip to content

Commit

Permalink
test(tests/test_case.py): add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
kwkwc committed Oct 18, 2020
1 parent f3f5fb2 commit 0b00ad1
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 45 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[run]
omit =
*/venv/*
*/virtualenv/*
*/tests/*
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ install:
- pip install -r tests/requirements.txt
- pip install coveralls
script:
- coverage run tests/test_accept.py
- coverage run tests/test_case.py
deploy:
provider: pypi
distributions: sdist bdist_wheel
Expand Down
2 changes: 1 addition & 1 deletion examples/sample/sample_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Api Document needs to be displayed
app.config['API_DOC_MEMBER'] = ['api', 'platform']

ApiDoc(app, title='Sample App', version='0.1.7')
ApiDoc(app, title='Sample App', version='0.1.8')

api = Blueprint('api', __name__)
platform = Blueprint('platform', __name__)
Expand Down
2 changes: 1 addition & 1 deletion examples/sample/sample_app_restful.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
app.config['RESTFUL_API_DOC_EXCLUDE'] = []

restful_api = Api(app)
ApiDoc(app, title='Sample App Restful', version='0.1.7')
ApiDoc(app, title='Sample App Restful', version='0.1.8')


class TodoList(Resource):
Expand Down
2 changes: 1 addition & 1 deletion examples/sample/sample_app_restful_methodview .py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# RESTful Api documents to be excluded
app.config['RESTFUL_API_DOC_EXCLUDE'] = []

ApiDoc(app, title='Sample App Restful Methodview', version='0.1.7')
ApiDoc(app, title='Sample App Restful Methodview', version='0.1.8')


class TodoList(MethodView):
Expand Down
2 changes: 1 addition & 1 deletion flask_docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Program:
Flask-Docs
Version:
0.1.7
0.1.8
History:
Created on 2018/05/20
Last modified on 2020/10/18
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def read(fname):

setup(
name='Flask-Docs',
version='0.1.7',
version='0.1.8',
url='https://github.com/kwkwc/flask-docs',
license='MIT',
author='kwkw',
Expand Down
39 changes: 0 additions & 39 deletions tests/test_accept.py

This file was deleted.

91 changes: 91 additions & 0 deletions tests/test_case.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env python
# coding=utf8

'''
Program:
Test case
Version:
0.0.2
History:
Created on 2020/10/18
Last modified on 2020/10/18
Author:
kwkw
'''


import sys
sys.path.append('.')

import unittest
from flask import Flask, Blueprint
from flask_restful import Resource, Api
from flask_docs import ApiDoc


app = Flask(__name__)
app.config['API_DOC_MEMBER'] = ['api']
ApiDoc(app, title='Test App')


class AcceptTestCase(unittest.TestCase):

def test_accept_docs_api(self):

with app.test_client() as client:
res = client.get('/docs/api/')
self.assertEqual(res.status_code, 200)
self.assertEqual(res.content_type, 'text/html; charset=utf-8')


class RestfulApiTestRoute(Resource):
pass


class TodoList(RestfulApiTestRoute):
"""Manage todolist"""

def post(self):
"""Submission of data"""
pass

def get(self):
"""
@@@
### markdown
@@@
"""
pass


class CoverageTestCase(unittest.TestCase):

def test_api_route_coverage(self):

api = Blueprint('api', __name__)

@api.route('/add_data', methods=['POST'])
@api.route('/data', methods=['POST', 'GET'])
def add_data():
pass

app.register_blueprint(api, url_prefix='/api')

with app.test_client() as client:
res = client.get('/docs/api/')
self.assertEqual(res.status_code, 200)
self.assertEqual(res.content_type, 'text/html; charset=utf-8')

def test_restful_api_route_coverage(self):

restful_api = Api(app)
restful_api.add_resource(TodoList, '/todolist', '/todo')

with app.test_client() as client:
res = client.get('/docs/api/')
self.assertEqual(res.status_code, 200)
self.assertEqual(res.content_type, 'text/html; charset=utf-8')


if __name__ == '__main__':
unittest.main()

0 comments on commit 0b00ad1

Please sign in to comment.