A small flask restful framework
Project description
Installation
API test
Role Template
下指令
flask-admin startproject
會同時把API測試的role template也建起來(建立一個tests資料夾)
Role Template程式解說
manage.py
若要執行API測試程式,請下指令:
python manage.py test
會測試所有test case,執行tests/roles資料夾底下檔名為「*_test.py」的所有檔案
tests/roles資料夾
- 有幾個role,就寫幾個py檔,命名規則為「role名_test.py」
- 每當新增一個role,請在tests/enumerations.py裡的RoleType新增一個role,
並且在app/config/dev.yaml中新增「role名_USERNAME」以及「role名_PASSWORD」(此role的帳密)
tests/roles/administrator_test.py
- 例如有一個管理員role,就寫一個administrator_test.py
- AdministratorTests class繼承了TestBase
- TestBase為tests/base.py裡的class
- 要測API請詳見後面flask-admin startapp說明
tests/base.py
- TestBase class繼承了flask_testing的TestCase,所以必須override create_app function,此function必須回傳一個Flask instance
- 並override setUp function(每個測試執行前會先執行setUp),裡面包含了針對資料庫做資料的初始化(清空資料,insert初始資料),並且獲取此role的帳密,call login API做登入的動作(獲取token)
tests/functions/sqls
請放入資料庫的初始資料的insert sql
app/config/dev.yaml
變數說明:
1.IS_NEED_INIT_DB_EVERY_TEST:每次測試前是否要初始化資料庫資料
API Template
下指令
flask-admin startapp
假設給定app名稱為account
在apps/account/tests/test.py為testcase
要讓Administrator去執行的話,就要讓tests/roles/administrator_test.py的AdministratorTests去繼承它
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for flask_restful_helper-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e1f6bef43512c390d4b7a9719a5e9b58437ba99fa4f131687a378ed20b35be5 |
|
MD5 | 6a207b5f3da12fea73b74f9db86aa7ee |
|
BLAKE2b-256 | 1a5a943ccd9b2761ca6b593ed174f5a0c82528f721ccad40a48a40d4a8a57fbd |