コード例 #1
0
 def testWithdraw(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------')
コード例 #2
0
    def testLogin(self, case):
        my_log.info(f'TestCase {case.case_name} starting------')

        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:
            wb.w_data(case.row + 1, wb.r_max()[1], result)
            my_log.info(f'TestCase {case.case_name} end------')
コード例 #3
0
    def test(self, case):
        my_log.info(f'TestCase {case.case_name} starting------')
        expect = json.loads(case.expected_data)
        sql = f'SELECT leaveamount FROM member where mobilephone = {case.mobilephone}'

        amount = case.amount if expect['code'] == '10001' else 0
        flag = False if case.mobilephone is None or case.amount is None else True
        try:
            if flag:
                con1 = Mysql()
                amount_bf = con1.select(sql)[0] if con1.select(sql) is not None else 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 flag:
                con1.commit()
                # con2 = Mysql()
                amount_af = con1.select(sql)[0] if con1.select(sql) is not None else 0
                self.assertEqual(amount, amount_bf - amount_af) if flag else print('未校验金额')
            self.assertEqual((expect['status'], expect['code']), (actual['status'], actual['code']))
        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------')
コード例 #4
0
ファイル: R_request.py プロジェクト: julystone/keyou
 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!')
         raise RuntimeError
     return res.text