def test_entry_to_dict(self): """Test entry to dict conversion.""" # Disable W0212: Test access protected members of admin module. # pylint: disable=W0212 schema = [ ('a', 'a', str), ('b', 'b', [str]), ('c', 'C', int), ('d', 'd', dict), ] self.assertEqual({ 'a': '1', 'b': ['x'], 'C': 1 }, admin._entry_2_dict({ 'a': ['1'], 'b': ['x'], 'c': ['1'] }, schema)) self.assertEqual({ 'a': '1', 'b': ['x'], 'd': { 'x': 1 } }, admin._entry_2_dict( { 'a': ['1'], 'b': ['x'], 'd': ['{"x": 1}'] }, schema)) self.assertEqual({ 'a': ['1'], 'b': ['x'], 'c': ['1'] }, admin._dict_2_entry({ 'a': '1', 'b': ['x'], 'C': 1 }, schema)) self.assertEqual({ 'a': ['1'], 'd': ['{"x": 1}'] }, admin._dict_2_entry({ 'a': '1', 'd': { 'x': 1 } }, schema))
def test_entry_to_dict(self): """Test entry to dict conversion.""" # Disable W0212: Test access protected members of admin module. # pylint: disable=W0212 schema = [ ('a', 'a', str), ('b', 'b', [str]), ('c', 'C', int), ('d', 'd', dict), ('e', 'e', bool), ('f', 'f', bool), ] self.assertEqual( admin._entry_2_dict( { 'a': ['1'], 'b': ['x'], 'c': ['1'], 'e': [True], 'f': [False], }, schema ), { 'a': '1', 'b': ['x'], 'C': 1, 'e': True, 'f': False }, ) self.assertEqual( admin._entry_2_dict( { 'a': ['1'], 'b': ['x'], 'd': ['{"x": 1}'], # XXX: This is necessary until previous bad entries are # cleaned up. 'e': ['True'], 'f': ['1'], }, schema ), { 'a': '1', 'b': ['x'], 'd': { 'x': 1 }, 'e': True, 'f': True, } ) self.assertEqual( admin._dict_2_entry( { 'a': '1', 'b': ['x'], 'C': 1, 'e': False, 'f': True }, schema ), { 'a': ['1'], 'b': ['x'], 'c': ['1'], 'e': [False], 'f': [True], } ) self.assertEqual( admin._dict_2_entry( { 'a': '1', 'd': { 'x': 1 } }, schema ), { 'a': ['1'], 'd': ['{"x": 1}'] } )