def test_reg(self, case):
     print("开始执行第{}个测试用例:".format(case.case_id))
     import json
     data_dict = json.loads(case.data)
     if data_dict["mobilephone"] == "${register_mobile}":
         data_dict["mobilephone"] = int(self.max) + 1
     read_config = ReadConfig()
     pre_url = read_config.get("api", "pre_url")
     resp = self.request.request(method=case.method,
                                 url=pre_url + case.url,
                                 data=data_dict)
     doexcels = doexcel.DoExcel(contants.case_file, "reg")
     try:
         self.assertEqual(case.expected, resp.text)
         doexcels.write_back(row=case.case_id + 1,
                             col=8,
                             value="PASS",
                             sheet_name="reg")
     except AssertionError as e:
         doexcels.write_back(row=case.case_id + 1,
                             col=8,
                             value="FAIlED",
                             sheet_name="reg")
     doexcels.write_back(case.case_id + 1, 7, resp.text, sheet_name="reg")
     print(resp.text)
Beispiel #2
0
class LoginTest(unittest.TestCase):
    cases = doexcel.DoExcel(contants.case_file, "login").get_data("login")
    request = Request()

    def setUp(self):
        pass

    def tearDown(self):
        pass

    @data(*cases)
    def test_login(self, case):
        logg.info("开始执行第{}个测试用例:".format(case.case_id))
        resp = self.request.request(method=case.method,
                                    url=case.url,
                                    data=case.data)
        doexcels = doexcel.DoExcel(contants.case_file, "login")
        try:
            self.assertEqual(case.expected, resp.text)
            doexcels.write_back(row=case.case_id + 1,
                                col=8,
                                value="PASS",
                                sheet_name="login")
        except AssertionError as e:
            doexcels.write_back(row=case.case_id + 1,
                                col=8,
                                value="FAIlED",
                                sheet_name="login")
            logg.error("第{}个用例执行结果:failed".format(case.case_id))
        doexcels.write_back(case.case_id + 1, 7, resp.text, sheet_name="login")
        logg.info(resp.text)
Beispiel #3
0
class AddloanTest(unittest.TestCase):
    cases = doexcel.DoExcel(contants.case_file, "addloan").get_data("addloan")
    request = Request()

    def setUp(self):
        pass

    def tearDown(self):
        pass

    @data(*cases)
    def test_addloan(self, case):
        readconfig = ReadConfig()
        pre_url = readconfig.get("api", "pre_url")
        print("开始执行第{}个测试用例:".format(case.case_id))
        resp = self.request.request(method=case.method,
                                    url=pre_url + case.url,
                                    data=case.data)
        doexcels = doexcel.DoExcel(contants.case_file, "addloan")
        try:
            self.assertEqual(case.expected, resp.text)
            doexcels.write_back(row=case.case_id + 2,
                                col=8,
                                value="PASS",
                                sheet_name="addloan")
        except AssertionError as e:
            doexcels.write_back(row=case.case_id + 2,
                                col=8,
                                value="FAIlED",
                                sheet_name="addloan")
        doexcels.write_back(case.case_id + 2,
                            7,
                            resp.text,
                            sheet_name="addloan")
        print(resp.text)
class RechargeTest(unittest.TestCase):
    cases = doexcel.DoExcel(contants.case_file,
                            "recharge").get_data("recharge")
    request = Request()

    def setUp(self):
        pass

    def tearDown(self):
        pass

    @data(*cases)
    def test_login(self, case):
        print("开始执行第{}个测试用例:".format(case.case_id))
        resp = self.request.request(method=case.method,
                                    url=case.url,
                                    data=case.data)
        doexcels = doexcel.DoExcel(contants.case_file, "recharge")
        try:
            self.assertEqual(case.expected, resp.text)
            doexcels.write_back(row=case.case_id + 2,
                                col=8,
                                value="PASS",
                                sheet_name="recharge")
        except AssertionError as e:
            doexcels.write_back(row=case.case_id + 2,
                                col=8,
                                value="FAIlED",
                                sheet_name="recharge")
            raise e
        doexcels.write_back(case.case_id + 2,
                            7,
                            resp.text,
                            sheet_name="recharge")
        print(resp.text)
Beispiel #5
0
class InvestTest(unittest.TestCase):
    cases = doexcel.DoExcel(contants.case_file, "invest").get_data("invest")
    request = Request()
    @classmethod
    def setUpClass(cls):
        cls.mysql = MysqlUtil()
    @classmethod
    def tearDownClass(cls):
        cls.mysql.close()

    @data(*cases)
    def test_invest(self,case):
        readconfig = ReadConfig()
        pre_url = readconfig.get("api","pre_url")
        print("开始执行第{}个测试用例:".format(case.case_id))
        case.data = replace(case.data)
        resp = self.request.request(method=case.method,url = pre_url+case.url,data=case.data)
        doexcels = doexcel.DoExcel(contants.case_file, "invest")
        try:
            self.assertEqual(case.expected,resp.text)
            doexcels.write_back(row=case.case_id + 2, col=8, value="PASS", sheet_name="invest")
            #加一层判断,判断加标是否成功,如果成功,就把标的的ID查出来反射给类的属性,以便下一条用例取
            if resp.json()["msg"] == "加标成功":
                load_member_id = getattr(Context,"loan_member_id")
                mysql = MysqlUtil()
                sql = "select Id from future.loan where MemberID={} order by CreateTime desc limit 1".format(load_member_id)
                loan_id = mysql.fetchone(sql)[0]
                setattr(Context,"loan_id",str(loan_id))
        except AssertionError as  e:
            doexcels.write_back(row=case.case_id + 2, col=8, value="FAIlED", sheet_name="invest")
        doexcels.write_back(case.case_id + 2,7,resp.text,sheet_name="invest")
        print(resp.text)
class RegisterTest(unittest.TestCase):
    cases = doexcel.DoExcel(contants.case_file, "reg").get_data("reg")
    request = Request()

    def setUp(self):
        pass

    def tearDown(self):
        pass

    mysql = MysqlUtil()
    sql = "select max(mobilephone) from future.member"
    max = mysql.fetchone(sql)[0]

    @data(*cases)
    def test_reg(self, case):
        print("开始执行第{}个测试用例:".format(case.case_id))
        import json
        data_dict = json.loads(case.data)
        if data_dict["mobilephone"] == "${register_mobile}":
            data_dict["mobilephone"] = int(self.max) + 1
        read_config = ReadConfig()
        pre_url = read_config.get("api", "pre_url")
        resp = self.request.request(method=case.method,
                                    url=pre_url + case.url,
                                    data=data_dict)
        doexcels = doexcel.DoExcel(contants.case_file, "reg")
        try:
            self.assertEqual(case.expected, resp.text)
            doexcels.write_back(row=case.case_id + 1,
                                col=8,
                                value="PASS",
                                sheet_name="reg")
        except AssertionError as e:
            doexcels.write_back(row=case.case_id + 1,
                                col=8,
                                value="FAIlED",
                                sheet_name="reg")
        doexcels.write_back(case.case_id + 1, 7, resp.text, sheet_name="reg")
        print(resp.text)