def test_replace_value_replaces_existing_value_in_doubly_cascaded_dict( self): target_dict = {'kfoo': {'kfoobar': {'kbar': 'vfoo'}}} replacement = {'vfoo': 'vbar'} target_dict = utils.replace_value_in_dict(replacement, target_dict) self.assertEqual(replacement['vfoo'], target_dict['kfoo']['kfoobar']['kbar'])
def test_replace_value_replaces_empty_list_in_target(self): target_dict = {'kfoo': []} replacement = {'kfoo': ['foo', 'bar']} target_dict = utils.replace_value_in_dict(replacement, target_dict) self.assertEqual(replacement['kfoo'], target_dict['kfoo'])
def test_replace_value_handles_lists_of_dicts(self): target_dict = {'kfoo': [{'kfoo': 'vfoo'}, {'kbar': 'vbar'}]} replacement = {'vfoo': 'vbar'} target_dict = utils.replace_value_in_dict(replacement, target_dict) self.assertEqual(replacement['vfoo'], target_dict['kfoo'][0]['kfoo'])
def test_replace_value_replaces_existing_value_in_list(self): target_dict = {'kfoo': ['vfoo', 'vbar']} replacement = {'vfoo': 'vbar'} target_dict = utils.replace_value_in_dict(replacement, target_dict) self.assertEqual(replacement['vfoo'], target_dict['kfoo'][0])
def test_replace_value_ignores_nonexisting_value_in_cascaded_dict(self): target_dict = {'kfoo': {'kbar': 'vfoo'}} replacement = {'kfoo': 'vbar'} modified_dict = utils.replace_value_in_dict(replacement, target_dict) self.assertEqual(modified_dict, target_dict)
def test_replace_value_returns_dict(self): target_dict = {'kfoo': 'vfoo', 'kbar': 'vbar'} replacement = {'kfoo': 'vbar'} target_dict = utils.replace_value_in_dict(replacement, target_dict) self.assertTrue(isinstance(target_dict, dict))