网上找了一下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. 了解JavaScript核心精髓(三)

    1.js判断对象是否存在属性. hasOwnProperty(‘property’)  判断原型属性是否存在. "property" in o;  判断原型属性和原型链属性是否存在 ...

  2. JavaScript中最常用的55个经典技巧,没事的时候看看,拓展解决问题的思路

    都转烂了,不过还是贴上来了.查的时候方便... test 1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键 & ...

  3. ASP.NET Core 认证与授权[2]:Cookie认证 (笔记)

    原文链接:https://www.cnblogs.com/RainingNight/p/cookie-authentication-in-asp-net-core.html 由于HTTP协议是无状态的 ...

  4. markdown备忘

    文章主要(99%)参考自:markdown基本语法 这是二级标题 这是加粗的文字 这是倾斜的文字` 这是引用的内容 这是引用的内容 以下是分割线: 超链接 列表内容1 列表内容2 列表内容3 1.列表 ...

  5. [转] mysql分区性能初探

    本文转自:http://www.cnblogs.com/acpp/archive/2010/08/09/1795464.html 一,      分区概念  分区允许根据指定的规则,跨文件系统分配单个 ...

  6. 波动数列 神奇的dp

    问题描述 观察这个数列: 1 3 0 2 -1 1 -2 ... 这个数列中后一项总是比前一项增加2或者减少3. 栋栋对这种数列很好奇,他想知道长度为 n 和为 s 而且后一项总是比前一项增加a或者减 ...

  7. 解决IDEA2018.1.5或者Android Studio 3.0版本的输入法不跟随光标问题

    问题1:IDEA2018.1.5版本的输入法不跟随光标 解决办法1:修改JDK版本,步骤如下: 1. 使用快捷键ctrl+shift+A,在输入框中输入Switch Boot JDK,如图所示 2.替 ...

  8. Tomcat学习笔记(一)

    Tomcat目录结构的认识 tomcat是Apache旗下的一个开源Servlet的容器,实现了对Servlet和JSP技术支持. 通过http://tomcat.apache.org/ 下载tomc ...

  9. ACM-Hero In Maze

                                                   Hero In Maze 时间限制(普通/Java):1000MS/10000MS          运行 ...

  10. Python学习笔记(Django篇)——4、继续完善视图层

    在demo/views.py中添加这些代码: def detail(request, question_id): returnHttpResponse("You're looking at ...