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_to_schema_rename(self): # test if fields are reverse-renamed correctly converter = Converter(rename=[(u'x', u'g'), (u'y', u'h')]) self.assertEquals({u'x': u'a', u'y': u'b', u'z': u'c'}, converter.to_schema({u'g': u'a', u'h': u'b', u'z': u'c'}))
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_to_schema_rename(self): # test if fields are reverse-renamed correctly converter = Converter(rename=[(u'x', u'g'), (u'y', u'h')]) self.assertEquals({ u'x': u'a', u'y': u'b', u'z': u'c' }, converter.to_schema({ u'g': u'a', u'h': u'b', u'z': u'c' }))
def test_to_schema_exclude(self): # nothing should happen when converting to the schema converter = Converter(exclude=[u'x', u'y']) self.assertEquals({ u'x': u'a', u'y': u'b', u'z': u'c' }, converter.to_schema({ u'x': u'a', u'y': u'b', u'z': u'c' }))
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_to_schema_exclude(self): # nothing should happen when converting to the schema converter = Converter(exclude=[u'x', u'y']) self.assertEquals({u'x': u'a', u'y': u'b', u'z': u'c'}, converter.to_schema({u'x': u'a', u'y': u'b', u'z': u'c'}))