FasterRunner (httptunner+django)搭建以及小功能补充
配置
下载地址
https://github.com/httprunner/FasterRunner 后端配置
https://www.jianshu.com/p/e26ccc21ddf2 前端配置
https://www.cnblogs.com/luopan/p/10250485.html mac下安装RabbitMq
https://www.cnblogs.com/yihuihui/p/9095130.html 入口
http://localhost:8080/fastrunner/login
问题:
1. pycharm 创建的虚拟环境不能pip
https://www.jianshu.com/p/e46e36addf8d
2. pymysql/mysqlclient caching_sha2_password,
https://blog.csdn.net/weekdawn/article/details/81039382
django 1.8.2 mysql 加密方式 caching_sha2_password
django 2.0.3 mysql 加密方式 mysql_native_password
部分功能配置及补充
定时任务
1. setting.py
djcelery.setup_loader()
CELERY_ENABLE_UTC = True
CELERY_TIMEZONE = 'Asia/Shanghai'
# BROKER_URL = 'amqp://username:password@IP:5672//'
BROKER_URL = 'amqp://guest:guest@127.0.0.1:5672//'
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json' CELERY_TASK_RESULT_EXPIRES = 7200
CELERYD_CONCURRENCY = 1 if DEBUG else 5
CELERYD_MAX_TASKS_PER_CHILD = 40
2.定时服务
cd /home/conan/conan-ta/FasterRunner/
nohup python3 manage.py celery beat -l info >> /Users/zd/Documents/FasterRunner/logs/beat.log 2>&1 & cd /home/conan/conan-ta/FasterRunner/
celery multi start w1 -A FasterRunner -l info --logfile=/Users/zd/Documents/FasterRunner/logs/worker.log 2>&1 &
3.调试定时任务
更改定时相关逻辑时,需要关掉并重新启动celery beat,celery multi 才会生效,打印出来的调试信息在logs/worker.log下查看。
举例:定时任务,增加发送邮件的标题:
fastrunner/utils/task.py

fastrunner/task.py


发送邮件
setting.py
# 发邮件
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_SEND_USERNAME = 'no-reply@fenbi.com' # 定时任务报告发送邮箱,支持163,qq,sina,企业qq邮箱等,注意需要开通smtp服务
EMAIL_SEND_PASSWORD = '' # 邮箱密码
EMAIL_PORT = 25
EMAIL_USE_TLS = True
fastrunner/utils/email.py
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from FasterRunner.settings import EMAIL_SEND_USERNAME, EMAIL_SEND_PASSWORD def send_email_reports(receiver,save_summary,Cc=None,title=None):
receiver = receiver.rstrip(';')
all_receivers = receiver.split(';')
if '@sina.com' in EMAIL_SEND_USERNAME:
smtpserver = 'smtp.sina.com'
elif '@163.com' in EMAIL_SEND_USERNAME:
smtpserver = 'smtp.163.com'
else:
smtpserver = 'smtp.exmail.qq.com' if title:
subject = "【%s】接口自动化测试报告"%title
else:
subject = "接口自动化测试报告"
smtp = smtplib.SMTP_SSL(smtpserver, 465)
smtp.login(EMAIL_SEND_USERNAME, EMAIL_SEND_PASSWORD)
msg = MIMEText(save_summary, "html", "utf-8")
msg["Subject"] = Header(subject, "utf-8")
msg['From'] = Header('no-reply', 'utf-8')
msg['To'] = receiver
# 处理抄送
if Cc:
Cc = Cc.rstrip(';')
msg['Cc'] = Cc
all_receivers = receiver + ';' + Cc
all_receivers = all_receivers.split(';') smtp.sendmail(EMAIL_SEND_USERNAME, all_receivers, msg.as_string())
fastrunner/tasks.py
from fastrunner.utils.emails import send_email_reports
import time @shared_task
def schedule_debug_suite(*args, **kwargs):
"""定时任务
"""
print("定时任务start.....")
project = kwargs["project"]
receiver = kwargs["receiver"]
Cc = kwargs["copy"]
title = kwargs["name"] print("receiver****:%s"%receiver)
print("args****:%s"%args)
print("kwargs****:%s"%kwargs)
print("定时任务end.....")
receiver = receiver.strip()
Cc = Cc.strip() suite = []
test_sets = []
config_list = []
for pk in args:
try:
name = models.Case.objects.get(id=pk).name
suite.append({
"name": name,
"id": pk
})
except ObjectDoesNotExist:
pass for content in suite:
test_list = models.CaseStep.objects. \
filter(case__id=content["id"]).order_by("step").values("body") testcase_list = []
config = None
for content in test_list:
body = eval(content["body"])
if "base_url" in body["request"].keys():
config = eval(models.Config.objects.get(name=body["name"], project__id=project).body)
continue
testcase_list.append(body)
config_list.append(config)
test_sets.append(testcase_list) summary = debug_suite(test_sets, project, suite, config_list, save=False)
save_summary("", summary, project, type=3) # 整理数据
testTime = summary['time']['start_at']
testTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(testTime))
durTime = str(summary['time']['duration'])[:8] totalApi = summary['stat']['testsRun']
successApi = summary['stat']['successes']
FailApi = summary['stat']['failures']
errorApi = summary['stat']['errors']
skipApi = summary['stat']['skipped'] htmll = """
<table border="1" cellpadding="0" cellspacing="0" width="700px">
<tr style="background-color: #f8f8fa">
<th>测试时间</th>
<th>持续时间</th>
<th>Total</th>
<th>Success</th>
<th>Failed</th>
<th>Error</th>
<th>Skipped</th>
</tr>
<tr>
<td>%s</td>
<td>%s 秒</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>
</table>
<div style="height: 30px"></div>
<table border="1" cellpadding="0" cellspacing="0" width="700px">
<tr style="background-color: #f8f8fa">
<th>名称</th>
<th>请求地址</th>
<th>请求方法</th>
<th>响应时间(ms)</th>
<th>测试结果</th>
</tr>
""" % (
testTime, durTime, totalApi, successApi, FailApi, errorApi, skipApi
) # 名称/请求地址/请求方法/响应时间/测试结果
for i in summary['details']: # [{},{}]
detail = i['records'] # 列表
for d in detail:
name = d['name']
uurl = d['meta_data']['request']['url']
method = d['meta_data']['request']['method']
responseTime = d['meta_data']['response']['response_time_ms']
iresult = d['status'] htmll += """
<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s (ms)</td>
<td>%s</td>
</tr>
""" % (name, uurl, method, responseTime, iresult) htmll = htmll + '</table>' if Cc:
send_email_reports(receiver, htmll, Cc=Cc,title=title)
else:
send_email_reports(receiver, htmll,title=title)

启动/关闭 shell
start.sh
#!/bin/bash #启动 FasterWeb
echo -e "启动 FasterWeb"
cd /home/conan/conan-ta/FasterWeb/
nohup npm run build >> /home/shared/log/npm.log 2>&1 & # 启动 FasterRunner
echo -e "启动 FasterRunner"
cd /home/conan/conan-ta/FasterRunner/
nohup python3 manage.py runserver 0.0.0.0:9000 >> /home/shared/log/django.log 2>&1 & # 使用默认的celery.py启动
echo -e "启动celery beat"
cd /home/conan/conan-ta/FasterRunner/
nohup python3 manage.py celery beat -l info >> /Users/zd/Documents/FasterRunner/logs/beat.log 2>&1 & # 使用默认的celery.py启动
echo -e "启动 celery work"
cd /home/conan/conan-ta/FasterRunner/
celery multi start w1 -A FasterRunner -l info --logfile=/Users/zd/Documents/FasterRunner/logs/worker.log 2>&1 &
stop.sh
#!/bin/bash # kill django pid
echo -e "shutting down django pid"
pids=$(ps aux | grep "python" | grep "runserver" | awk '{print $2}')
for pid in $pids
do
kill -9 $pid
done # kill celery beat pid
echo -e "shutting down celery beat pid"
pids=$(ps aux | grep "celery" | grep "FasterRunner" | awk '{print $2}')
for pid in $pids
do
kill -9 $pid
done
FasterRunner (httptunner+django)搭建以及小功能补充的更多相关文章
- 用MVC5+EF6+WebApi 做一个小功能(三) 项目搭建
一般一个项目开始之前都会有启动会,需求交底等等,其中会有一个环节,大讲特讲项目的意义,然后取一个高大上的项目名字,咱这是一个小功能谈不上项目,但是名字不能太小气了.好吧,就叫Trump吧.没有任何含义 ...
- Django开发简单采集用户浏览器信息的小功能
Django开发简单采集用户浏览器信息的小功能 Centos环境准备 yum install –y python-pip export http_proxy=http://10.11.0.148:80 ...
- Django搭建博客网站(三)
Django搭建博客网站(三) 第三篇主要记录view层的逻辑和template. Django搭建博客网站(一) Django搭建博客网站(二) 结构 网站结构决定我要实现什么view. 我主要要用 ...
- Django-中间件-csrf扩展请求伪造拦截中间件-Django Auth模块使用-效仿 django 中间件配置实现功能插拔式效果-09
目录 昨日补充:将自己写的 login_auth 装饰装在 CBV 上 django 中间件 django 请求生命周期 ***** 默认中间件及其大概方法组成 中间件的执行顺序 自定义中间件探究不同 ...
- 从0到1搭建移动App功能自动化测试平台(2):操作iOS应用的控件
转自:http://debugtalk.com/post/build-app-automated-test-platform-from-0-to-1-Appium-interrogate-iOS-UI ...
- Django搭建简易博客
Django简易博客,主要实现了以下功能 连接数据库 创建超级用户与后台管理 利用django-admin-bootstrap美化界面 template,view与动态URL 多说评论功能 Markd ...
- Django搭建及源码分析(三)---+uWSGI+nginx
每个框架或者应用都是为了解决某些问题才出现旦生的,没有一个事物是可以解决所有问题的.如果觉得某个框架或者应用使用很不方便,那么很有可能就是你没有将其使用到正确的地方,没有按开发者的设计初衷来使用它,当 ...
- EBS OAF开发中的Java 实体对象(Entity Object)验证功能补充
EBS OAF开发中的Java 实体对象(Entity Object)验证功能补充 (版权声明,本人原创或者翻译的文章如需转载,如转载用于个人学习,请注明出处:否则请与本人联系,违者必究) EO理论上 ...
- Django 源码小剖: 初探 WSGI
Django 源码小剖: 初探 WSGI python 作为一种脚本语言, 已经逐渐大量用于 web 后台开发中, 而基于 python 的 web 应用程序框架也越来越多, Bottle, Djan ...
随机推荐
- python知识储备目录
1.with as 的实现原理 https://www.cnblogs.com/lice-blog/p/11581741.html 2.事务的四个隔离级别 3.rabitMQ 4.c3算法 5.wit ...
- [转帖]电源ac和dc有什么区别_dc ac分别代表什么
电源ac和dc有什么区别_dc ac分别代表什么 发表于 2017-10-28 17:18:58 电源设计应用 +关注 http://m.elecfans.com/article/571712.htm ...
- Python+request超时和重试
Python+request超时和重试 一.什么是超时? 1.连接超时 连接超时指的是没连接上,超过指定的时间内都没有连接上,这就是连接超时.(连接时间就是httpclient发送请求的地方开始到连接 ...
- (MVC — — Demo)客户管理系统的开发日志
点击一下 目录 第一步:搭建开发环境 第二步:层次包(按照三层架构思想写) 第四步:开发(utils)工具包 第四步:开发 Dao 层 第五步:开发 services 层 第六步:开发 factory ...
- 机器猫css
<html> <head> <title>机器猫</title> <style> div{ width: 30px; h ...
- JMM(Java内存模型)是什么?为什么使用并发?
1.计算机 首先我们需要讲解下计算机的模型:现代计算机模型是基于-冯诺依曼计算机模型 我们不用管输入和输出设备,最主要的就是中间计算器和存储器之间的交互,也就是CPU与主内存之间取数.存数. 大家会看 ...
- Python之random.seed()用法
import random # 随机数不一样 random.seed() print('随机数1:',random.random()) random.seed() print('随机数2:',rand ...
- Django(一)安装启动
Django下载/启动 1.下载安装 pip install django 或者 压缩文件下载地址:https://github.com/django/django/releases python s ...
- 怎样使用yum安装nginx
yum install -y nginx 以上.
- 计算两个坐标点的距离(高德or百度)
/// <summary> /// 获取两个坐标之间的距离 /// </summary> /// <param name="lat1">第一个坐 ...