示例#1
0
class changsheng(unittest.TestCase):
    log = Log()
    log.info("长生项目电子投保测试开始")
    @classmethod
    def setUpClass(cls):
        cls.log.info("开始初始化浏览器.....")
        option = webdriver.ChromeOptions()
        # option.add_argument('headless')  # 静默执行,不打开浏览器
        option.add_argument('disable-infobars')  # 取消打开浏览器时候提示‘被自动化控制’等字体
        cls.driver = webdriver.Chrome()   # 实例化浏览器
        cls.driver.implicitly_wait(20)   # 隐式等待
        cls.driver.get("http://tstmobile.gwcslife.com/NGLife/")
        cls.driver.maximize_window()  # 最大化浏览器

    testdata = testDataMap()  # 实例化读取Excel数据操作
    @ddt.data(*testdata)
    def test_01(self,data):
        self.log.info('------登录-------')
        self.log.info('输入账号密码,开始登录.........................................')
        LoginAction.login(self.driver, data['userName'], data['passWord'])  # 调用登录的方法
        self.assertEqual('长生销售支持系统', self.driver.title, '用例执行成功')  # Excel中的预期结果和页面信息作比较
        self.log.info('账号:%s,密码:%s' % (data['userName'], data['passWord']))
        self.log.info('登录操作结束..................................................')
        self.log.info('用例执行成功')
    @classmethod
    def tearDownClass(cls):
        cls.driver.close()
示例#2
0
文件: helpers.py 项目: VaneCloud/kree
def get_job_details(task_id):
    log = Log.getLogger(__name__ + '.get_job_details')
    log.debug("Entering get job detailes function.")
    rds = Rds("job-" + task_id)
    job_details = rds.getter()
    #  job_details = eval_json_data(job_details)
    return job_details
示例#3
0
def get_raw_log_output(task_id):
    log = Log.getLogger(__name__ + '.get_raw_log_output')
    log.debug("Starting to get raw log output.")
    raw_log_output = []
    raw_log_filehandler = app.config['STDOUT_DIR'] + '/' + task_id + '.log'
    fh = open(raw_log_filehandler, 'r')
    for line in fh.readlines():
        raw_log_output.append(line)
    log.debug("Raw log output: %s" % raw_log_output)
    return raw_log_output
示例#4
0
def parse_raw_log_output(raw_log_output):
    log = Log.getLogger(__name__ + '.parse_raw_log_output')
    log.debug("Starting parse raw log output to JSON format.")
    log_pointer_len = len(raw_log_output)
    for log_pointer in range(0, log_pointer_len):
        log.debug(raw_log_output[log_pointer])
        if re.match("^TASK:", raw_log_output[log_pointer]):
            log.debug("Match: raw_log_output[log_pointer]")
            for log_pointer_inner in range(log_pointer, log_pointer_len):
                pass
示例#5
0
def get_job_details(task_id):
    log = Log.getLogger(__name__ + '.get_job_details')
    log.debug("Entering get job detailes function.")
    rds = Rds("job-" + task_id)
    job_details = rds.getter()
    #  job_details = eval_json_data(job_details)
    #  from celery.contrib.rdb import set_trace
    #  set_trace()
    # fix result is running while job has already finished issue
    if job_details['task_state'] == 'finished' and job_details[
            'result'] == 'running':
        job_details['result'] = 'failed'
    return job_details
示例#6
0
文件: routes.py 项目: VaneCloud/kree
 def post(self, task_id):
     log = Log.getLogger(__name__ + ".Callback.post")
     data = {}
     data = request.get_json()
     queue = Rds('job-' + task_id)
     log.debug(queue._key_name)
     queue_data = queue.getter()
     step_result_id = len(queue_data['step_result']) + 1
     queue_data['step_result'][step_result_id] = data
     queue_data['update_time'] = data['timestamp']
     if data.has_key('result'):
         queue_data['result'] = data['result']
     queue.setter(queue_data)
     log.debug("Task event updated from callback: %s %s" %
               (task_id, json.dumps(queue_data)))
def make_celery(app):
    #  celery = Celery('kree', broker=app.config['CELERY_BROKER_URL'], backend=app.config['CELERY_BROKER_URL'])
    celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'], backend=app.config['CELERY_BROKER_URL'])
    celery.conf.update(app.config)
    TaskBase = celery.Task

    class ContextTask(TaskBase):
        abstract = True

        def __call__(self, *args, **kwargs):
            with app.app_context():
                return TaskBase.__call__(self, *args, **kwargs)

    celery.Task = ContextTask
    log = Log.getLogger(__name__)
    log.info("Task scheduling system initiald.")
    return celery
示例#8
0
#!/usr/bin/env python
# encoding: utf-8

from queue import Rds
from celery import task
from config.logger import Log
from tools.path_utils import get_playbooks_dir
from main import app
import ast
import re
import datetime

log = Log.getLogger(__name__)


class Time(object):
    def __new__(cls):
        return datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S')


def get_playbooks_list():
    return get_playbooks_dir()


def get_job_details(task_id):
    log = Log.getLogger(__name__ + '.get_job_details')
    log.debug("Entering get job detailes function.")
    rds = Rds("job-" + task_id)
    job_details = rds.getter()
    #  job_details = eval_json_data(job_details)
    #  from celery.contrib.rdb import set_trace
示例#9
0
文件: routes.py 项目: VaneCloud/kree
 def get(self, task_id):
     log = Log.getLogger(__name__ + ".Callback.get")
     queue = Rds('job-' + task_id)
     queue_data = queue.getter()
     log.debug("Task event callback called: %s %s" %
               (task_id, json.dumps(queue_data)))
示例#10
0
class Email:
    log = Log()

    def __init__(self,
                 server,
                 sender,
                 password,
                 receiver,
                 title,
                 message=None,
                 path=None):
        """初始化Email
        :param title: 邮件标题,必填。
        :param message: 邮件正文,非必填。
        :param path: 附件路径,可传入list(多附件)或str(单个附件),非必填。
        :param server: smtp服务器,必填。
        :param sender: 发件人,必填。
        :param password: 发件人密码,必填。
        :param receiver: 收件人,多收件人用“;”隔开,必填。
        """
        self.title = title
        self.message = message
        self.files = path
        self.msg = MIMEMultipart('related')
        self.server = server
        self.sender = sender
        self.receiver = receiver
        self.password = password

    def _attach_file(self, att_file):
        """将单个文件添加到附件列表中"""
        att = MIMEText(open('%s' % att_file, 'rb').read(), 'plain', 'utf-8')
        att["Content-Type"] = 'application/octet-stream'
        file_name = re.split(r'[\\|/]', att_file)
        att["Content-Disposition"] = 'attachment; filename="%s"' % file_name[-1]
        self.msg.attach(att)
        self.log.info('attach file {}'.format(att_file))

    def send(self):
        self.msg['Subject'] = self.title
        self.msg['From'] = self.sender
        self.msg['To'] = self.receiver
        # 邮件正文
        if self.message:
            self.msg.attach(MIMEText(self.message))
        # 添加附件,支持多个附件(传入list),或者单个附件(传入str)
        if self.files:
            if isinstance(self.files, list):
                for f in self.files:
                    self._attach_file(f)
            elif isinstance(self.files, str):
                self._attach_file(self.files)

        # 连接服务器并发送
        try:
            smtp_server = smtplib.SMTP(self.server)  # 连接sever
        except (gaierror and error) as e:
            self.log.error('发送邮件失败,无法连接到SMTP服务器,检查网络以及SMTP服务器. %s', e)
        else:
            try:
                smtp_server.login(self.sender, self.password)  # 登录
            except smtplib.SMTPAuthenticationError as e:
                self.log.error('用户名密码验证失败!%s', e)
            else:
                smtp_server.sendmail(self.sender, self.receiver.split(';'),
                                     self.msg.as_string())  # 发送邮件
            finally:
                smtp_server.quit()  # 断开连接
                self.log.info('发送邮件"{0}"成功! 收件人:{1}。如果没有收到邮件,请检查垃圾箱,'
                              '同时检查收件人地址是否正确'.format(self.title,
                                                     self.receiver))