def test_all_removed(self): src = {'name': 'NAME', 'desc': 'DESC'} comp = {} d = diff(src, comp) self.assertEqual(2, len(d)) self.assertTrue(_removed('name', 'NAME') in d) self.assertTrue(_removed('desc', 'DESC') in d)
def test_update_dict_with_list_clear(self): src = {'name': 'NAME', 'data': ['A', 'B', 'C']} comp = {'name': 'NAME_UPD', 'data': []} d = diff(src, comp) self.assertEqual(4, len(d)) self.assertTrue(_updated('name', 'NAME', 'NAME_UPD') in d) self.assertTrue(_removed('data[0]', 'A') in d) self.assertTrue(_removed('data[1]', 'B') in d) self.assertTrue(_removed('data[2]', 'C') in d)
def test_update_list_reduce(self): src = ['A', 'B', 'C'] comp = ['A', 'Z'] d = diff(src, comp) self.assertEqual(2, len(d)) self.assertTrue(_updated('[1]', 'B', 'Z') in d) self.assertTrue(_removed('[2]', 'C') in d)
def test_update_dict_with_list_removed(self): src = {'name': 'NAME', 'data': ['A', 'B', 'C']} comp = { 'name': 'NAME_UPD', } d = diff(src, comp) self.assertEqual(2, len(d)) self.assertTrue(_updated('name', 'NAME', 'NAME_UPD') in d) self.assertTrue(_removed('data', ['A', 'B', 'C']) in d)
def test_delete_dict(self): src = {'name': 'NAME_UPD', 'desc': 'DESC_UPD'} comp = None d = diff(src, comp) self.assertEqual(1, len(d)) self.assertTrue( _removed('', { 'name': 'NAME_UPD', 'desc': 'DESC_UPD' }) in d)
def test_update_list_of_lists(self): src = [ ['A', 'B', 'C'], ['X', 'Y', 'Z'], ['1', '2', '3'], ] comp = [['A1', 'B', 'C', 'D'], ['X1', 'Y'], ['1A', '2', '3'], ['D', 'E']] d = diff(src, comp) self.assertEqual(6, len(d)) self.assertTrue(_updated('[0][0]', 'A', 'A1') in d) self.assertTrue(_added('[0][3]', 'D') in d) self.assertTrue(_updated('[1][0]', 'X', 'X1') in d) self.assertTrue(_removed('[1][2]', 'Z') in d) self.assertTrue(_updated('[2][0]', '1', '1A') in d) self.assertTrue(_added('[3]', ['D', 'E']) in d)
def test_remove_dict_with_dict(self): src = { 'name': 'NAME_UPD', 'data': { 'attr1': 'VALUE_1', 'attr2': 'VALUE_2' } } comp = None d = diff(src, comp) self.assertEqual(1, len(d)) self.assertTrue( _removed( '', { 'name': 'NAME_UPD', 'data': { 'attr1': 'VALUE_1', 'attr2': 'VALUE_2' } }) in d)
def test_update_dict_with_list_of_dict_reduce(self): src = { 'name': 'NAME', 'data': [{ 'name': 'NAME_1', 'data': 'DATA_1' }, { 'name': 'NAME_2', 'data': 'DATA_2' }, { 'name': 'NAME_3', 'data': 'DATA_3' }] } comp = { 'name': 'NAME_UPD', 'data': [{ 'name': 'NAME_1_UPD', 'data': 'DATA_1_UPD' }, { 'name': 'NAME_2', 'data': 'DATA_2' }] } d = diff(src, comp) self.assertEqual(4, len(d)) self.assertTrue(_updated('name', 'NAME', 'NAME_UPD') in d) self.assertTrue(_updated('data[0].name', 'NAME_1', 'NAME_1_UPD') in d) self.assertTrue(_updated('data[0].data', 'DATA_1', 'DATA_1_UPD') in d) self.assertTrue( _removed('data[2]', { 'name': 'NAME_3', 'data': 'DATA_3' }) in d)
def test_removed_property(self): src = {'name': 'NAME', 'desc': 'DESC'} comp = {'name': 'NAME'} d = diff(src, comp) self.assertEqual(1, len(d)) self.assertTrue(_removed('desc', 'DESC') in d)
def test_delete_value(self): src = 'VALUE' comp = None d = diff(src, comp) self.assertEqual(1, len(d)) self.assertTrue(_removed('', 'VALUE') in d)
def test_removed(self): self.assertEqual({ 'path': 'PATH', 'old_value': 'OLD' }, _removed('PATH', 'OLD'))