Ejemplo n.º 1
0
    def __init__(self, cfname):
        self.data = ReadConfig("DB_CONFIG.ini")
        self.conn = pymysql.connect(
            host=self.data.get_db(cfname, "host"),
            user=self.data.get_db(cfname, "user"),
            password=self.data.get_db(cfname, "passwd"),
            charset="utf8",
            database=self.data.get_db(cfname, "dbname"),
            port=int(self.data.get_db(cfname, "port")),
            cursorclass=pymysql.cursors.DictCursor)

        self.cursor = self.conn.cursor()
Ejemplo n.º 2
0
#coding=utf-8
import os

from config.readconfig import ReadConfig

# Read configuration file
config_file_path = os.path.split(os.path.realpath(__file__))[0]
read_config = ReadConfig(os.path.join(config_file_path, 'config.ini'))
# Project parameter setting
prj_path = read_config.getValue('projectConfig', 'project_path')
# Log path
log_path = os.path.join(prj_path, 'report', 'log')
# Screenshot file path
img_path = os.path.join(prj_path, 'report', 'image')
#Exception screenshot file path
eximg_path = os.path.join(prj_path, 'report', 'exception_img')
#Test report path
report_path = os.path.join(prj_path, 'report', 'test_report')
#Upload the autoit file path
auto_path = os.path.join(prj_path, 'up_files', 'autoit_pic')
#
yaml_path = os.path.join(prj_path, 'config', 'readyaml')
# Default browser
browser = 'chrome'
# Test data path
data_path = os.path.join(prj_path, '', 'testdata')
Ejemplo n.º 3
0
 def __init__(self, robotname):
     filename = 'RobotConfig.ini'
     test = ReadConfig(filename)
     self.tokenurl = test.get_db(robotname, "tokenrul")
     self.secret = test.get_db(robotname, "secret")
     self.url = self.make_url()
Ejemplo n.º 4
0
class MyDbHelper(object):
    conn = None

    def __init__(self, cfname):
        self.data = ReadConfig("DB_CONFIG.ini")
        self.conn = pymysql.connect(
            host=self.data.get_db(cfname, "host"),
            user=self.data.get_db(cfname, "user"),
            password=self.data.get_db(cfname, "passwd"),
            charset="utf8",
            database=self.data.get_db(cfname, "dbname"),
            port=int(self.data.get_db(cfname, "port")),
            cursorclass=pymysql.cursors.DictCursor)

        self.cursor = self.conn.cursor()

    def close_db(self):
        self.cursor.close()
        self.conn.close()

    def insert(self, table, insert_data):
        """
        :param table:
        :param insert_data  type:[{},{}]:
        :return:effect_row 1 影响的行数
        """
        try:
            for data in insert_data:
                key = ','.join(data.keys())
                values = map(self._deal_values, data.values())
                insert_data = ', '.join(values)
                sql = "insert into {table}({key}) values ({val})".format(
                    table=table, key=key, val=insert_data)
                effect_row = self.__cursor.execute(sql)
                self.conn.commit()
                return effect_row
        except Exception as e:
            print(e)
        finally:
            # self.close_db()
            pass

    def delete(self, table, condition):
        """
        :param table:
        :param condition type{"":""}:
        :return effect_row 1 影响的行数:
        """
        condition_list = self._deal_values(condition)
        condition_data = ' and '.join(condition_list)
        sql = "delete from {table} where {condition}".format(
            table=table, condition=condition_data)
        effect_row = self.cursor.execute(sql)
        self.conn.commit()
        # self.close_db()
        return effect_row

    def update(self, table, data, condition=None):
        """
        :param table:
        :param data type 字典 {}:
        :param condition tpye 字典 {}:
        :return:
        """
        update_list = self._deal_values(data)
        update_data = ",".join(update_list)
        if condition is not None:
            condition_list = self._deal_values(condition)
            condition_data = ' and '.join(condition_list)
            sql = "update {table} set {values} where {condition}".format(
                table=table, values=update_data, condition=condition_data)
        else:
            sql = "update {table} set {values}".format(table=table,
                                                       values=update_data)
        effect_row = self.cursor.execute(sql)
        self.conn.commit()
        # self.close_db()
        return effect_row

    def select_id(self, table, id):
        """
        :param table:
        :param show_list type 列表 (字段):
        :param condition type 字典:
        :param get_one bool:
        :return:
        """
        sql = "select * from {table} where id = {id}".format(table=table,
                                                             id=id)
        self.cursor.execute(sql)
        result = self.cursor.fetchone()
        # self.close_db()
        if result:
            return result
        else:
            return None

    def select_some(self, table, filed, value):
        """
        :param table:
        :param show_list type 列表 (字段):
        :param condition type 字典:
        :return:
        """
        sql = "select * from {table} where {filed} = '{value}'".format(
            table=table, filed=filed, value=value)
        self.cursor.execute(sql)
        result = self.cursor.fetchall()
        # self.close_db()
        if result:
            return result
        else:
            return None

    def select_all(self, table):
        """
        :param table:
        :param show_list type 列表 (字段):
        :param condition type 字典:
        :return:
        """
        sql = "select * from {table}".format(table=table)
        self.cursor.execute(sql)
        result = self.cursor.fetchall()
        # self.close_db()
        if result:
            return result
        else:
            return None

    def query_sql(self, sql):
        self.cursor.execute(sql)
        result = self.cursor.fetchall()
        if result:
            return result
        else:
            return None

    def _deal_values(self, value):
        """
        self._deal_values(value) -> str or list
            处理传进来的参数
        """
        # 如果是字符串则加上''
        if isinstance(value, str):
            value = ("'{value}'".format(value=value))
        # 如果是字典则变成key=value形式
        elif isinstance(value, dict):
            result = []
            for key, value in value.items():
                value = self._deal_values(value)
                res = "{key}={value}".format(key=key, value=value)
                result.append(res)
            return result
        else:
            value = (str(value))
        return value

    def get_one(self, sql):
        result = None
        try:
            self.cursor.execute(sql)
            result = self.cursor.fetchone()
        except Exception as e:
            print(e)
        return result

    def get_all(self, sql):
        list_data = ()
        try:
            self.cursor.execute(sql)
            list_data = self.cursor.fetchall()
        except Exception as e:
            print(e)
        return list_data
Ejemplo n.º 5
0
import requests
from config.readconfig import ReadConfig

read_config = ReadConfig()


class ConfigHttp():
    def __init__(self, section, host, port, timeout):
        '''
        读取配置config.ini文件中的全局配置信息
        :param section 配置文件中【节】的名字
        :param host: 配置文件中name的名字
        :param port: 配置文件中name的名字
        :param timeout: 配置文件中name的名字
        '''
        self.host = read_config.get_config_value(section, host)
        self.port = read_config.get_config_value(section, port)
        self.timeout = read_config.get_config_value(section, timeout)
        self.headers = {}
        self.params = {}
        self.data = {}
        self.url = None
        self.files = {}
        self.log = Log.get_log()
        self.logger = self.log.get_logger()

    def set_url(self, url):
        '''拼接完整的接口测试地址'''
        self.url = self.host + url

    def set_headers(self, headers):
Ejemplo n.º 6
0
import os
from email.mime.text import MIMEText
from email.header import Header
from smtplib import SMTP_SSL
from email.mime.multipart import MIMEMultipart
from config.readconfig import ReadConfig
from datetime import datetime

# 将ReadConfig类的get_email_config方法赋值给变量read_config
read_config = ReadConfig().get_email_config


def send_report(file):
    '''发送测试报告'''
    with open(file, "rb") as f:
        mail_body = f.read()

    host_server = read_config("mail_host")
    user = read_config("mail_user")
    pwd = read_config("mail_pass")
    reciever = read_config("receiver")
    sender = read_config("sender")

    mail_title = read_config("subject")

    msg = MIMEMultipart()
    msg["Subject"] = Header(mail_title, "utf-8")
    msg["From"] = sender

    msg.attach(MIMEText(mail_body, "html", "utf-8"))