基于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. 官 ...
随机推荐
- Jenkins拾遗--第五篇-git插件填坑
Jenkins使用过程中,大部分Job的第一项就行从源码库里签出代码.由于git越来越流行,所以,稍微新一些的项目的源码管理都是基于git的.对应的,jenkins的git plugin几乎是大部分j ...
- 剑指Offer - 九度1515 - 打印1到最大的N位数
剑指Offer - 九度1515 - 打印1到最大的N位数2013-11-30 01:11 题目描述: 给定一个数字N,打印从1到最大的N位数. 输入: 每个输入文件仅包含一组测试样例.对于每个测试案 ...
- 超链接标签的CSS伪类link,visited,hover,active
CSS伪类,是一种特殊的类,它针对到CSS选择器起作用,使选中的标签或元素产生特定的效果. CSS伪类的语法就是: 选择器 : 伪类名 { 属性 : 属性值 } 用的最多的伪类就是超链接a的伪类,有: ...
- CSS简易学习笔记
学习地址:http://www.w3school.com.cn/css/index.asp cnblog不能把格式复制上来,有格式文字版:https://github.com/songzhenhua/ ...
- 深入MySQL用户自定义变量:使用详解及其使用场景案例
一.前言 在前段工作中,曾几次收到超级话题积分漏记的用户反馈.通过源码的阅读分析后,发现问题出在高并发分布式场景下的计数器上.计数器的值会影响用户当前行为所获得积分的大小.比如,当用户在某超级话题下连 ...
- c++知识点总结--友元&运算符重载
友元函数(不属于类) 可以访问类的私有变量,以及私有函数 友元函数在类内声明需要friend关键字,类外定义就不需要 友元函数可以直接在类内定义 友元函数必须包含对象指针 友元类(不适用继承,只适 ...
- CodeForces C. Maximal Intersection
http://codeforces.com/contest/1029/problem/C You are given nn segments on a number line; each endpoi ...
- ocrosoft Contest1316 - 信奥编程之路~~~~~第三关 问题 K: 大整数加法
http://acm.ocrosoft.com/problem.php?cid=1316&pid=10 题目描述 求两个不超过200位的非负整数的和. 输入 有两行,每行是一个不超过200 ...
- jQuery选择器之全选择器(*选择器)
在css中,经常会在第一行写下这样一段样式: * { margin:; padding:; } 通配符*意味着给所有的元素设置默认的边距.jQuery中我们也可以通过传递*选择器来选中文档页面中的元素 ...
- NetScaler Active-Active模式
NetScaler Active-Active模式 NetScaler Active-Active模式 (此文档基于版本:NS9.3: Build 55.6 nc) By ShingTan Activ ...