示例#1
0
    def test_request_1(self):
        config = CONFIG_MAP['elasticsearch']

        queries = get_jsonpath(REQUEST_1, config['query_path'])
        self.assertEqual("kimchy", queries[0])

        topks = get_jsonpath(REQUEST_1, config['topk_path'])
        self.assertEqual(20, topks[0])

        true_cids = get_jsonpath(REQUEST_1, config['true_cids_path'])
        self.assertEqual(['0', '2'], true_cids[0])
示例#2
0
    def test_response_1(self):
        config = CONFIG_MAP['elasticsearch']

        choices = get_jsonpath(RESPONSE_1, config['choices_path'])
        choices = flatten(choices)
        self.assertEqual(1.4, choices[0]['_score'])

        cvalues = get_jsonpath(choices, '[*].' + config['cvalues_path'])
        self.assertEqual(
            ["trying out Elasticsearch", "second result", "third result"],
            cvalues)

        cids = get_jsonpath(choices, '[*].' + config['cids_path'])
        self.assertEqual(['0', '1', '2'], cids)
示例#3
0
文件: proxy.py 项目: yueyedeai/nboost
    def get_request_paths(request, configs) -> Tuple[str, int, list]:
        """Get the request jsonpaths noted in the configs"""
        queries = get_jsonpath(request, configs['query_path'])
        topks = get_jsonpath(request, configs['topk_path'])
        true_cids = get_jsonpath(request, configs['true_cids_path'])

        # coerce request variables from their paths
        topk = int(topks[0]) if topks else configs['default_topk']
        query = configs['delim'].join(queries)

        # check for errors
        if not query:
            raise MissingQuery

        return query, topk, true_cids
示例#4
0
 def get_path(self, path: str) -> JSONTYPES:
     # To improve performance, don't use get_jsonpath if the key is easily accessible using dotted path syntax (e.g. "path.to.my.key")
     is_dotted_path = True if re.match("^([\w]+[.]?)+$", path) else False
     if is_dotted_path:
         return [self._get_dict_by_path(self.dict, path)]
     else:
         return get_jsonpath(self.dict, path)
示例#5
0
文件: proxy.py 项目: yueyedeai/nboost
    def get_response_paths(response, configs) -> Tuple[list, list, list]:
        """Get the request jsonpaths noted in the configs"""
        choices = get_jsonpath(response, configs['choices_path'])

        if not isinstance(choices, list):
            raise InvalidChoices('choices were not a list')

        choices = flatten(choices)
        cids = get_jsonpath(choices, '[*].' + configs['cids_path'])
        cvalues = get_jsonpath(choices, '[*].' + configs['cvalues_path'])

        # check for errors
        if not len(choices) == len(cids) == len(cvalues):
            raise InvalidChoices('number of choices, cids, and cvalues differ')

        return choices, cids, cvalues
示例#6
0
 def test_request_5(self):
     queries = get_jsonpath(REQUEST_5, 'body.params.query')
     self.assertEqual(['my query'], queries)
示例#7
0
 def test_request_4(self):
     queries = get_jsonpath(
         REQUEST_4,
         'body.query.function_score.query.bool.should.[*].match.text.query')
     self.assertEqual(['query one', 'query two'], queries)
示例#8
0
    def test_request_3(self):
        config = CONFIG_MAP['elasticsearch']

        queries = get_jsonpath(REQUEST_3, config['query_path'])
        self.assertEqual("hello there", queries[0])
示例#9
0
    def test_request_2(self):
        config = CONFIG_MAP['elasticsearch']

        queries = get_jsonpath(REQUEST_2, config['query_path'])
        self.assertEqual("message:test query", queries[0])
示例#10
0
 def get_response_path(self, path: str):
     return get_jsonpath(self.response, path)
示例#11
0
 def get_request_path(self, path: str):
     return get_jsonpath(self.request, path)
示例#12
0
 def get_path(self, path: str) -> JSONTYPES:
     return get_jsonpath(self.dict, path)