Esempio n. 1
0
class TestRegister(unittest.TestCase):
    def setUp(self):
        self.rc = readConfig()
        self.read_path = self.rc.getstr(section='url', option='url')
        self.mylog = MyLog('register模块')


    @data(*data_case)
    def test_register(self,item):
        params = json.loads(item['params'])
        value = self.rc.getstr(section='register_phone', option='phone')
        if params['mobilephone'] == 'phone':
            params['mobilephone'] = value
        url = self.read_path + item['url']
        res = Request(method=item['method'], url=url, data=params)
        actual = res.get_txt()
        resp = res.get_json()
        try:
            self.assertEqual(actual, item['excepted'])
            if resp['msg'] == '注册成功':
                self.rc.setvalue('register_phone','phone',value=str(int(value)+1))
            result = 'Pass'
            self.mylog.debug('正在执行第{}个用例,测试参数: {},测试结果:{}'.format(item['caseid'],params,resp))
        except Exception as e:
            result = 'Filed'
            self.mylog.error('正在执行第{}个用例,测试参数: {},断言结果:{}'.format(item['caseid'], params, e))
            raise e
        finally:
            red.write_back(item['caseid']+1, 7,actual)
            red.write_back(item['caseid']+1 ,8,result)
Esempio n. 2
0
class TestLogin(unittest.TestCase):
    def setUp(self):
        self.mylog = MyLog('login模块测试')

    @data(*data_case)
    def test_logig(self, item):
        params = json.loads(DoRegex().replace(data=item['params']))
        url = readConfig().getstr('url', 'url') + item['url']
        resp = Request(url=url, method=item['method'], data=params)
        actual = resp.get_txt()
        try:
            self.assertEqual(actual, item['excepted'])
            self.mylog.debug('正在执行第{}个用例,测试参数: {},测试结果:{}'.format(item['caseid'], params, actual))
            result = 'Pass'
        except AssertionError as e:
            result = 'Filed'
            self.mylog.error('正在执行第{}个用例,测试参数: {},断言结果:{}'.format(item['caseid'], params, e))
            raise e
        finally:
            re.write_back(row=item['caseid'] + 1, column=7, value=actual)
            re.write_back(row=item['caseid'] + 1, column=8, value=result)
Esempio n. 3
0
class MySql:
    def __init__(self):
        self.mylog = MyLog('Sql查询')
        self.conf = readConfig()
        host = self.conf.getstr('mysql', 'host')
        user = self.conf.getstr('mysql', 'user')
        password = self.conf.getstr('mysql', 'pwd')
        port = self.conf.getint('mysql', 'port')
        cursorclass = pymysql.cursors.DictCursor
        self.mysql = pymysql.connect(host=host,
                                     user=user,
                                     password=password,
                                     port=port,
                                     cursorclass=cursorclass)

    def fet_one(self, sql):
        cursor = self.mysql.cursor()
        try:
            cursor.execute(sql)
            res = cursor.fetchone()
            self.mylog.debug('sql语句:{},数据查询结果:{}'.format(sql, res))
            self.mysql.close()
        except Exception as e:
            self.mylog.error('数据库查询出错啦!!【error】:{}'.format(e))
            raise e
        return res

    def fet_all(self, sql):
        cursor = self.mysql.cursor()
        try:
            cursor.execute(sql)
            res = cursor.fetchall()
            self.mylog.debug('sql语句:{},数据查询结果:{}'.format(sql, res))
            self.mysql.close()
        except Exception as e:
            self.mylog.error('数据库查询出错啦!!【error】:{}'.format(e))
            raise e
        return res
Esempio n. 4
0
class TestRecharge(unittest.TestCase):
    def setUp(self):
        self.read_path = readConfig().getstr(section='url', option='url')
        self.rc = readConfig()
        self.mylog = MyLog('recharge模块')

    @data(*data_case)
    def test_recharge(self, item):
        '''通过反射查看是否有COOKIES的值'''
        if hasattr(contex, 'COOKIES'):
            COOKIES = getattr(contex, 'COOKIES')
        else:
            COOKIES = None
        print('COOKIES:', COOKIES)
        params = json.loads(DoRegex().replace(item['params']))
        url = self.read_path + item['url']
        resp = Request(url=url,
                       method=item['method'],
                       data=params,
                       cookies=COOKIES)
        if resp.cookies():
            setattr(contex, 'COOKIES', resp.cookies())
        actual = resp.get_txt()
        try:
            self.assertEqual(actual, item['excepted'])
            self.mylog.debug('正在执行第{}个用例,测试参数: {},测试结果:{}'.format(
                item['caseid'], params, actual))
            result = 'Pass'
        except AssertionError as e:
            result = 'Filed'
            self.mylog.error('正在执行第{}个用例,测试参数: {},断言结果:{}'.format(
                item['caseid'], params, e))
            raise e
        finally:
            red.write_back(row=item['caseid'] + 1, column=7, value=actual)
            red.write_back(row=item['caseid'] + 1, column=8, value=result)
Esempio n. 5
0
class readExcel:
    def __init__(self, filename, sheetname):
        self.mylog = MyLog('Excel读写')
        self.filename = filename
        self.sheetname = sheetname
        self.read_conf = readConfig().getother('Testconf', 'module')

    def do_excel(self):
        try:
            wb = load_workbook(filename=self.filename)
            self.mylog.debug('====打开Excel====')
        except FileNotFoundError as e:
            self.mylog.error('打开Excel错误{}'.format(e))
            raise e
        try:
            sheet = wb[self.sheetname]
            self.mylog.debug('====打开Sheet====')
        except KeyError as e:
            self.mylog.error('打开Sheet错误{}'.format(e))
            raise e

        if self.sheetname in self.read_conf:
            list = []
            for i in range(2, sheet.max_row + 1):
                dict = {}
                for j in range(1, sheet.max_column + 1):
                    dict[sheet.cell(1, j).value] = sheet.cell(i, j).value
                list.append(dict)
            return list

    def write_back(self, row, column, value):
        wb = load_workbook(filename=self.filename)
        sheet = wb[self.sheetname]
        sheet.cell(row, column).value = value
        wb.save(self.filename)
        wb.close()