博主最近开始优化之前的API接口自动化框架,这次打算使用django框架来完成
1 # -*- coding: utf-8 -*- 2 from __future__ import unicode_literals 3 from datetime import datetime 4 from django.db import models 5 from django.utils import timezone 6 7 8 # Create your models here. 9 10 11 # Api接口分类 12 class Module(models.Model): 13 module_name = models.CharField(max_length=30) 14 15 def __unicode__(self): 16 return self.module_name 17 18 19 # Api接口详情 20 class Main(models.Model): 21 module = models.ForeignKey(Module) 22 main_name = models.CharField(max_length=30) 23 # Api的方法 post、get、delete 24 main_method = models.CharField(max_length=30) 25 main_url = models.CharField(max_length=30) 26 # Api的传参类型 json、data 27 main_type = models.CharField(max_length=30) 28 29 def __unicode__(self): 30 return self.main_name 31 32 33 # Api接口用例 34 class Case(models.Model): 35 main = models.ForeignKey(Main) 36 case_name = models.CharField(max_length=1024, null=True) 37 case_doc = models.CharField(max_length=1024, null=True) 38 env = models.TextField(null=True) 39 url = models.CharField(max_length=30) 40 general_param = models.TextField(null=True) 41 request_param = models.TextField(null=True) 42 response_param = models.TextField(null=True) 43 path = models.CharField(max_length=30) 44 45 def __unicode__(self): 46 return self.case_doc 47 48 # # Api用例执行记录 49 # class Record(models.Model): 50 # record_name = models.CharField(max_length=64) 51 # record_user = models.CharField(max_length=64) 52 # result = models.CharField(max_length=64) 53 # path = models.CharField(max_length=256) 54 # # auto_now_add=True 第一次创建当前时间、 修改不更新 55 # record_time = models.DateTimeField(auto_now_add=True) 56 # 57 # def __unicode__(self): 58 # return self.record_name
设计的思路:展示API的分类,下面是每一个API接口,然后打开是接口下所有测试用例
这里的用例详情包括 用例名称,环境,公共参数,请求参数,返回参数,
最后是用例的执行记录情况,文件可以下载