Beispiel #1
0
    def choices(self) -> list:
        choices = self.get_path(self.request.choices_path)

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

        return flatten(choices)
Beispiel #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)
Beispiel #3
0
    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
Beispiel #4
0
 def rerank_cids(self) -> list:
     rerank_cids = self.get_config('rerank_cids')
     return flatten(rerank_cids)
Beispiel #5
0
 def cids(self) -> list:
     cids = self.get_response_path(self.cids_path)
     return flatten(cids)