网上找了一下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. 剑指Offer - 九度1518 - 反转链表

    剑指Offer - 九度1518 - 反转链表2013-11-30 03:09 题目描述: 输入一个链表,反转链表后,输出链表的所有元素.(hint : 请务必使用链表) 输入: 输入可能包含多个测试 ...

  2. 《Cracking the Coding Interview》——第3章:栈和队列——题目3

    2014-03-18 05:17 题目:设计一个栈,这个栈实际上由一列子栈组成.每当一个子栈的大小达到n,就新产生下一个子栈.整个栈群对外看起来就像普通栈一样,支持取顶top().压入push().弹 ...

  3. shell脚本获取网页快照并生成缩略图

    获取网页快照并生成缩略图可分两步进行: 1.获取网页快照 2.生成缩略图 获取网页快照 这里我们用 phantomjs 来实现.关于 phantomjs 的详细用法可参考官方网站. 1.安装 我的环境 ...

  4. 【Merge Intervals】cpp

    题目: Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6], ...

  5. excel批量导入

    https://www.cnblogs.com/mingyue1818/p/4828865.html

  6. isinstance()判断数据类型

    判断数据类型isinstance()l=[1,2,3]print(isinstance(l,list))#括号里面第一个填需要判断的数据,第二个是判断条件

  7. Python 自学 Day1

    作业二:编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 #!/usr/bin/env python import getpass def log(): uname = input ...

  8. day04_08-while查询所有行

    <?php $link = @mysql_connect('localhost','root',''); mysql_query('use test',$link); mysql_query(' ...

  9. sharePreference的几个重点

    一.  SharePreferences是用来存储一些简单配置信息的一种机制,使用Map数据结构来存储数据,以键值对的方式存储,采用了XML格式将数据存储到设备中,文件存放在/data/data/&l ...

  10. 【Python】- yield 使用浅析

    您可能听说过,带有 yield 的函数在 Python 中被称之为 generator(生成器),何谓 generator ? 我们先抛开 generator,以一个常见的编程题目来展示 yield ...