Пример #1
0
    def setUp(self):

        self.dm = Mapper(
            {
                'first': {
                    'of': {
                        'all': 'with-string',
                        'with': ['first-item', 'middle-item', 'last-item']
                    },
                    'and': [(0, 1), (1, 2), (2, 3), (3, 4)]
                },
                'filtered': [{
                    'name': 'first',
                    'value': 'good'
                }, {
                    'name': 'second',
                    'value': 'normal'
                }, {
                    'name': 'third',
                    'value': 'bad'
                }],
                'emptylist': {
                    'item': 'itemname'
                },
                'notemptylist': [{
                    'item': 'itemname'
                }, {
                    'item': 'seconditemname'
                }],
                'strvalue':
                'many',
                'strlist': ['many', 'list', 'item'],
                'root':
                'R',
                u'útvonal': {
                    u'árvíztűrőtükörfórógép': 4
                }
            },
            routes={
                'first_of_list': 'first/of/with/0',
                'last_of_list': 'first/of/with/-1',
                'tuple_last_first': 'first/and/-1/0',
                'not_existing_route': 'first/of/here',
                'root': 'root',
                'existing_route': 'first/of/all',
                'filtered_list': 'filtered/name=second/value',
                'attributes_from_list': 'filtered/*/value',
                'whole_list_with_star': 'filtered/*',
                'whole_list_wo_star': 'filtered',
                'range_of_list': 'filtered/0:-1/value',
                'attribute_from_dict_via_expected_list': 'emptylist/~0/item',
                'attribute_from_list': 'notemptylist/~0/item',
                'string_value': 'strvalue',
                'string_to_list': 'strvalue/!/0',
                'string_to_list_check_length': 'strvalue/!/1',
                'first_attribute_from_list': 'strlist/!/0',
                'next_attribute_from_list': 'strlist/!/1',
                'accent_path': u'útvonal/árvíztűrőtükörfórógép'
            })
Пример #2
0
    def setUp(self):

        self.dm = Mapper([{
            'id': 1,
            'active': True,
            'name': 'Steve',
            'others': {
                'age': 41,
                'childs': {
                    'year': 1991
                }
            },
        }, {
            'id': 2,
            'active': False,
            'name': 'Peter',
            'others': {
                'age': 31,
                'childs': [{
                    'year': 1999
                }, {
                    'year': 1992
                }]
            },
        }, {
            'id': 3,
            'active': True,
            'name': 'Bruce',
            'others': {
                'age': 45,
                'childs': [{
                    'year': 1987
                }, {
                    'year': 1987
                }]
            },
        }])

        self.dict_dm = Mapper({
            'id': 1,
            'name': 'Steve',
            'others': {
                'age': 41,
                'childs': {
                    'year': 1991
                }
            },
        })
Пример #3
0
    def setUp(self):

        self.inner_test_object = TestObject(attr='anything')
        self.test_object = TestObject(
            string='item',
            list=['first-item', 'middle', 'last-item'],
            object=self.inner_test_object)
        self.dm = Mapper(self.test_object)
Пример #4
0
    def setUp(self):

        self.test_object = TestObject(attr='anything')
        self.dm = Mapper({
            'string': 'item',
            'list': ['first-item', 'middle', 'last-item'],
            'object': self.test_object,
            'multi-level': {
                'existing-node': True
            }
        })
Пример #5
0
    def setUp( self ):

        self.dm = Mapper({
            'first': {
                'of': {
                    'all': 'with-string',
                    'with': [ 'first-item', 'middle-item', 'last-item' ]
                },
                'and': [ (0, 1), (1, 2), (2, 3), (3, 4) ]
            },
            'filtered': [ { 
                'name': 'first', 
                'value': 'good'
            }, {
                'name': 'second',
                'value': 'normal'
            }, {
                'name': 'third',
                'value': 'bad'
            } ],
            'emptylist': {
                'item': 'itemname'
            },
            'notemptylist': [
                { 'item': 'itemname' },
                { 'item': 'seconditemname' }
            ],
            'strvalue': 'many',
            'strlist': [ 'many', 'list', 'item' ],
            'root': 'R',
            u'útvonal': { u'árvíztűrőtükörfórógép': 4 }
        }, routes = { 
            'first_of_list': 'first/of/with/0',
            'last_of_list': 'first/of/with/-1',
            'tuple_last_first': 'first/and/-1/0',
            'not_existing_route': 'first/of/here',
            'root': 'root',
            'existing_route': 'first/of/all',
            'filtered_list': 'filtered/name=second/value',
            'attributes_from_list': 'filtered/*/value',
            'whole_list_with_star': 'filtered/*',
            'whole_list_wo_star': 'filtered',
            'range_of_list': 'filtered/0:-1/value',
            'attribute_from_dict_via_expected_list': 'emptylist/~0/item',
            'attribute_from_list': 'notemptylist/~0/item',
            'string_value': 'strvalue',
            'string_to_list': 'strvalue/!/0',
            'string_to_list_check_length': 'strvalue/!/1',
            'first_attribute_from_list': 'strlist/!/0',
            'next_attribute_from_list': 'strlist/!/1',
            'accent_path': u'útvonal/árvíztűrőtükörfórógép'
        })
Пример #6
0
    def getValues(self, obj, base=None):

        ret_dict = Mapper(obj, routes=self.normal_rules).getRoutes()
        ret_dict.update(Mapper(base, routes=self.base_rules).getRoutes())

        return ret_dict
Пример #7
0
    def getValues( self, obj, base = None ):

        ret_dict = Mapper( obj, routes = self.normal_rules ).getRoutes()
        ret_dict.update( Mapper( base, routes = self.base_rules ).getRoutes() )

        return ret_dict
Пример #8
0
class TestRoutes( unittest.TestCase ):

    def setUp( self ):

        self.dm = Mapper({
            'first': {
                'of': {
                    'all': 'with-string',
                    'with': [ 'first-item', 'middle-item', 'last-item' ]
                },
                'and': [ (0, 1), (1, 2), (2, 3), (3, 4) ]
            },
            'filtered': [ { 
                'name': 'first', 
                'value': 'good'
            }, {
                'name': 'second',
                'value': 'normal'
            }, {
                'name': 'third',
                'value': 'bad'
            } ],
            'emptylist': {
                'item': 'itemname'
            },
            'notemptylist': [
                { 'item': 'itemname' },
                { 'item': 'seconditemname' }
            ],
            'strvalue': 'many',
            'strlist': [ 'many', 'list', 'item' ],
            'root': 'R',
            u'útvonal': { u'árvíztűrőtükörfórógép': 4 }
        }, routes = { 
            'first_of_list': 'first/of/with/0',
            'last_of_list': 'first/of/with/-1',
            'tuple_last_first': 'first/and/-1/0',
            'not_existing_route': 'first/of/here',
            'root': 'root',
            'existing_route': 'first/of/all',
            'filtered_list': 'filtered/name=second/value',
            'attributes_from_list': 'filtered/*/value',
            'whole_list_with_star': 'filtered/*',
            'whole_list_wo_star': 'filtered',
            'range_of_list': 'filtered/0:-1/value',
            'attribute_from_dict_via_expected_list': 'emptylist/~0/item',
            'attribute_from_list': 'notemptylist/~0/item',
            'string_value': 'strvalue',
            'string_to_list': 'strvalue/!/0',
            'string_to_list_check_length': 'strvalue/!/1',
            'first_attribute_from_list': 'strlist/!/0',
            'next_attribute_from_list': 'strlist/!/1',
            'accent_path': u'útvonal/árvíztűrőtükörfórógép'
        })

    def test_map_with_list( self ):

        self.assertEqual( self.dm.first_of_list, 'first-item' )
        self.assertEqual( self.dm.last_of_list, 'last-item' )
        self.assertEqual( self.dm.tuple_last_first, 3 )
        self.assertIsNone( self.dm.not_existing_route )
        self.assertEqual( self.dm.root, 'R' )
        self.assertEqual( self.dm.existing_route, 'with-string' )
        self.assertEqual( self.dm.filtered_list, 'normal' )
        self.assertEqual( self.dm.range_of_list, ['good','normal'] )
        self.assertEqual( self.dm.attributes_from_list, ['good','normal','bad'] )
        self.assertEqual( self.dm.attribute_from_dict_via_expected_list, 'itemname' )
        self.assertEqual( self.dm.attribute_from_list, 'itemname' )
        self.assertEqual( self.dm.string_value, 'many' )
        self.assertEqual( self.dm.string_to_list, 'many' )
        self.assertIsNone( self.dm.string_to_list_check_length )
        self.assertEqual( self.dm.first_attribute_from_list, 'many' )
        self.assertEqual( self.dm.next_attribute_from_list, 'list' )
        self.assertEqual( self.dm.whole_list_with_star, self.dm.whole_list_wo_star )
        self.assertEqual( self.dm.accent_path, 4 )

    def test_routes( self ):

        self.assertEqual( self.dm.getRoutes(), {
            'first_of_list': 'first-item',
            'last_of_list': 'last-item',
            'tuple_last_first': 3,
            'not_existing_route': None,
            'root': 'R',
            'existing_route': 'with-string',
            'filtered_list': 'normal',
            'range_of_list': ['good','normal'],
            'attributes_from_list': ['good','normal','bad'],
            'attribute_from_dict_via_expected_list': 'itemname',
            'attribute_from_list': 'itemname',
            'string_value': 'many',
            'string_to_list': 'many',
            'string_to_list_check_length': None,
            'first_attribute_from_list': 'many',
            'next_attribute_from_list': 'list',
            'whole_list_with_star': self.dm.whole_list_wo_star,
            'whole_list_wo_star': self.dm.whole_list_with_star,
            'accent_path': 4,
        })
Пример #9
0
    def setUp(self):

        self.dm = Mapper(['first-item', 'middle', 'last-item'])
Пример #10
0
    def setUp(self):

        self.dm = Mapper('anything')
Пример #11
0
    def setUp(self):

        self.dm = Mapper(None)
Пример #12
0
class TestRoutes(unittest.TestCase):
    def setUp(self):

        self.dm = Mapper(
            {
                'first': {
                    'of': {
                        'all': 'with-string',
                        'with': ['first-item', 'middle-item', 'last-item']
                    },
                    'and': [(0, 1), (1, 2), (2, 3), (3, 4)]
                },
                'filtered': [{
                    'name': 'first',
                    'value': 'good'
                }, {
                    'name': 'second',
                    'value': 'normal'
                }, {
                    'name': 'third',
                    'value': 'bad'
                }],
                'emptylist': {
                    'item': 'itemname'
                },
                'notemptylist': [{
                    'item': 'itemname'
                }, {
                    'item': 'seconditemname'
                }],
                'strvalue':
                'many',
                'strlist': ['many', 'list', 'item'],
                'root':
                'R',
                u'útvonal': {
                    u'árvíztűrőtükörfórógép': 4
                }
            },
            routes={
                'first_of_list': 'first/of/with/0',
                'last_of_list': 'first/of/with/-1',
                'tuple_last_first': 'first/and/-1/0',
                'not_existing_route': 'first/of/here',
                'root': 'root',
                'existing_route': 'first/of/all',
                'filtered_list': 'filtered/name=second/value',
                'attributes_from_list': 'filtered/*/value',
                'whole_list_with_star': 'filtered/*',
                'whole_list_wo_star': 'filtered',
                'range_of_list': 'filtered/0:-1/value',
                'attribute_from_dict_via_expected_list': 'emptylist/~0/item',
                'attribute_from_list': 'notemptylist/~0/item',
                'string_value': 'strvalue',
                'string_to_list': 'strvalue/!/0',
                'string_to_list_check_length': 'strvalue/!/1',
                'first_attribute_from_list': 'strlist/!/0',
                'next_attribute_from_list': 'strlist/!/1',
                'accent_path': u'útvonal/árvíztűrőtükörfórógép'
            })

    def test_map_with_list(self):

        self.assertEqual(self.dm.first_of_list, 'first-item')
        self.assertEqual(self.dm.last_of_list, 'last-item')
        self.assertEqual(self.dm.tuple_last_first, 3)
        self.assertIsNone(self.dm.not_existing_route)
        self.assertEqual(self.dm.root, 'R')
        self.assertEqual(self.dm.existing_route, 'with-string')
        self.assertEqual(self.dm.filtered_list, 'normal')
        self.assertEqual(self.dm.range_of_list, ['good', 'normal'])
        self.assertEqual(self.dm.attributes_from_list,
                         ['good', 'normal', 'bad'])
        self.assertEqual(self.dm.attribute_from_dict_via_expected_list,
                         'itemname')
        self.assertEqual(self.dm.attribute_from_list, 'itemname')
        self.assertEqual(self.dm.string_value, 'many')
        self.assertEqual(self.dm.string_to_list, 'many')
        self.assertIsNone(self.dm.string_to_list_check_length)
        self.assertEqual(self.dm.first_attribute_from_list, 'many')
        self.assertEqual(self.dm.next_attribute_from_list, 'list')
        self.assertEqual(self.dm.whole_list_with_star,
                         self.dm.whole_list_wo_star)
        self.assertEqual(self.dm.accent_path, 4)

    def test_routes(self):

        self.assertEqual(
            self.dm.getRoutes(), {
                'first_of_list': 'first-item',
                'last_of_list': 'last-item',
                'tuple_last_first': 3,
                'not_existing_route': None,
                'root': 'R',
                'existing_route': 'with-string',
                'filtered_list': 'normal',
                'range_of_list': ['good', 'normal'],
                'attributes_from_list': ['good', 'normal', 'bad'],
                'attribute_from_dict_via_expected_list': 'itemname',
                'attribute_from_list': 'itemname',
                'string_value': 'many',
                'string_to_list': 'many',
                'string_to_list_check_length': None,
                'first_attribute_from_list': 'many',
                'next_attribute_from_list': 'list',
                'whole_list_with_star': self.dm.whole_list_wo_star,
                'whole_list_wo_star': self.dm.whole_list_with_star,
                'accent_path': 4,
            })