配置

下载地址
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)搭建以及小功能补充的更多相关文章

  1. 用MVC5+EF6+WebApi 做一个小功能(三) 项目搭建

    一般一个项目开始之前都会有启动会,需求交底等等,其中会有一个环节,大讲特讲项目的意义,然后取一个高大上的项目名字,咱这是一个小功能谈不上项目,但是名字不能太小气了.好吧,就叫Trump吧.没有任何含义 ...

  2. Django开发简单采集用户浏览器信息的小功能

    Django开发简单采集用户浏览器信息的小功能 Centos环境准备 yum install –y python-pip export http_proxy=http://10.11.0.148:80 ...

  3. Django搭建博客网站(三)

    Django搭建博客网站(三) 第三篇主要记录view层的逻辑和template. Django搭建博客网站(一) Django搭建博客网站(二) 结构 网站结构决定我要实现什么view. 我主要要用 ...

  4. Django-中间件-csrf扩展请求伪造拦截中间件-Django Auth模块使用-效仿 django 中间件配置实现功能插拔式效果-09

    目录 昨日补充:将自己写的 login_auth 装饰装在 CBV 上 django 中间件 django 请求生命周期 ***** 默认中间件及其大概方法组成 中间件的执行顺序 自定义中间件探究不同 ...

  5. 从0到1搭建移动App功能自动化测试平台(2):操作iOS应用的控件

    转自:http://debugtalk.com/post/build-app-automated-test-platform-from-0-to-1-Appium-interrogate-iOS-UI ...

  6. Django搭建简易博客

    Django简易博客,主要实现了以下功能 连接数据库 创建超级用户与后台管理 利用django-admin-bootstrap美化界面 template,view与动态URL 多说评论功能 Markd ...

  7. Django搭建及源码分析(三)---+uWSGI+nginx

    每个框架或者应用都是为了解决某些问题才出现旦生的,没有一个事物是可以解决所有问题的.如果觉得某个框架或者应用使用很不方便,那么很有可能就是你没有将其使用到正确的地方,没有按开发者的设计初衷来使用它,当 ...

  8. EBS OAF开发中的Java 实体对象(Entity Object)验证功能补充

    EBS OAF开发中的Java 实体对象(Entity Object)验证功能补充 (版权声明,本人原创或者翻译的文章如需转载,如转载用于个人学习,请注明出处:否则请与本人联系,违者必究) EO理论上 ...

  9. Django 源码小剖: 初探 WSGI

    Django 源码小剖: 初探 WSGI python 作为一种脚本语言, 已经逐渐大量用于 web 后台开发中, 而基于 python 的 web 应用程序框架也越来越多, Bottle, Djan ...

随机推荐

  1. windows7-maven配置

    1.确认jdk安装 2.下载 3.解压缩 4.配置环境变量 (1)计算机属性--高级系统配置--高级--环境变量---系统变量--新建 (2)添加环境变量 MAVEN_HOME PATH中添加到mav ...

  2. 使用C++11原子量实现自旋锁

    一.自旋锁 自旋锁是一种基础的同步原语,用于保障对共享数据的互斥访问.与互斥锁的相比,在获取锁失败的时候不会使得线程阻塞而是一直自旋尝试获取锁.当线程等待自旋锁的时候,CPU不能做其他事情,而是一直处 ...

  3. 对于大于等于3的整数n,在区间【n,3/2 * n】中一定存在一个素数

    对于大于3的整数n,在区间[n,3/2 * n]中一定存在一个素数

  4. [CF429E]Points ans Segments_欧拉回路

    Points and Segments 题目链接:www.codeforces.com/contest/429/problem/E 注释:略. 题解: 先离散化. 发现每个位置如果被偶数条线段覆盖的话 ...

  5. [转帖]NTLM说明

    [思路/技术]Windows认证 | 网络认证     来源:https://bbs.ichunqiu.com/thread-53598-1-1.html   圣乱X无心i春秋-核心白帽 发表于 5  ...

  6. class.forName 和 classLoader的区别

    Java中的Class.forName()和ClassLoader都可以用来对类进行加载.Class.forName()除了将类的.class文件加载到JVM中 还会对类进行解释,执行类中的stati ...

  7. Win10修改字体

    先将自己喜欢的字体下载下来. 把自己喜欢的字体下载之后,一般会是一个压缩包,将其解,格式是ttf. 点击解压后的字体文件,将其安装在windows系统之中. 键盘上先按住win,在按R,出现一个窗口, ...

  8. java CGLib代理

    转载自   cglib之Enhancer 1. 背景 cglib库的Enhancer在Spring AOP中作为一种生成代理的方式被广泛使用.本文针对Enhancer的用法以实际代码为例作一些介绍. ...

  9. 【AtCoder】AGC007

    AGC007 A - Shik and Stone 如果i + j走过的格子只有一个,那么就是可以走到 #include <bits/stdc++.h> #define fi first ...

  10. 虚拟机(VM)安装openwrt-koolshare软路由

    ⒈创建虚拟机 **软路由选择Windows操作系统,因为我们需要在PE环境中进行软路由的写入,固件类型选择BIOS,网络类型选择使用仅主机模式网络,虚拟磁盘类型选择IDE[一定要选择IDE模式],SC ...