Exemple #1
0
 def testBidLoan(self, case):
     my_log.info(f'TestCase {case.case_name} starting------')
     # login session
     testRequest.request(method='post', url='http://test.lemonban.com/futureloan/mvc/api/member/login',
                         data={"mobilephone": "13912345611", "pwd": "123456"})
     actual = testRequest.request(method=case.method, url=case.url, data=eval(case.request_data),
                                  params=eval(case.request_data))
     # actual = register(*eval(case.data))
     actual = json.loads(actual)
     expect = json.loads(case.expected_data)
     try:
         result = None
         self.assertEqual((expect['status'], expect['code']), (actual['status'], actual['code']))
     except AssertionError as e:
         print('Not Passed...')
         result = 'failed'
         print(f"{expect['msg']}\n{actual['msg']}")
         my_log.error(f'【Failed】:E{expect} != A{actual}')
         raise e
     else:
         print('Passed')
         result = 'passed'
         my_log.info(f'【Success】')
     finally:
         wb.w_data(case.row + 1, wb.r_max()[1], result)
         my_log.info(f'TestCase {case.case_name} end------')
Exemple #2
0
 def test(self, case):
     my_log.info(f'TestCase {case.case_name} starting------')
     number = self.checkNumber(case)
     case.request_data = my_replace(case.request_data, content=number)
     case.url = api + case.url
     actual = testRequest.request(method=case.method,
                                  url=case.url,
                                  data=eval(case.request_data),
                                  params=eval(case.request_data))
     actual = json.loads(actual)
     expect = json.loads(case.expected_data)
     try:
         result = None
         self.assertEqual((expect['status'], expect['code']),
                          (actual['status'], actual['code']))
     except AssertionError as e:
         print('Not Passed...')
         result = 'failed'
         print(f"{expect['msg']}\n{actual['msg']}")
         my_log.error(f'【Failed】:E{expect} != A{actual}')
         raise e
     else:
         print('Passed')
         result = 'passed'
         my_log.info(f'【Success】:E{expect} == A{actual}')
     finally:
         self.wb.w_data(case.row, self.wb.r_max()[1], result)
         my_log.info(f'TestCase {case.case_name} end------')
Exemple #3
0
class AddTestCase(unittest.TestCase):
    sheet_name = 'add'
    wb = ReadExcel(file_path, sheet_name)
    cases = wb.read_data_obj()

    @classmethod
    def setUpClass(cls):
        testRequest.request(
            method='post',
            url='http://test.lemonban.com/futureloan/mvc/api/member/login',
            data={
                "mobilephone": "13912345611",
                "pwd": "123456"
            })

    @classmethod
    def tearDownClass(cls):
        pass

    @data(*cases)
    def test(self, case):
        my_log.info(f'TestCase {case.case_name} starting------')
        case.request_data = my_replace(case.request_data)
        case.url = api + case.url

        expect = json.loads(case.expected_data)
        if case.checksql:
            case.checksql = my_replace(case.checksql)
            id_old = my_sql.select(case.checksql)[0] if my_sql.select(
                case.checksql) is not None else None
        actual = testRequest.request(method=case.method,
                                     url=case.url,
                                     data=eval(case.request_data),
                                     params=eval(case.request_data),
                                     timeout=5)
        actual = json.loads(actual) if actual is not None else None
        if case.checksql:
            id_new = my_sql.select(case.checksql)[0]
        result = None
        try:
            self.assertEqual((expect['status'], expect['code']),
                             (actual['status'], actual['code']))
            self.assertNotEqual(id_old, id_new) if case.checksql else True
        except (AssertionError, TypeError) as e:
            print(f"Not Passed...\n{expect['msg']}\n{actual['msg']}")
            print(f"\n请求参数为{case.request_data}")
            result = 'failed'
            my_log.error(f'【Failed】:E{expect} != A{actual}')
            raise e
        else:
            print('Passed')
            result = 'passed'
            my_log.info(f'【Success】:E{expect} == A{actual}')
        finally:
            # 2
            self.wb.w_data(case.row, self.wb.r_max()[1], result)
            my_log.info(f'TestCase {case.case_name} end------')
Exemple #4
0
class RechargeTestCase(unittest.TestCase):
    sheet_name = 'recharge'
    wb = ReadExcel(file_path, sheet_name)
    cases = wb.read_data_obj()

    @classmethod
    def setUpClass(cls):
        testRequest.request(
            method='post',
            url='http://test.lemonban.com/futureloan/mvc/api/member/login',
            data={
                "mobilephone": "13912345611",
                "pwd": "123456"
            })

    @classmethod
    def tearDownClass(cls):
        cls.wb.save()

    @data(*cases)
    def test(self, case):
        my_log.info(f'TestCase {case.case_name} starting------')
        case.request_data = my_replace(case.request_data)
        case.url = api + case.url

        expect = json.loads(case.expected_data)

        amount = case.amount if case.checksql else 0
        if case.checksql:
            case.checksql = my_replace(case.checksql)
            amount_bf = my_sql.select(case.checksql)[0]
        actual = testRequest.request(method=case.method,
                                     url=case.url,
                                     data=eval(case.request_data),
                                     params=eval(case.request_data))
        actual = json.loads(actual)
        if case.checksql:
            amount_af = my_sql.select(case.checksql)[0]
        try:
            self.assertEqual((expect['status'], expect['code']),
                             (actual['status'], actual['code']))
            self.assertEqual(amount, amount_af -
                             amount_bf) if case.checksql else print('未校验金额')
        except (AssertionError, TypeError) as e:
            print(f"Not Passed...\n{expect['msg']}\n{actual['msg']}")
            result = 'failed'
            my_log.error(f'【Failed】:E{expect} != A{actual}')
            raise e
        else:
            print('Passed')
            result = 'passed'
            my_log.info(f'【Success】:E{expect} == A{actual}')
        finally:
            # 2
            self.wb.w_data(case.row, self.wb.r_max()[1], result)
            my_log.info(f'TestCase {case.case_name} end------')
def do_assert(actual, expect, cls, case):
    try:
        cls.assertEqual((expect["retCode"], expect['retInfo']),
                        (actual['retCode'], actual['retInfo']))
    except AssertionError as e:
        print('Not Passed...')
        result = 'failed'
        print(case.request_data)
        my_log.error(f'【Failed】:E{expect} != A{actual}')
        print(f'E{expect}\nA{actual}')
        raise e
    else:
        print('Passed')
        result = 'passed'
        my_log.info(f'【Success】:E{expect} == A{actual}')
    finally:
        cls.wb.w_data(case.row, cls.wb.r_max()[1], result)
        my_log.info(f'TestCase {case.case_name} end------')
    return result
Exemple #6
0
 def request(self,
             method,
             url,
             data=None,
             params=None,
             json=None,
             headers=None,
             cookies=None,
             timeout=None):
     if method.lower() == 'get':
         my_log.info(f'Sending {method}:{url} {params}')
         res = self.session.get(url=url,
                                params=params,
                                headers=headers,
                                cookies=cookies,
                                timeout=timeout)
     elif method.lower() == 'post':
         if json:
             my_log.info(f'Sending {method}:{url} {json}')
             res = self.session.post(url=url,
                                     json=json,
                                     headers=headers,
                                     cookies=cookies,
                                     timeout=timeout)
         else:
             my_log.info(f'Sending {method}:{url} {data}')
             res = self.session.post(url=url,
                                     data=data,
                                     headers=headers,
                                     cookies=cookies,
                                     timeout=timeout)
     else:
         res = None
     if res.status_code == 404:
         my_log.error(f'404 not found!')
         print('404 not found!')
         raise RuntimeError
     return res.text