当前位置:网站首页>Test platform (V) knowledge points supplement
Test platform (V) knowledge points supplement
2022-07-28 12:00:00 【M1kasal】
Preface
If you look at me before the whole 【 Test platform construction 】 There are many questions in my article , For example, if you haven't used some packages introduced inside and don't know how to use them , You can read this blog , I put some knowledge points , Screw it out separately and sum it up
Next, I will talk about each knowledge point one by one
Back end :
--> 1、flask Basic use
--> 2、Flask Restx Basic use
--> 3、Flask-Restx Integrate Swagger
--> 4、Orm Brief introduction
--> 5、flask_SQLAlchemy Basic use
front end :
--> 1、api Optimize
- Mikasa Test platform construction column :https://blog.csdn.net/makasa/category_11904938.html?spm=1001.2014.3001.5482
One 、flask Basic use
- In fact, it has been briefly introduced before , Don't understand the notes
https://blog.csdn.net/Makasa/article/details/125690307
1、 download flask
pip install flask

2、flask_demo.py
""" Here is a brief introduction flask Basic use of Premise : pip install flask """
from flask import Flask
# 1、 establish app example
app = Flask(__name__)
# 2、 Define routing and view functions
@app.route("/demo")
def hello_world():
return "HelloWorld"
# 2、 Define dynamic routing and view functions
@app.route("/getname/<username>")
def getname(username):
return username
# 3、 Definition 【 Limited type 】 Routing and view functions
# Types include 5 Kind of :string,int,float,path,uuid
@app.route("/post/<string:username>")
def get(username):
return username
# 4、 The end of the route is marked with "/"( Enter and do not enter in the address bar of the browser “/” The effect is the same )
# There is no at the end of the route “/”( Input URL Cannot add “/”, Will report a mistake 404)
# Types include 5 Kind of :string,int,float,path,uuid
@app.route("/demo2/")
def print():
return " There is /"
# Definition http request :get/post/put/delete
# 5、 Definition 【get/post/put/delete request 】 Routing and view functions
# Be careful :methods, It's a list
@app.route("/testcase", methods=["get"])
# @app.route("/testcase", methods=["post"])
# @app.route("/testcase", methods=["put"])
# @app.route("/testcase", methods=["delete"])
def get_case():
return {
"code": 0, "msg": "get success"}
if __name__ == '__main__':
# debug by true, It's thermal loading , You can see the effect after saving the changes
# Appoint host For LAN
app.run(debug=True, host="0.0.0.0")
Two 、Flask-Restx Basic use
1、 install flask-restx
# Need to download package
pip install flask-restx

2、flask_restx_demo1.py
""" Here are Flask Restx Basic use of interface configuration Premise :pip install flask-restx He is a supporter Restful Of flask plug-in unit , For the preparation of standardized interfaces , And support swagger file """
from flask import Flask
from flask_restx import Api, Resource
# 1、 establish app example
app = Flask(__name__)
# 2、 establish Api example
api = Api(app)
# 3、 Define routing and view functions
# Be careful : Change the decorator to use @api.route("")
# Class should inherit Resource class
@api.route('/hello')
class HelloWorld(Resource):
def get(self):
return {
'hello': 'world'}
# 4、 start-up
if __name__ == '__main__':
app.run(debug=True)
3、flask_restx_demo2.py
""" Here are Flask Restx Basic use of interface configuration 2 Premise :pip install flask-restx Use restful Style specification interface """
from flask import Flask
from flask_restx import Api, Resource
# 1、 establish app example
app = Flask(__name__)
# 2、 establish api example
api = Api(app)
# The interface path is defined on the class , Create different methods corresponding to different request operations
@api.route("/user")
# Be careful : Class to inherit Resource
class User(Resource):
# 1、restful style get Method
def get(self):
return {
'code': 0, "msg": "get success"}
# 2、restful style post Method
def post(self):
return {
'code': 0, "msg": "post success"}
# 3、restful style put Method
def put(self):
return {
'code': 0, "msg": "put success"}
# 4、restful style delete Method
def delete(self):
return {
'code': 0, "msg": "delete success"}
if __name__ == '__main__':
app.run(debug=True)
3、 ... and 、Flask-Restx Integrate Swagger
1、flask_restx_namespace_demo.py
""" Here are Flask-Restx namespace Use """
from flask import Flask
from flask_restx import Api, Namespace, Resource
app = Flask(__name__)
api = Api(app)
# 1、 Definition Namespacce example
hello_ns = Namespace("demo", description="demo management ")
case_ns = Namespace("case", description=" Use case management ")
# 2、 Add decorator for class @namespace.route("") Control sub routes
@case_ns.route("")
class TestCase(Resource):
def get(self):
return {
'code': 0, 'msg': "get success"}
def post(self):
return {
'code': 0, 'msg': "post success"}
# 3、 Specify the access resource path for the namespace , It can be understood that the visit is /case Under the get/post.. Method , Namespace is : Use case management
api.add_namespace(case_ns, '/case')
if __name__ == '__main__':
app.run(debug=True)
2、flask_restx_swagger_demo.py
""" Here are flask_restx, Integrate swagger Basic use of swagger It can be understood as API Interface document , Easy to use in front and back end separation projects The front end can directly access the document for interface calls , Be similar to postman """
from flask import Flask
from flask_restx import Api, Namespace, Resource
app = Flask(__name__)
api = Api(app)
# 1、 Define the namespace
case_ns = Namespace("case", description=" Use case management ")
# 2、 Add decorator for class @namespace.route("") Control sub routes
@case_ns.route("")
class TestCase(Resource):
# 3、 Definition parser Parser object
get_paresr = api.parser()
# 4、 adopt parser Object to add parameters
# The first parameter is the parameter name , Followed by keyword parameters :
# 4.1、type: type (int/bool/float/string/FileStorage);
# 4.2、required Constraint control (True/False)
# 4.3、choices Enumeration parameters
# 4.4、location Corresponding request Properties in objects (args/form/json/files)
# Be careful : commonly get request location All are args,
# post The request can be /form/json/files, But what? file and json Can't coexist ,form and json Nor can they coexist
# That is to call add_argumet() when , Adding parameters cannot have location=file/json
get_paresr.add_argument("id", type=int, location="args")
# 5、 Add decorators
@case_ns.expect(get_paresr)
def get(self):
return {
'code': 0, 'msg': "get success"}
# 6、 Specify the access resource path for the namespace , It can be understood that the visit is /case Under the get/post.. Method , Namespace is : Use case management
api.add_namespace(case_ns, '/case')
if __name__ == '__main__':
app.run(debug=True)
Four 、Orm Brief introduction
1、ORM The meaning of
ORM(Object Relational apping): Object relation mapping , His function is Make a mapping between relation to database and object , This is also in the specific operation of the database , There's no need to go and complicated SQL Deal with sentences , You only need to operate like the normal operation object
- We 【 Test platform 】 In the project of ORM thought , Map objects to table structures , Create an entity and directly operate the addition, deletion, modification and query of entities , You don't need to write alone sql sentence , So it looks much simpler


2、ORM Advantages and disadvantages
advantage :
- hide Details of data access
- ORM It makes it very simple for us to construct a solid data structure
shortcoming :
- Performance degradation , Added associated operations
- Unable to solve particularly complex database operations
5、 ... and 、Flask-SQLAlchemy The plug-in configuration
- This is a brief introduction ORM The meaning of ,SQLAlchemy yes python The most famous ORM frame , And we 【 Test platform 】 The back-end framework uses Flask, Then we can use flask-sqlalchemy To realize the mapping of objects
1、 install flask-sqlalchemy
pip install flask-sqlalchemy

2、Flask-SQLAlchemy Basic use


""" Here are flask-sqlalchemy Basic use of """
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
# 1、 Instantiation flask
app = Flask(__name__)
# 2、 Configuration database information
username = "root"
password = "yy1998123"
server = "127.0.0.1"
database = "test_platform"
app.config['SQLALCHEMY_DATABASE_URI'] = \
f"mysql+pymysql://{
username}:{
password}@{
server}/{
database}?charset=utf8"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
# 3、 take app And Flask-QLAlchemy Binding , Instantiate a db object
db = SQLAlchemy(app)
# 4、 Create a database model
# 4.1、 Need to inherit db.Model
class User(db.Model):
# 4.2、 Be careful : If you don't customize the table name , The database table he generates defaults to the class name (user), If class name UserInfo, Table name user_info
# If the table name is customized , The customized one shall prevail
__tablename__ = "User"
# 4.3、 Define table fields , type / keyword
# 4.3.1、 Common parameter types :Integer/String(20)/JSON/DateTime/Boolean/Text..
# 4.3.2、 Common keyword parameters :
# primary_key: Is the primary key? ;autoincrement Whether the increased
# nullable: Is it allowed to be empty ,unique: Is repetition allowed
# default: The default value is
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True, nullable=False)
create_time = db.Column(db.DateTime)
json = db.Column(db.JSON)
def __repr__(self):
return self.username
if __name__ == '__main__':
# 1、 Create table
db.create_all()
# 2、 Delete table
db.drop_all()
3、CURD Basic operation
3.1、 Add data


3.2、 Query data



3.3、 Modifying data

3.4、 Delete data

6、 ... and 、 front end API Structure optimization
- Why should the front end be optimized api framework ? Mainly for more standardized code
- Now I'll take our 【 Front end of test platform 】 For example , Give a brief explanation

1、http.js

2、 Encapsulate the interfaces of each module (testcase/plan/build.js)


3、 Integrate api.js

4、 mount api


边栏推荐
- Shell (II)
- [applet] how to notify users of wechat applet version update?
- 移动端人脸风格化技术的应用
- P5472 [NOI2019] 斗主地(期望、数学)
- 瑞吉外卖——Day01
- Techniques for visualizing large time series.
- Introduction to the usage of SAP ui5 image display control avatar trial version
- [diary of supplementary questions] [2022 Niuke summer multi school 2] l-link with level editor I
- ASP. Net core 6 framework unveiling example demonstration [29]: building a file server
- Training mode and practice of digital applied talents in Colleges and Universities under the integration of industry and education
猜你喜欢

Unity encountered a pitfall and the AB package failed to unload

Minikube initial experience environment construction

In order to ensure the normal operation of fire-fighting equipment in large buildings, the power supply monitoring system of fire-fighting equipment plays a key role

14、用户web层服务(二)

A hundred flowers bloom in data analysis engines. Why invest heavily in Clickhouse?

Shell (II)
![[general database integrated development environment] Shanghai daoning provides you with Aqua Data Studio downloads, tutorials, and trials](/img/46/830b7703ae7cbfa6051137061560c2.png)
[general database integrated development environment] Shanghai daoning provides you with Aqua Data Studio downloads, tutorials, and trials

Service Workers让网站动态加载Webp图片

Matlab sets the size of graphics window and image and the position of legend

Hcip (condition matching and OSPF packet related knowledge)
随机推荐
Hcip (PAP authentication and chap authentication of PPP)
Database advanced learning notes cursor
Develop your own NPM package from 0
[diary of supplementary questions] [2022 Niuke summer multi school 2] l-link with level editor I
[pyGame practice] the super interesting bubble game is coming - may you be childlike and always happy and simple~
Static proxy instance
tolua之wrap文件的原理与使用
Hcip day 6 (OSPF related knowledge)
Minikube initial experience environment construction
Go deadlock - when the channel meets mutex
Upgrading of computing power under the coordination of software and hardware, redefining productivity
P5472 [noi2019] douzhudi (expectation, Mathematics)
Business visualization - make your flowchart'run'(4. Actual business scenario test)
ES6 knowledge points supplement
STL concept and its application
Will PFP be the future of digital collections?
程序的存储态与运行态
R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize the grouped dot plot, set the palette parameter, and set the color of data points in different grouped dot p
A natural choice
一些知识概念