网上找了一下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

基于django rest framework的mock server实践的更多相关文章

  1. Mock Server实践

    转载自 https://tech.meituan.com/mock-server-in-action.html 背景 在美团服务端测试中,被测服务通常依赖于一系列的外部模块,被测服务与外部模块间通过R ...

  2. 基于Django rest framework 和Vue实现简单的在线教育平台

      一.基于api前端显示课程详细信息 1.调整Course.vue模块 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2 ...

  3. 基于django rest framework做认证组件

    先导入要用到的类 from rest_framework.authentication import BaseAuthentication from rest_framework.exceptions ...

  4. Django:Django Rest Framework

    Django Rest Framework   一. 什么是RESTful REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称 ...

  5. Django Rest Framework(阿奇)

    Django Rest Framework 一. 什么是RESTful REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称,中 ...

  6. Django Rest Framework(一)

    一.什么是RESTful REST与技术无关,代表一种软件架构风格,REST是Representational State Transfer的简称,中文翻译为“表征状态转移”. REST从资源的角度审 ...

  7. django restful framework教程大全

    一. 什么是RESTful REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称,中文翻译为“表征状态转移” REST从资源的角 ...

  8. 用Django Rest Framework和AngularJS开始你的项目

    Reference: http://blog.csdn.net/seele52/article/details/14105445 译序:虽然本文号称是"hello world式的教程&quo ...

  9. Django REST framework框架介绍和基本使用

    Django REST framework介绍 Django REST framework是基于Django实现的一个RESTful风格API框架,能够帮助我们快速开发RESTful风格的API. 官 ...

随机推荐

  1. 新浪微博API Oauth2.0 认证

    原文链接: http://rsj217.diandian.com/post/2013-04-17/40050093587 本意是在注销账号前保留之前的一些数据.决定用python 爬取收藏.可是未登录 ...

  2. 剑指Offer - 九度1283 - 第一个只出现一次的字符

    剑指Offer - 九度1283 - 第一个只出现一次的字符2013-11-21 21:13 题目描述: 在一个字符串(1<=字符串长度<=10000,全部由大写字母组成)中找到第一个只出 ...

  3. Percona-Tookit工具包之pt-summary

      Preface       As a dba,We are obliged to master several basic tools(such as vmstat,top,netstat,ios ...

  4. JS——BOM、DOM

    BOM.DOM BOM window对象 history对象 location对象 screen对象 DOM DOM对HTML元素访问操作 HTML DOM树 DOM 节点 DOM访问HTML元素 D ...

  5. diskimage-builder-command

    yum -y install python-virtualenv.noarch virtualenv ~/dib-virtualenv . ~/dib-virtualenv/bin/activate ...

  6. HDU 4681 String 胡搞

    设串C的第一个字母在串A中出现的位置是stA, 串C的最后一个字母在串A中出现的位置是edA. 设串C的第一个字母在串B中出现的位置是stB, 串C的最后一个字母在串B中出现的位置是edB. 求出每一 ...

  7. fragment中的WebView返回上一页

    public final class Text1Fm extends Fragment { static WebView mWeb; private View mContentView; privat ...

  8. 使用puTTY或Xshell连接阿里云TimeOut超时

    根据网上很多主流的说法,我依次检查了 ssh: service sshd status 防火墙:service iptables stop (CentOS 7好像已经没有这个iptable了) 都没有 ...

  9. lambda表达式10个示例——学习笔记

    摘录:http://www.importnew.com/16436.html 1.lambda实现Runnable // Java 8之前: new Thread(new Runnable() { @ ...

  10. 【Luogu】P3288方伯伯运椰子(消圈定理)

    题目链接 分数规划题,详见luogu题解 #include<cstdio> #include<cstring> #include<cctype> #include& ...