Пример #1
0
    def test_extract_via_json_path_not_dict(self, log_mock):
        """JSONParser - Extract via JSON Path, Not Dictionary"""
        options = {
            'schema': {
                'key': 'string'
            },
            'configuration': {
                'embedded_json': True,
                'json_path': 'key[].value'
            }
        }
        record_data = {'key': [{'value': '["list of data"]'}]}

        parser = JSONParser(options)
        result = parser._extract_via_json_path(record_data)
        assert_equal(result, [(['list of data'], False)])
        log_mock.assert_any_call('Embedded json is invalid: %s',
                                 'record data is not a dictionary')
Пример #2
0
    def test_extract_via_json_path_bad_json(self, log_mock):
        """JSONParser - Extract via JSON Path, Bad JSON"""
        options = {
            'schema': {
                'key': 'string'
            },
            'configuration': {
                'embedded_json': True,
                'json_path': 'key[].value'
            }
        }
        record_data = {'key': [{'value': 'not json'}]}

        parser = JSONParser(options)
        result = parser._extract_via_json_path(record_data)
        assert_equal(result, [('not json', False)])
        log_mock.assert_any_call('Embedded json is invalid: %s',
                                 'Expecting value: line 1 column 1 (char 0)')