In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use the mock interface in python. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
What is mock?
Mock means to simulate in translation. It allows you to replace parts of your system with mock objects and assert the way they have been used.
Mock usually means that when testing an object, we construct some fake objects to simulate interaction with it. The behavior of these Mock objects is set in advance and as expected. Through these Mock objects to test whether the object works properly under normal logic, abnormal logic or stress, the behavior of Mock is fixed, it ensures that when you visit a method of the Mock, you can always get an expected result returned directly without any logic. Mock interface is to use some reasonable means to construct objects to simulate the real interface.
Import flaskimport jsonserver = flask.Flask (_ _ name__) # treat this py file as the service @ server.route ('/ api/login',methods= ['post','get']) # interface name. The default get request def login (): d = {' status_code':0,'message':' login successful'} return json.dumps (dre rearrangascification false) @ server.route ('/ api/update',methods= ['post','get']) # interface name The default get request def update (): uname = flask.request.values.get ('username') # username is incoming pwd = flask.request.values.get (' password') # password is passed in d = {'status_code':0,'message':' updated successfully', 'username': uname,' password': pwd} return json.dumps (dre rearrangasciific FalseVision post' 6) @ server.route ('/ api/check',methods= ['post') 'get']) # API name, default get request def check (): data = flask.request.get_json () # input parameter is json request d = {' status_code':0,'message':' query success', 'data':data} server.run (host='0',port=8000) Debug=True) # host='0' users in the local area network can access the debug=True modification code without restarting from fastapi import Formapp = FastAPI () @ app.post ('/ login') # post writing async def login (*, username:str=Form (...), password:str=Form (...): return {'username':username, "password": password} @ app.get (' / reg') # get writing def login (username:str,password:str): uvicorn.run (app,port=8001) Debug=True) this is the end of the article on "how to use the mock interface in python" Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.