Exemplo n.º 1
0
class LoginCase(unittest.TestCase):
    excel = openexcel.DoExcel(contants.case_file, 'login')
    cases = excel.read()

    def setUp(self):
        logger.info('准备测试前置')
        self.http_request= HttpCookies()
        self.context=Context()
        warnings.simplefilter("ignore", ResourceWarning)

    @data(*cases)
    @unpack
    def test_login(self,url,method,data,expected,case_id,title,result,check_sql):
        logger.info('开始测试:{0}'.format(title))
        data = self.context.replace(json.dumps(data))  #转换成str
        resp=self.http_request.http_request(url,json.loads(data),method)# 实际值 ,data,转换成json
        resp2=json.dumps(resp,ensure_ascii=False) #转换成字符串
        logger.info('请求是:{}'.format(data))
        # print('''用例编号{},用例标题{}'''.format(case_id,title))
        try:
            self.assertEqual(expected,resp)
            result='PASS'
        except AssertionError as e:
            result = 'FALSE'
            logger.error("报错了,{0}".format(e))
            raise e
        finally:
            logger.info('响应结果是:{}'.format(result))
            self.excel.write(int(case_id) + 1, resp, result)

    def tearDown(self):
        logger.info('测试后置处理')
Exemplo n.º 2
0
class InvestCase(unittest.TestCase):
    excel = openexcel.DoExcel(contants.case_file, 'invest')
    cases = excel.read()
    @classmethod
    def setUpClass(cls):
        cls.http_request= HttpSessions()
        logger.info('准备测试前置')
        cls.context=Context()
        cls.mysql=DoMysql()
        warnings.simplefilter("ignore", ResourceWarning)


    @data(*cases)
    @unpack
    def test_invest(self,url,method,data,expected,case_id,title,result,check_sql):
        data = self.context.replace(json.dumps(data))
        logger.info('用例标题是:{}'.format(title))
        logger.info('请求是:{}'.format(data))
        if title=='投资人正常投资' and check_sql is not None:
            sql = eval(check_sql)['sql1']
            member = self.mysql.fetch_one(sql)
            print(member['leaveamount'])
            before = member['leaveamount']
            print(before)
        resp=self.http_request.http_request(method,url,json.loads(data))# 实际值
        resp2=json.loads(resp)['code']#转换成字符串
        resp3=json.loads(resp)['msg']
        try:
            self.assertEqual(expected,int(resp2))
            result = 'PASS'
            if resp3 == "加标成功" and check_sql is not None:
                sql = eval(check_sql)['sql2']
                loan_id = self.mysql.fetch_one(sql)['id']
                print('标的ID:', loan_id)
                # 保存到类属性里面
                setattr(Context, "loan_id", str(loan_id))
            if resp3 == "竞标成功" and check_sql is not None:
                sql = eval(check_sql)['sql1']
                member = self.mysql.fetch_one(sql)
                print(member['leaveamount'])
                after = member['leaveamount']#剩余金额
                print(after)
                recharge_amount = int(json.loads(data)['amount'])  # 竞标金额
                print(recharge_amount)
                self.assertEqual(before , after)
        except AssertionError as e:
            result = 'FALSE'
            logger.error("报错了,{0}".format(e))
            raise e
        finally:
            logger.info('响应结果是:{}'.format(result))
            self.excel.write(int(case_id) + 1, resp, result)
    @classmethod
    def tearDownClass(cls):
        logger.info('测试后置处理')
        cls.http_request.close()
Exemplo n.º 3
0
class RechargeCase(unittest.TestCase):
    excel = openexcel.DoExcel(contants.case_file, 'recharge')
    cases = excel.read()

    @classmethod
    def setUpClass(cls):
        logger.info('准备测试前置')
        cls.http_request = HttpSessions()
        cls.context = Context()
        cls.mysql = DoMysql()
        warnings.simplefilter("ignore", ResourceWarning)

    @data(*cases)
    @unpack
    def test_recharge(self, url, method, data, expected, case_id, title,
                      result, check_sql):
        data = self.context.replace(json.dumps(data))
        logger.info('开始测试:{0}'.format(title))
        logger.info('请求是:{}'.format(data))
        if check_sql is not None:
            sql = eval(check_sql)['sql1']
            member = self.mysql.fetch_one(sql)
            print(member['leaveamount'])
            before = member['leaveamount']
        resp = self.http_request.http_request(method, url,
                                              json.loads(data))  # 实际值
        resp2 = json.loads(resp)['code']  #转换成字符串
        try:
            self.assertEqual(expected, int(resp2))
            result = 'PASS'
            if check_sql is not None:
                sql = eval(check_sql)['sql1']
                member = self.mysql.fetch_one(sql)
                print(member['leaveamount'])
                after = member['leaveamount']
                recharge_amount = int(json.loads(data)['amount'])  # 充值金额
                self.assertEqual(before + recharge_amount, after)
        except AssertionError as e:
            result = 'FALSE'
            logger.error("报错了,{0}".format(e))
            raise e
        finally:
            logger.info('响应结果是:{}'.format(result))
            self.excel.write(int(case_id) + 1, resp, result)

    @classmethod
    def tearDownClass(cls):
        logger.info('测试后置处理')
        cls.http_request.close()
Exemplo n.º 4
0
class RegisterCase(unittest.TestCase):
    excel = openexcel.DoExcel(contants.case_file, 'register')
    cases = excel.read()


    def setUp(self):
        logger.info('准备测试前置')
        self.http_request= HttpCookies()
        self.mysql= do_mysql.DoMysql()
        self.context = Context()
        warnings.simplefilter("ignore", ResourceWarning)
    @data(*cases)
    @unpack
    def test_register(self,url,method,data,expected,case_id,title,result,check_sql):
        logger.info('开始测试:{}'.format(title))
        logger.info('请求是:{}'.format(data))
        if data['mobilephone']=='register_mobile':
            sql = 'select max(mobilephone) from future.member'
            max_phone = self.mysql.fetch_one(sql)[0]  # 查询最大手机号码
            max_phone=int(max_phone)+1
            data['mobilephone']=max_phone
            print(data['mobilephone'])
        resp=self.http_request.http_request(url,data,method)# 实际值
        resp2=json.dumps(resp,ensure_ascii=False) #转换成字符串
        try:
            self.assertEqual(expected,resp)
            result = 'PASS'
            if check_sql is not None:
                sql = eval(check_sql)['sql1']
                mobilephone = self.mysql.fetch_one(sql)
                print(mobilephone['mobilephone'])
                after = mobilephone['mobilephone']
                self.assertEqual(data['mobilephone'], after)
        except AssertionError as e:
            result = 'FALSE'
            logger.error("报错了,{0}".format(e))
            raise e
        finally:
           logger.info('响应结果是:{}'.format(result))
           self.excel.write(int(case_id) + 1, resp, result)
           logger.info('结束测试:{0}'.format(title))


        def tearDown(self):
            self.mysql.close()
Exemplo n.º 5
0
class WithDraw(unittest.TestCase):
    excel = openexcel.DoExcel(contants.case_file, 'withdraw')
    cases = excel.read()

    @classmethod
    def setUpClass(cls):

        cls.http_request = HttpSessions()
        warnings.simplefilter("ignore", ResourceWarning)
        cls.context = Context()

    @data(*cases)
    @unpack
    def test_withdraw(self, url, method, data, expected, case_id, title,
                      result, check_sql):
        data = self.context.replace(json.dumps(data))  #替换data
        logger.info('开始测试:{0}'.format(title))
        logger.info('请求是:{}'.format(data))
        resp = self.http_request.http_request(
            method, url, json.loads(data))  # 实际值 data,转成json格式
        resp2 = json.loads(resp)['code']  #转换成字符串
        try:
            self.assertEqual(expected, int(resp2))
            result = 'PASS'
        except AssertionError as e:
            result = 'FALSE'
            logger.error("报错了,{0}".format(e))
            raise e
        finally:
            logger.info('响应结果是:{}'.format(result))
            self.excel.write(int(case_id) + 1, resp, result)

    @classmethod
    def tearDownClass(cls):
        logger.info('测试后置处理')
        cls.http_request.close()