Пример #1
0
 def verify_publish_kyc(self, url, header, update_flipping_id):
     header.update({'Region': config.COUNTRY})
     publish_resp = self.publish_kyc_reason_api(url, header)
     utils.log("verify publish kyc reason successfully.")
     self.assertEqual(
         utils.query_json(json.loads(publish_resp), 'msg'), 'success',
         'publish flipping_id={} kyc reason failed!'.format(
             update_flipping_id))
Пример #2
0
 def verify_update_kyc(self, url, header, payload, update_flipping_id):
     header.update({'Region': config.COUNTRY})
     update_resp = self.update_kyc_reason_api(url, header, payload)
     utils.log("verify update kyc reason successfully.")
     self.assertEqual(
         utils.query_json(json.loads(update_resp), 'msg'), 'success',
         'update flipping_id={} kyc reason failed!'.format(
             update_flipping_id))
Пример #3
0
 def test_search_kyc_reason_exist(self):
     """验证搜索存在的Flipping ids成功"""
     search_resp = self.search_kyc_with_params(
         self.rule_data['searchKyc']['validParams'][config.COUNTRY])
     kyc_reason_total = utils.query_json(json.loads(search_resp),
                                         'data.total')
     utils.log(
         'verify search kyc reason records success with exist Flipping ids')
     self.assertTrue(kyc_reason_total > 0,
                     'search kyc reason with exist Flipping ids failed!')
Пример #4
0
 def call_rule(self, test_data):
     params = self.rule_data['rule']['params']['general']
     params.update(test_data)
     result = RuleEngine.rule(self.req, params)
     utils.log('Step. verify call api borrow-apply successfully.')
     self.assertEqual(utils.query_json(result, 'msg'), 'success',
                      'call api rule failed!')
     time.sleep(3)
     utils.log(result)
     return result
Пример #5
0
 def call_borrow_apply(self, data):
     utils.log('call api [borrow-apply] for [{}]'.format(config.COUNTRY))
     url = self.model_data['Host'][
         config.COUNTRY] + self.model_data['CeleryPort'][
             config.COUNTRY] + self.model_data['BorrowApply']['path']
     header = self.model_data['BorrowApply']['header']
     model_result = json.loads(
         self.req.post(url, headers=header, json=data).text)
     utils.log('1.verify call RiskMQ-app API borrow-apply successfully.')
     self.assertEqual(utils.query_json(model_result, 'success'), 'true',
                      'call api borrow-apply failed!')
Пример #6
0
 def call_borrow_apply(self, data, clean_borrow_case=True):
     id_account, id_borrow = data['id_account'], data['id_borrow']
     if clean_borrow_case:
         self.clean_borrow_case_if_exist(id_account, id_borrow)
     transaction_id = "RT{}{}{}".format(id_account, id_borrow, utils.get_random_numb(1001, 9999))
     data.update({"transaction_id": transaction_id})
     result = Pipeline.borrow_apply(self.req, data)
     utils.log('2.verify call api borrow-apply successfully.')
     self.assertEqual(utils.query_json(result, 'success'), 'true', 'call api borrow-apply failed!')
     time.sleep(6)
     return result, transaction_id
Пример #7
0
 def test_search_kyc_reason_not_exist(self):
     """验证搜索不存在的Flipping ids成功"""
     search_resp = self.search_kyc_with_params(
         self.rule_data['searchKyc']['invalidParams'])
     kyc_reason_total = utils.query_json(json.loads(search_resp),
                                         'data.total')
     utils.log(
         'verify search kyc reason records success with Not exist Flipping ids'
     )
     self.assertEqual(
         kyc_reason_total, 0,
         'search kyc reason with Not exist Flipping ids failed! should equal 0!'
     )
Пример #8
0
    def _extract_field_with_delimiter(self, field):
        """ response content could be json or html text.

        Args:
            field (str): string joined by delimiter.
            e.g.
                "status_code"
                "headers"
                "cookies"
                "content"
                "headers.content-type"
                "content.person.name.first_name"

        """
        # string.split(sep=None, maxsplit=-1) -> list of strings
        # e.g. "content.person.name" => ["content", "person.name"]
        try:
            top_query, sub_query = field.split('.', 1)
        except ValueError:
            top_query = field
            sub_query = None

        # status_code
        if top_query in ["status_code", "encoding", "reason", "url"]:
            if sub_query:
                # status_code.XX
                err_msg = u"Failed to extract: {}\n".format(field)
                logger.log_error(err_msg)
                raise exceptions.ParamsError(err_msg)

            return getattr(self, top_query)

        # cookies
        elif top_query == "cookies":
            cookies = self.cookies
            if not sub_query:
                # extract cookies
                return cookies

            try:
                return cookies[sub_query]
            except KeyError:
                err_msg = u"Failed to extract cookie! => {}\n".format(field)
                err_msg += u"response cookies: {}\n".format(cookies)
                logger.log_error(err_msg)
                raise exceptions.ExtractFailure(err_msg)

        # headers
        elif top_query == "headers":
            headers = self.headers
            if not sub_query:
                # extract headers
                return headers

            try:
                return headers[sub_query]
            except KeyError:
                err_msg = u"Failed to extract header! => {}\n".format(field)
                err_msg += u"response headers: {}\n".format(headers)
                logger.log_error(err_msg)
                raise exceptions.ExtractFailure(err_msg)

        # response body
        elif top_query in ["content", "text", "json"]:
            try:
                body = self.json
            except exceptions.JSONDecodeError:
                body = self.text

            if not sub_query:
                # extract response body
                return body

            if isinstance(body, (dict, list)):
                # content = {"xxx": 123}, content.xxx
                return utils.query_json(body, sub_query)
            elif sub_query.isdigit():
                # content = "abcdefg", content.3 => d
                return utils.query_json(body, sub_query)
            else:
                # content = "<html>abcdefg</html>", content.xxx
                err_msg = u"Failed to extract attribute from response body! => {}\n".format(
                    field)
                err_msg += u"response body: {}\n".format(body)
                logger.log_error(err_msg)
                raise exceptions.ExtractFailure(err_msg)

        else:
            err_msg = u"Failed to extract attribute from response! => {}\n".format(
                field)
            err_msg += u"available response attributes: status_code, cookies,  headers, content, text, json, encoding,  reason, url.\n\n"
            err_msg += u"response.new_attribute = 'new_attribute_value'\n"
            logger.log_error(err_msg)
            raise exceptions.ParamsError(err_msg)