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.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68f61e3c36c5eb9db53de8b4b754b44f97a2e80ebe45a381399b7baece433357 |
|
MD5 | 0ff6bcb2a82aa8215850d8409225264c |
|
BLAKE2b-256 | c62b83b0330294222d3f9b8b83a294f3d94fc80024ef7f0bacf6f7f095e1cb79 |