日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

基于django rest framework的mock server实践

發布時間:2023/12/2 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于django rest framework的mock server实践 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

網上找了一下mock server的實現,發現python的基本都是基于flask來實現的,因最近在學django,就嘗試用drf實現了下:

A brief introduction of sui_mock

sui mock server is an attempt that aim at dealing some issues of the third part service,get it from https://github.com/chengtch/sui-mock

Reference resources:
simple mock from testerhome with flask https://testerhome.com/topics/10238
ali mock platform https://yq.aliyun.com/articles/236198

1) Why we need mock

1.1 To simulate unstable services

????Because there is no business logic in mock server,that makes it stable enough

2.2 To quickly construct complex data

????Because we can customize a response

2.3 To rapidly construct abnormal scenes

????Because we can return any response code we want

2.4 To help the coders impove coding efficiency

????Because they don't need to wait too long for debugging

2.5 To help the testers get better working

????As a tester ,you should know what i am trying to say

2) Design logic

????Django + rest framework + mysql

3) Steps to complete

  • 3.1 create new django project named sui_mock
  • 3.2 create new app named app_mock
  • 3.3 design the models with all the api params
  • 3.4 make configrations of the settings about db,app,language
  • 3.5 makemigrations\migrate\createsuperuser: admin/your_password
  • 3.6 register the model class in the admin.py
  • 3.7 edit the serializer and views to implement the function logic
  • 3.8 config the urls.py to match the request path
  • 3.9 install all the dependency (get it from the requirement.txt)
  • 3.10 start the mockserver by python manage.py runserver 0.0.0.0:8000

4) Examples

4.1 Start the server and add an api in the backstage management system


4.2 Call the api by postman

5) Run server by https

first install some thirdpart libs:

pip install django-extensions pip install django-werkzeug-debugger-runserver pip install pyOpenSSL

then run the server:

python manage.py runserver_plus --cert server.crt 0.0.0.0:8000

finally visit the https server:

eg: https://192.168.254.1:8000/cnp/auth

轉載于:https://www.cnblogs.com/chengtch/p/9570587.html

總結

以上是生活随笔為你收集整理的基于django rest framework的mock server实践的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。