Example #1
0
    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)))
Example #2
0
    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)))
Example #3
0
 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'}))
Example #4
0
    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'
                          }))
Example #5
0
 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'
     }))
Example #6
0
 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'
     }))
Example #7
0
    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'}))
Example #8
0
 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'}))