def test_all_new(self): src = {} comp = {'name': 'NAME', 'desc': 'DESC'} d = diff(src, comp) self.assertEqual(2, len(d)) self.assertTrue(_added('name', 'NAME') in d) self.assertTrue(_added('desc', 'DESC') in d)
def test_update_list_extend(self): src = ['A', 'B', 'C'] comp = ['A', 'Z', 'C', 'D'] d = diff(src, comp) self.assertEqual(2, len(d)) self.assertTrue(_updated('[1]', 'B', 'Z') in d) self.assertTrue(_added('[3]', 'D') 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_update_dict_with_list_extend(self): src = {'name': 'NAME', 'data': ['A', 'B', 'C']} comp = {'name': 'NAME_UPD', 'data': ['A', 'Z', 'Y', 'D']} d = diff(src, comp) self.assertEqual(4, len(d)) self.assertTrue(_updated('name', 'NAME', 'NAME_UPD') in d) self.assertTrue(_updated('data[1]', 'B', 'Z') in d) self.assertTrue(_updated('data[2]', 'C', 'Y') in d) self.assertTrue(_added('data[3]', 'D') in d)
def test_new_dict(self): src = None comp = {'name': 'NAME_UPD', 'desc': 'DESC_UPD'} d = diff(src, comp) self.assertEqual(1, len(d)) self.assertTrue( _added('', { 'name': 'NAME_UPD', 'desc': 'DESC_UPD' }) in d)
def test_new_dict_with_list(self): src = None comp = {'name': 'NAME', 'data': ['A', 'B', 'C']} d = diff(src, comp) self.assertEqual(1, len(d)) self.assertTrue( _added('', { 'name': 'NAME', 'data': ['A', 'B', 'C'] }) in d)
def test_new_dict_with_dict(self): src = None comp = { 'name': 'NAME_UPD', 'data': { 'attr1': 'VALUE_1', 'attr2': 'VALUE_2' } } d = diff(src, comp) self.assertEqual(1, len(d)) self.assertTrue( _added( '', { 'name': 'NAME_UPD', 'data': { 'attr1': 'VALUE_1', 'attr2': 'VALUE_2' } }) in d)
def test_update_dict_with_list_of_dict_extend(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', 'data': [{ 'name': 'NAME_1', 'data': 'DATA_1' }, { 'name': 'NAME_2', 'data': 'DATA_2' }, { 'name': 'NAME_3', 'data': 'DATA_3' }, { 'name': 'NAME_4', 'data': 'DATA_4' }] } d = diff(src, comp) self.assertEqual(1, len(d)) self.assertTrue( _added('data[3]', { 'name': 'NAME_4', 'data': 'DATA_4' }) in d)
def test_new_property(self): src = {'name': 'NAME'} comp = {'name': 'NAME', 'desc': 'DESC'} d = diff(src, comp) self.assertEqual(1, len(d)) self.assertTrue(_added('desc', 'DESC') in d)
def test_new_value(self): src = None comp = 'VALUE' d = diff(src, comp) self.assertEqual(1, len(d)) self.assertTrue(_added('', 'VALUE') in d)
def test_added(self): self.assertEqual({ 'path': 'PATH', 'new_value': 'NEW' }, _added('PATH', 'NEW'))