コード例 #1
0
class Register(unittest.TestCase):
    do_excel = Do_excel(file_os1, "login")
    cases = do_excel.excel()

    def setUp(self):
        print("------------------开始执行登录测试用例----------------------")

    @data(*cases)
    def test_login(self, case):
        if "123123gnn" in case.data:
            passwoed = MD5Test("123123gnn").upper()
            case.data = case.data.replace("123123gnn", passwoed)
        logging.info("开始执行第{}个条测试用例".format(case.case_id))
        data_2 = data_1.data1
        data_2["data"] = json.loads(case.data)
        res = Request().request(case.method, case.url, data_2)
        test_api = json.loads(decrypt_str(res.json()))
        try:
            excepted = eval(case.expected)
            for key, value in excepted.items():
                self.assertEqual(value, test_api[key])
            self.do_excel.write_data(case.case_id + 1, res.text, "pass")
            logging.error("第{}条的结果为:pass".format(case.case_id))

        except AssertionError as e:
            self.do_excel.write_data(case.case_id + 1, res.text, "flas")
            logging.error("第{}条的结果为:flas".format(case.case_id))
            raise e
コード例 #2
0
ファイル: test_register.py プロジェクト: gnn123456/test_qidi
class Register(unittest.TestCase):
    do_excel = Do_excel(file_os1, "register")
    cases = do_excel.excel()

    def setUp(self):
        print("------------------开始执行注册测试用例----------------------")
        self.mysql = mysqlni(retu_dict=True)

    @data(*cases)
    def test_login(self, case):
        if "#phone#" in case.data:
            phone = gen_mobile()
            case.data = case.data.replace("#phone#", phone)
        logging.info("开始执行第{}个条测试用例".format(case.case_id))
        data_2 = data_1.data1
        data_2["data"] = json.loads(case.data)
        res = Request().request(case.method, case.url, data_2)
        test_api = json.loads(decrypt_str(res.json()))
        # print(test_api)
        try:
            excepted = eval(case.expected)
            for key, value in excepted.items():
                self.assertEqual(value, test_api[key])
            if test_api["Status"] == 000000:
                data_dice = json.loads(case.data)
                sql = "select * from ab_member where mobile=to_base64(AES_ENCRYPT('{}','19549303ghdyoscc'))".format(
                    data_dice["Mobile"])
                sql = "select * from futureloan.member where mobile_phone={};".format(
                    data_dice["mobile_phone"])
                ress = self.mysql.fet_all(sql)
                self.assertTrue(ress)

            self.do_excel.write_data(case.case_id + 1, res.text, "pass")
            logging.error("第{}条的结果为:pass".format(case.case_id))

        except AssertionError as e:
            self.do_excel.write_data(case.case_id + 1, res.text, "flas")
            logging.error("第{}条的结果为:flas".format(case.case_id))
            raise e

    #
    def tearDown(self):
        self.mysql.close()
コード例 #3
0
class TestBindBankCard(unittest.TestCase):
    doexcel_ob = Do_excel(contants.case_file, 'bindBankCard')
    mylog = MyLog(__name__).my_log()

    @classmethod
    def setUpClass(cls):
        cls.service = WebService()
        cls.mysql = DoMysql()
        cls.mylog.info('开始执行用例')

    @data(*doexcel_ob.get_data())
    def test_bindbankcard(self, case):

        case.data = DoRe(case.data)

        # 随机生成IP地址,并且反射到Context类的属性中,方便后面参数调用
        if case.data.find('register_ip') != -1:
            random_ip = '192.168.1' + ''.join(random.sample(
                string.digits, 2)) + '.1' + ''.join(
                    random.sample(string.digits, 2))
            setattr(Context, 'register_ip', random_ip)
            case.data = case.data.replace('register_ip', random_ip)
コード例 #4
0
class TestSendMCode(unittest.TestCase):
    doexcel_ob = Do_excel(contants.case_file, 'sendMCode')
    mylog = MyLog(__name__).my_log()

    @classmethod
    def setUpClass(cls):
        cls.service = WebService()
        cls.mysql = DoMysql()
        cls.mylog.info('开始执行用例')

    @data(*doexcel_ob.get_data())
    def test_sendmcode(self, case):

        # 随机生成IP地址,并且反射到Context类的属性中,方便后面参数调用
        if case.data.find('sendmcode_ip') != -1:
            random_ip = '192.168.1' + ''.join(random.sample(
                string.digits, 2)) + '.1' + ''.join(
                    random.sample(string.digits, 2))
            case.data = case.data.replace('sendmcode_ip', random_ip)

        # 随机生成电话号码,并且反射到Context类的属性中,方便后面参数调用
        random_phone = '15' + ''.join(random.sample(string.digits, 6)) + '207'
        if case.data.find('sendmcode_mobile') != -1:
            case.data = case.data.replace('sendmcode_mobile', random_phone)