Ejemplo n.º 1
0
    def test_full_array_flatten(self):
        record = {
            "person": {
                "name": {
                    "first": "Joe",
                    "last": "Smith"
                },
                "address": "123 Place Ave"
            },
            "phone_numbers": [{
                "type": "cell",
                "number": 1112223333
            }, {
                "type": "home",
                "number": 4445556666
            }]
        }

        gold = {
            "person.name.first": "Joe",
            "person.name.last": "Smith",
            "person.address": "123 Place Ave",
            "phone_numbers.cell.number": 1112223333,
            "phone_numbers.home.number": 4445556666
        }

        output = flatten(record,
                         parse_lists=True,
                         list_key_id="type",
                         full_list_flatten=True)
        self.assertEqual(gold, output)
Ejemplo n.º 2
0
 def test_flatten_null_array(self):
     record = {"key": []}
     gold = {"key": []}
     output = flatten(record,
                      parse_lists=True,
                      list_key_id="id",
                      full_list_flatten=True)
     self.assertEqual(gold, output)
Ejemplo n.º 3
0
 def test_no_array_flattening(self):
     record = {"key": [{"k": "v"}]}
     gold = {"key": [{"k": "v"}]}
     output = flatten(record, parse_lists=False)
     self.assertEqual(gold, output)
Ejemplo n.º 4
0
 def test_array_of_primitives(self):
     record = {"key": [1, 2]}
     gold = {"key": [1, 2]}
     output = flatten(record)
     self.assertEqual(gold, output)
Ejemplo n.º 5
0
 def test_wrong_args_1(self):
     record = {}
     with self.assertRaises(AssertionError):
         flatten(record=record, parse_lists=True)
Ejemplo n.º 6
0
 def test_mix_levels(self):
     record = {"k1": {"k2": 1}, "k1_2": "hi"}
     gold = {"k1.k2": 1, "k1_2": "hi"}
     output = flatten(record)
     self.assertEqual(gold, output)
Ejemplo n.º 7
0
 def test_simple_nest(self):
     record = {"k1": {"k2": 1}}
     gold = {"k1.k2": 1}
     output = flatten(record)
     self.assertEqual(gold, output)
Ejemplo n.º 8
0
 def test_mult_base_keys(self):
     record = {"key1": "value1", "key2": "value2"}
     gold = {"key1": "value1", "key2": "value2"}
     output = flatten(record)
     self.assertEqual(gold, output)
Ejemplo n.º 9
0
 def test_base_case(self):
     record = {"key": "value"}
     gold = {"key": "value"}
     output = flatten(record)
     self.assertEqual(gold, output)
Ejemplo n.º 10
0
 def test_null_case(self):
     record = {}
     gold = {}
     output = flatten(record)
     self.assertEqual(gold, output)
Ejemplo n.º 11
0
 def test_wrong_args_5(self):
     record = {}
     with self.assertRaises(AssertionError):
         flatten(record=record, list_key_id="id", full_list_flatten=True)