Esempio n. 1
0
    def __init__(self):

        # 连接数据库
        self.con = pymysql.connect(host=conf.get("mysql", "host"),
                                   port=conf.getint("mysql", "port"),
                                   user=conf.get("mysql", 'user'),
                                   password=conf.get("mysql", "password"),
                                   charset="utf8")
        # 创建游标
        self.cur = self.con.cursor()
Esempio n. 2
0
    def user_register(self, case):

        # if "#phone#" in case.request_data:
        #     mcode = self.db.find_one("SELECT Fverify_code FROM sms_db_{}.t_mvcode_info_{} WHERE Fmobile_no={}"
        #                      .format(case.mobile[8:10], case.mobile[7], case.mobile))
        #     case.request_data = case.request_data.replace('#mcode#', mcode)
        #     case.request_data = case.request_data.replace('#phone#', case.mobile)
        #
        # else:
        #     case.request_data = data_replace(case.request_data)

        # 拼接url地址
        url = conf.get("env", "url") + case.url
        self.row = case.case_id + 1
        web_service = client.Client(url=url)
        data = eval(case.request_data)
        res = web_service.service.sendMCode(data)
        result = dict(res)
        if 'retCode' in str(result):
            result = {
                'retCode': result['retCode'],
                'retInfo': str(result['retInfo'])
            }
        else:
            # result = {'faultcode': result['faultcode'], 'faultstring': result['faultstring']}
            result = str(result)

        # 该打印的内容会显示在报告中
        print("请求数据--> {}".format(case.request_data))
        print("期望结果---> {}".format(case.expected_data))
        print("服务器响应数据--> {}".format(result))
        print("服务器响应数据类型:{}".format(type(result)))

        try:
            if 'retCode' in case.expected_data:
                self.assertEqual(eval(case.expected_data), result)
            else:
                self.assertEqual(case.expected_data, str(result))

        except AssertionError as e:
            result = 'FAIL'
            my_log.exception(e)  # 将异常信息记录到日志
            raise e
        else:
            result = 'PASS'
            my_log.debug("预期结果:%s, 实际结果:%s, 测试通过" %
                         (case.expected_data, str(result)))

        finally:
            self.wb.write_data(row=self.row, column=10, msg=result)
Esempio n. 3
0
def data_replace(data):
    """
    :param data: 用例的参数
    :return: 替换之后的结果
    """
    while re.search(p, data):
        key = re.search(p, data).group(1)
        try:
            value = conf.get("test_data", key)
        except:
            # value = getattr(ConText, "loanid")
            if "loanid" in data:
                value = getattr(ConText, "loanid")
            elif "phone1" in data:
                value = rand_phone(eval(data)["mobile"][6:9])  # 获取phone后面的手机号段
        data = re.sub(p, value, data, count=1)
    return data
Esempio n. 4
0
    def test_verify_user_auth(self, case):

        # 拼接url地址
        url = conf.get("env", "url") + case.url
        self.row = case.case_id + 1
        ws = WebRequests()
        response = ws.web_request(url=url, interface='verifyUserAuth', data=case.request_data)
        # 成功服务器响应数据{'retCode': 0, 'retInfo': ok},需将ok --> 'ok'
        if 'retCode' in str(response):
            result = {'retCode': response['retCode'], 'retInfo': str(response['retInfo'])}
        # 由于测试失败返回的数据特殊{'faultcode': soap:Server, 'faultstring': 手机号码错误},只能转换为str再来断言
        else:
            result = str(response)

        # 该打印的内容会显示在报告中
        print("请求数据--> {}".format(case.request_data))
        my_log.info("请求数据--> {}".format(case.request_data))

        print("期望结果--> {}".format(case.expected_data))
        my_log.info("期望结果--> {}".format(case.expected_data))

        print("服务器响应数据--> {}".format(response))
        my_log.info("服务器响应数据--> {}".format(response))

        try:
            # if 'retCode' in case.expected_data:
            #     self.assertEqual(eval(case.expected_data), result)
            # else:
            #     self.assertEqual(case.expected_data, str(result))
            self.assertEqual(eval(case.expected_data), response)

        except AssertionError as e:
            result = 'FAIL'
            my_log.exception(e)     # 将异常信息记录到日志
            raise e
        else:
            result = 'PASS'
            my_log.debug("断言结果:{}, 测试通过".format(result))

        finally:
            self.wb.write_data(row=self.row, column=8, msg=str(response))
            self.wb.write_data(row=self.row, column=9, msg=result)
Esempio n. 5
0
=================================


"""

import unittest
from library.HTMLTestRunnerNew import HTMLTestRunner
from custom.config import conf
from custom.constant import CASE_DIR, REPORT_DIR
from custom.send_email import SendEmail
import os
import time


_title = conf.get('report', 'title')
_description = conf.get('report', 'description')
_tester = conf.get('report', 'tester')
report_name = conf.get('report', 'report_name')
report_name = time.strftime("%Y%m%d%H%M%S", time.localtime()) + "_" + report_name


suite = unittest.TestSuite()  # 创建测试集合
loader = unittest.TestLoader()
suite.addTest(loader.discover(CASE_DIR))

file_path = os.path.join(REPORT_DIR, report_name)

with open(file_path, 'wb') as f:
    runner = HTMLTestRunner(
        stream=f,
Esempio n. 6
0

import unittest
from library.ddt import ddt, data
from custom.read_excel import ReadExcel
from custom.logger import my_log   # 可直接导入对象
from custom.config import conf
import os
from custom.constant import DATA_DIR
from custom.http_request import HTTPRequest2
from custom.execute_mysql import ExecuteMysql
from custom.web_request import WebRequests


# 从配置文件获取数据
file_name = conf.get('excel', 'file_name')
read_column = conf.get('excel', 'read_column')
read_column = eval(read_column)     # 将str转换成list


@ddt
class VerifyUserAuthTestCase(unittest.TestCase):

    # 拼接完整的excel路径,然后读取excel数据
    wb = ReadExcel(os.path.join(DATA_DIR, file_name), "verifyUserAuth")
    # wb = ReadExcel(os.path.join(DATA_DIR, file_name), "re")
    cases = wb.read_column_data(read_column)

    @classmethod
    def setUpClass(cls):
Esempio n. 7
0
"""

import unittest
from library.ddt import ddt, data
from custom.read_excel import ReadExcel
from custom.logger import my_log  # 可直接导入对象
from custom.config import conf
import os
from custom.constant import DATA_DIR
from custom.http_request import HTTPRequest2
from custom.execute_mysql import ExecuteMysql
from custom.tools import data_replace, rand_name, rand_ip
from custom.web_request import WebRequests

# 从配置文件获取数据
file_name = conf.get('excel', 'file_name')
read_column = conf.get('excel', 'read_column')
read_column = eval(read_column)  # 将str转换成list


@ddt
class UserRegisterTestCase(unittest.TestCase):

    # 拼接完整的excel路径,然后读取excel数据
    wb = ReadExcel(os.path.join(DATA_DIR, file_name), "userRegister")
    # wb = ReadExcel(os.path.join(DATA_DIR, file_name), "re")
    cases = wb.read_column_data(read_column)

    @classmethod
    def setUpClass(cls):
Esempio n. 8
0
E-mail:[email protected]

=================================


"""

import logging
from custom.config import conf
import os
from custom.constant import LOG_DIR

# 从配置文件中获取相关数据

log_name = conf.get('logs', 'logger_name')  # 日志收集器名称
level = conf.get('logs', 'level').upper()  # 收集信息级别,并转换成大写,增加容错机制
sh_level = conf.get('logs', 'sh_level').upper()  # 输出控制台级别
fh_level = conf.get('logs', 'fh_level').upper()  # 输出文件级别
log_file_path = conf.get('logs', 'log_file_path')


class MyLogging(object):
    def __new__(cls, *args, **kwargs):

        my_log = logging.getLogger(log_name)  # 创建日志收集器
        my_log.setLevel(level)  # 设置收集信息级别

        ls = logging.StreamHandler()  # 创建一个日志输出渠道,控制台
        ls.setLevel(sh_level)  # 设置输出级别
Esempio n. 9
0
class SendMCodeTestCase(unittest.TestCase):

    # 拼接完整的excel路径,然后读取excel数据
    wb = ReadExcel(os.path.join(DATA_DIR, file_name), "sendMCode")
    cases = wb.read_column_data(read_column)

    @classmethod
    def setUpClass(cls):

        my_log.info("======准备开始执行发送短信验证码接口的测试======")
        cls.request = HTTPRequest2()
        cls.db = ExecuteMysql()

    @classmethod
    def tearDownClass(cls):
        my_log.info("======发送短信验证码接口测试执行完毕======")
        cls.request.close()
        cls.db.close()

    @data(*cases)  # 拆包,拆成几个参数
    def test_send_m_code(self, case):

        # 替换成随机手机号码
        case.request_data = data_replace(case.request_data)

        # 替换成随机ip
        case.request_data = case.request_data.replace('$ip', rand_ip())

        # 拼接url地址
        url = conf.get("env", "url") + case.url
        self.row = case.case_id + 1

        # 调用封装好的webservice请求方法
        webs = WebRequests()
        response = webs.web_request(url=url,
                                    interface='sendMCode',
                                    data=case.request_data)

        # 用例失败则返回的键值不是str,会报错,需将值转换为str
        if 'faultcode' in response:
            response = {
                'faultcode': str(response.get('faultcode')),
                'faultstring': str(response.get('faultstring'))
            }

        # 该打印的内容会显示在报告中,以及日志
        print("请求参数--> {}".format(case.request_data))
        my_log.info('请求参数--> {}'.format(case.request_data))

        print("期望结果---> {}".format(case.expected_data))
        my_log.info("期望结果---> {}".format(case.expected_data))

        print("服务器响应数据--> {}".format(response))
        my_log.info("服务器响应数据--> {}".format(response))

        try:
            if 'retCode' in case.expected_data:
                self.assertEqual(eval(case.expected_data), response)
            else:
                self.assertEqual(case.expected_data, str(response))

        except AssertionError as e:
            result = 'FAIL'
            self.wb.write_data(row=self.row, column=9, msg=result)
            my_log.exception(e)  # 将异常信息记录到日志
            raise e
        else:
            result = 'PASS'
            my_log.info("断言结果--> {}, 测试通过".format(result))
        finally:
            self.wb.write_data(row=self.row, column=8,
                               msg=str(response))  # 只能写入str类型数据
            self.wb.write_data(row=self.row, column=9, msg=result)