Beispiel #1
0
    def test_get_not_a_value(self):
        # given
        nested_dict = self.get_nested_dict()

        # when
        with self.assertRaisesRegexp(KeyError, 'could not be found for nested path'):
            nested_dict_value(nested_dict, 'address.postal_code'.split('.'))
Beispiel #2
0
    def test_get_not_a_value(self):
        # given
        nested_dict = self.get_nested_dict()

        # when
        with self.assertRaisesRegexp(KeyError,
                                     'could not be found for nested path'):
            nested_dict_value(nested_dict, 'address.postal_code'.split('.'))
Beispiel #3
0
    def test_get_the_right_value(self):
        # given
        nested_dict = self.get_nested_dict()

        # when
        number = nested_dict_value(nested_dict, 'address.street.number'.split('.'))
        city = nested_dict_value(nested_dict, ['city'])

        # then
        self.assertEqual(number, 123)
        self.assertEqual(city, 'val')
Beispiel #4
0
    def test_get_the_right_value(self):
        # given
        nested_dict = self.get_nested_dict()

        # when
        number = nested_dict_value(nested_dict,
                                   'address.street.number'.split('.'))
        city = nested_dict_value(nested_dict, ['city'])

        # then
        self.assertEqual(number, 123)
        self.assertEqual(city, 'val')
 def filter(self, item):
     for key in self.keys:
         if self.nested_field_separator:
             nested_fields = key['name'].split(self.nested_field_separator)
             try:
                 value = nested_dict_value(item, nested_fields)
             except KeyError:
                 self.logger.debug('Missing path {} from item. Item dismissed'.format(
                         nested_fields))
                 return False
         else:
             value = item[key['name']]
         if not self._match_value(
                 value, key['value'], OPERATORS[key.get('operator', DEFAULT_OPERATOR)]):
             return False
     return True
Beispiel #6
0
 def test_get_none_value(self):
     with self.assertRaisesRegexp(TypeError, 'Could not get key'):
         nested_dict_value({'something': None},
                           ['something', 'in', 'the', 'way'])
Beispiel #7
0
 def test_get_none_value(self):
     with self.assertRaisesRegexp(TypeError, 'Could not get key'):
         nested_dict_value({'something': None}, ['something', 'in', 'the', 'way'])