def test_converter_rename_and_exclude(self): # test if fields are reverse-renamed correctly converter = Converter(exclude=[u'x'], rename=[(u'z', u'i')]) self.assertEquals({ u'y': u'b', u'i': u'c' }, converter.from_schema({ u'x': u'a', u'y': u'b', u'z': u'c' })) self.assertEquals({ u'y': u'b', u'z': u'c' }, converter.to_schema({ u'y': u'b', u'i': u'c' })) # test Converter where order of exclude and rename is important # (here, 'x' is excluded first, and then *not* renamed because) converter = Converter(exclude=[u'x'], rename=[(u'x', u'a')]) self.assertEquals({u'y': u'b'}, converter.from_schema({ u'x': u'a', u'y': u'b' }))
def test_rename_inverse(self): converter = Converter(rename=[(u'x', u'g'), (u'y', u'h')]) doc = {u'x': u'a', u'y': u'b', u'z': u'c'} self.assertEquals(doc, converter.to_schema(converter.from_schema(doc))) doc = {u'g': u'a', u'h': u'b', u'z': u'c'} self.assertEquals(doc, converter.from_schema(converter.to_schema(doc)))
def test_rename_inverse(self): converter = Converter(rename=[(u'x', u'g'), (u'y', u'h')]) doc = {u'x': u'a', u'y': u'b', u'z': u'c'} self.assertEquals(doc, converter.to_schema(converter.from_schema(doc))) doc = {u'g': u'a', u'h': u'b', u'z': u'c'} self.assertEquals(doc, converter.from_schema(converter.to_schema(doc)))
def test_converter_rename_and_exclude(self): # test if fields are reverse-renamed correctly converter = Converter(exclude=[u'x'], rename=[(u'z', u'i')]) self.assertEquals({u'y': u'b', u'i': u'c'}, converter.from_schema({u'x': u'a', u'y': u'b', u'z': u'c'})) self.assertEquals({u'y': u'b', u'z': u'c'}, converter.to_schema({u'y': u'b', u'i': u'c'})) # test Converter where order of exclude and rename is important # (here, 'x' is excluded first, and then *not* renamed because) converter = Converter(exclude=[u'x'], rename=[(u'x', u'a')]) self.assertEquals({u'y': u'b'}, converter.from_schema({u'x': u'a', u'y': u'b'}))
def test_from_schema_rename(self): # test if fields are renamed correctly converter = Converter(rename=[(u'x', u'g'), (u'y', u'h')]) self.assertEquals({u'g': u'a', u'h': u'b', u'z': u'c'}, converter.from_schema({u'x': u'a', u'y': u'b', u'z': u'c'}))
def test_from_schema_exclude(self): # test if fields are excluded correctly converter = Converter(exclude=[u'x', u'y']) self.assertEquals({u'z': u'c'}, converter.from_schema({ u'x': u'a', u'y': u'b', u'z': u'c' }))
def test_schema_exclude_recursive(self): converter = Converter(exclude=[u'a.b']) self.assertEquals({ u'a': {}, u'x': u'y' }, converter.from_schema({ u'a': { u'b': 666 }, u'x': u'y' }))
def test_from_schema_rename(self): # test if fields are renamed correctly converter = Converter(rename=[(u'x', u'g'), (u'y', u'h')]) self.assertEquals({ u'g': u'a', u'h': u'b', u'z': u'c' }, converter.from_schema({ u'x': u'a', u'y': u'b', u'z': u'c' }))
def test_schema_exclude_recursive(self): converter = Converter(exclude=[u'a.b']) self.assertEquals({u'a': {}, u'x': u'y'}, converter.from_schema({u'a': {u'b': 666}, u'x': u'y'}))
def test_from_schema_exclude(self): # test if fields are excluded correctly converter = Converter(exclude=[u'x', u'y']) self.assertEquals({u'z': u'c'}, converter.from_schema({u'x': u'a', u'y': u'b', u'z': u'c'}))