Exemplo n.º 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('.'))
Exemplo n.º 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('.'))
Exemplo n.º 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')
Exemplo n.º 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')
Exemplo n.º 5
0
 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
Exemplo n.º 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'])
Exemplo n.º 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'])