Skip to main content

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資料夾

  1. 有幾個role,就寫幾個py檔,命名規則為「role名_test.py」
  2. 每當新增一個role,請在tests/enumerations.py裡的RoleType新增一個role,
    並且在app/config/dev.yaml中新增「role名_USERNAME」以及「role名_PASSWORD」(此role的帳密)

tests/roles/administrator_test.py

  1. 例如有一個管理員role,就寫一個administrator_test.py
  2. AdministratorTests class繼承了TestBase
  3. TestBase為tests/base.py裡的class
  4. 要測API請詳見後面flask-admin startapp說明

tests/base.py

  1. TestBase class繼承了flask_testing的TestCase,所以必須override create_app function,此function必須回傳一個Flask instance
  2. 並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


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

flask_restful_helper-1.0.1-py3-none-any.whl (25.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page