基于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
基于django rest framework的mock server实践的更多相关文章
- Mock Server实践
转载自 https://tech.meituan.com/mock-server-in-action.html 背景 在美团服务端测试中,被测服务通常依赖于一系列的外部模块,被测服务与外部模块间通过R ...
- 基于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 ...
- 基于django rest framework做认证组件
先导入要用到的类 from rest_framework.authentication import BaseAuthentication from rest_framework.exceptions ...
- Django:Django Rest Framework
Django Rest Framework 一. 什么是RESTful REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称 ...
- Django Rest Framework(阿奇)
Django Rest Framework 一. 什么是RESTful REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称,中 ...
- Django Rest Framework(一)
一.什么是RESTful REST与技术无关,代表一种软件架构风格,REST是Representational State Transfer的简称,中文翻译为“表征状态转移”. REST从资源的角度审 ...
- django restful framework教程大全
一. 什么是RESTful REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称,中文翻译为“表征状态转移” REST从资源的角 ...
- 用Django Rest Framework和AngularJS开始你的项目
Reference: http://blog.csdn.net/seele52/article/details/14105445 译序:虽然本文号称是"hello world式的教程&quo ...
- Django REST framework框架介绍和基本使用
Django REST framework介绍 Django REST framework是基于Django实现的一个RESTful风格API框架,能够帮助我们快速开发RESTful风格的API. 官 ...
随机推荐
- 点击事件处理, 以及hitTest:withEvent:实现
发送触摸事件后, 系统会将事件添加到系统UIApplication的事件管理队列中 UIApplication会在事件队列的最前端取出事件,然后分发下去,以便处理, 通常会把事件首先分发给KeyWin ...
- 18、bootStap JavaScript插件
1.模态框 <!--模态框经过了优化,更加灵活,以弹出对话框的形式出现,具有最小和最实用的功能集.--> <button type="button" class= ...
- QA面试题:之一(中英文题目、难度:简单)
QA面试题:之一(中英文题目.难度:简单)
- ClassNotFoundException: http.nio.NHttpClientEventHandle
解决方案是打开maven仓库中的jar包看看报错的类所对应版本的类存在不存在,若不存在就换个版本的jar包
- 孤荷凌寒自学python第六十二天学习mongoDB的基本操作并进行简单封装1
孤荷凌寒自学python第六十二天学习mongoDB的基本操作并进行简单封装1 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第八天. 今天开始学习mongoDB的简单操作, ...
- CSU-2214 Sequence Magic
题目链接 http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2214 题目 Description 有一个1到N的自然数序列1,2,3, ...
- Leetcode 659.分割数组为连续子序列
分割数组为连续子序列 输入一个按升序排序的整数数组(可能包含重复数字),你需要将它们分割成几个子序列,其中每个子序列至少包含三个连续整数.返回你是否能做出这样的分割? 示例 1: 输入: [1,2,3 ...
- React02
目录 React 进阶提升 条件渲染 受控组件* 状态提升* 组件数据流 TODO-LIST 设置服务器端口 列表渲染 条目PropTypes检查类型 export & import Refs ...
- HDU 4107 Gangster(线段树 特殊懒惰标记)
两种做法. 第一种:标记区间最大值和最小值,若区间最小值>=P,则本区间+2c,若区间最大值<P,则本区间+c.非常简单的区间更新. 最后发一点牢骚:最后query查一遍就行,我这个2B竟 ...
- DAO设计模式的理解
为了降低耦合性,提出了DAO封装数据库操作的设计模式. 它可以实现业务逻辑与数据库访问相分离.相对来说,数据库是比较稳定的,其中DAO组件依赖于数据库系统,提供数据库访问的接口. 一般的DAO的封装由 ...