Пример #1
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'
                          }))
Пример #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)))
Пример #3
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)))
Пример #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'}))
Пример #5
0
 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'}))
Пример #6
0
 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'
                       }))
Пример #7
0
 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'
     }))
Пример #8
0
 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'
     }))
Пример #9
0
 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'}))
Пример #10
0
 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'}))