Example #1
0
 def test_flatten_dict(self):
     self.assertEqual(flatten_dict(dict(foo='bar')), dict(foo='bar'))
     self.assertEqual(flatten_dict(dict(foo=1)), dict(foo='1'))
     self.assertEqual(flatten_dict(dict(foo=1.1)), dict(foo='1.1'))
     self.assertEqual(flatten_dict(dict(foo=True)), dict(foo='True'))
     self.assertEqual(
         flatten_dict(dict(foo=True, bar=dict(tao=dict(te='ching')))),
         dict(foo='True', bar__tao__te='ching'))
Example #2
0
    def prepare_extras(instance):
        value = {}

        if instance.extras:
            value = jsonify_safe(instance.extras)
            if isinstance(value, dict):
                value = flatten_dict(value)

        return value or {}