基于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. 官 ...
随机推荐
- 《Cracking the Coding Interview》——第9章:递归和动态规划——题目4
2014-03-20 03:08 题目:给定一个集合,返回其幂集. 解法:DFS. 代码: // 9.4 Return all subsets of a set #include <cstdio ...
- 设计模式之第22章-组合模式(Java实现)
设计模式之第22章-组合模式(Java实现) “鱼哥,有没有什么模式是用来处理树形的“部分与整体”的层次结构的啊.”“当然”“没有?”“有啊.别急,一会人就到了.” 组合模式之自我介绍 “请问你是?怎 ...
- selenium初识(一)
Selenium是一个开源的便携式的自动化软件测试工具,用于测试web应用程序.有能力在不同浏览器和操作系统运行.它是一套工具,帮助我们有效地给予web应用程序的自动化. Selenium分为以下几个 ...
- navmesh自动寻路
一个导航网格(也就是Navmesh)是世界几何体简化的表示法,被游戏代理用于在世界中进行导航.通常,代理(agent )有一个目标,或一个目的地,它试图找到一个路径,然后沿路径导航到达目标.这个过程被 ...
- sqlalchemy 查询姿势总结
sqlalchemy查询使用 1.带条件查询 查询是最常用的,对于各种查询我们必须要十分清楚,首先是带条件的查询 #带条件查询 rows = session.query(User).filter_by ...
- Spring Boot多数据源配置(一)durid、mysql、jpa整合
目前在做一个统计项目.需要多数据源整合,其中包括mysql和mongo.本节先讲mysql.durid.jpa与spring-boot的整合. 引入Durid包 <dependency> ...
- cloud-init代码调试方法
新做的centos7.4镜像的cloud-init安装好之后,修改密码失败,但是同样的配置文件在7.2上的是正常的,对比了一下版本,centos7.4上的是0.7.9,7.2上的是0.7.5,经过调试 ...
- Hibernate 查询方法
1.简单查询: public User select(User user) { User newUser; try { newUser = (User) session.get(User.class, ...
- nodejs & docker
nodejs & docker https://github.com/xgqfrms-GitHub/Node.js/blob/master/Docker-Nodejs/translation. ...
- Python中的多线程编程,线程安全与锁(二)
在我的上篇博文Python中的多线程编程,线程安全与锁(一)中,我们熟悉了多线程编程与线程安全相关重要概念, Threading.Lock实现互斥锁的简单示例,两种死锁(迭代死锁和互相等待死锁)情况及 ...