Exemplo n.º 1
0
 def test_non_string_ids_in_arrays(self):
     table = [{'foreign': [1, 2]}, {'foreign': [3, 4]}]
     id_map = {'1': 'new 1', '2': 'new 2', '3': 'new 3', '4': 'new 4'}
     result = p.fix_foreign_keys(table, 'foreign', id_map)
     expected = [{
         'foreign': ['new 1', 'new 2']
     }, {
         'foreign': ['new 3', 'new 4']
     }]
     self.assertEqual(result, expected)
Exemplo n.º 2
0
 def test_correct_drop_nonexistent_ids_in_arrays(self):
     table = [{
         'foreign': ['old id 1', 'not old id 2']
     }, {
         'foreign': ['old id 3', 'not old id 4']
     }]
     id_map = {
         'old id 1': 'new id 1',
         'old id 2': 'new id 2',
         'old id 3': 'new id 3',
         'old id 4': 'new id 4'
     }
     result = p.fix_foreign_keys(table, 'foreign', id_map)
     expected = [{'foreign': ['new id 1']}, {'foreign': ['new id 3']}]
     self.assertEqual(result, expected)
Exemplo n.º 3
0
 def test_deal_with_ids_that_are_not_strings(self):
     table = [{'foreign': 1}, {'foreign': 2}]
     id_map = {'1': 'new 1', '2': 'new 2'}
     result = p.fix_foreign_keys(table, 'foreign', id_map)
     expected = [{'foreign': 'new 1'}, {'foreign': 'new 2'}]
     self.assertEqual(result, expected)
Exemplo n.º 4
0
 def test_drop_nonexistent_keys(self):
     table = [{'foreign': 'not old id 1'}, {'foreign': 'not old id 2'}]
     id_map = {'old id 1': 'new id 1', 'old id 2': 'new id 2'}
     result = p.fix_foreign_keys(table, 'foreign', id_map)
     expected = [{}, {}]
     self.assertEqual(result, expected)
Exemplo n.º 5
0
 def test_leave_other_columns_alone(self):
     table = [{'not foreign': 'old id 1'}, {'not foreign': 'old id 2'}]
     id_map = {'old id 1': 'new id 1', 'old id 2': 'new id 2'}
     result = p.fix_foreign_keys(table, 'foreign', id_map)
     expected = [{'not foreign': 'old id 1'}, {'not foreign': 'old id 2'}]
     self.assertEqual(result, expected)
Exemplo n.º 6
0
 def test_correct_foreign_keys(self):
     table = [{'foreign': 'old id 1'}, {'foreign': 'old id 2'}]
     id_map = {'old id 1': 'new id 1', 'old id 2': 'new id 2'}
     result = p.fix_foreign_keys(table, 'foreign', id_map)
     expected = [{'foreign': 'new id 1'}, {'foreign': 'new id 2'}]
     self.assertEqual(result, expected)