Пример #1
0
    def test_mapping_decorator_cross_classes(self):
        """ Mappings should not propagate to other classes"""
        class MomMapper(Component):
            _name = "mom.mapper"
            _inherit = "base.mapper"
            _apply_on = "res.users"

            @changed_by("name", "city")
            @mapping
            def name(self):
                pass

        class ZappMapper(Component):
            _name = "zapp.mapper"
            _inherit = "base.mapper"
            _apply_on = "res.users"

            @changed_by("email")
            @only_create
            @mapping
            def email(self):
                pass

        self._build_components(MomMapper, ZappMapper)

        mom_def = MappingDefinition(changed_by={"name", "city"},
                                    only_create=False)
        zapp_def = MappingDefinition(changed_by={"email"}, only_create=True)

        comp = self.comp_registry["mom.mapper"]
        self.assertEqual(comp._map_methods, {"name": mom_def})
        comp = self.comp_registry["zapp.mapper"]
        self.assertEqual(comp._map_methods, {"email": zapp_def})
Пример #2
0
    def test_mapping_decorator_cumul(self):
        """ Mappings should cumulate the ``super`` mappings
        and the local mappings."""
        class FryMapper(Component):
            _name = "fry.mapper"
            _inherit = "base.mapper"
            _apply_on = "res.users"

            @changed_by("name", "city")
            @mapping
            def name(self):
                pass

        class FryMapperInherit(Component):
            _inherit = "fry.mapper"

            @changed_by("email")
            @mapping
            def email(self):
                pass

        self._build_components(FryMapper, FryMapperInherit)

        name_def = MappingDefinition(changed_by={"name", "city"},
                                     only_create=False)
        email_def = MappingDefinition(changed_by={"email"}, only_create=False)

        comp = self.comp_registry["fry.mapper"]
        self.assertEqual(comp._map_methods, {
            "name": name_def,
            "email": email_def
        })
Пример #3
0
    def test_mapping_decorator_cross_classes(self):
        """ Mappings should not propagate to other classes"""
        class MomMapper(Component):
            _name = 'mom.mapper'
            _inherit = 'base.mapper'
            _apply_on = 'res.users'

            @changed_by('name', 'city')
            @mapping
            def name(self):
                pass

        class ZappMapper(Component):
            _name = 'zapp.mapper'
            _inherit = 'base.mapper'
            _apply_on = 'res.users'

            @changed_by('email')
            @only_create
            @mapping
            def email(self):
                pass

        self._build_components(MomMapper, ZappMapper)

        mom_def = MappingDefinition(changed_by=set(('name', 'city')),
                                    only_create=False)
        zapp_def = MappingDefinition(changed_by=set(('email',)),
                                     only_create=True)

        comp = self.comp_registry['mom.mapper']
        self.assertEqual(comp._map_methods, {'name': mom_def})
        comp = self.comp_registry['zapp.mapper']
        self.assertEqual(comp._map_methods, {'email': zapp_def})
Пример #4
0
    def test_mapping_decorator_cumul(self):
        """ Mappings should cumulate the ``super`` mappings
        and the local mappings."""
        class FryMapper(Component):
            _name = 'fry.mapper'
            _inherit = 'base.mapper'
            _apply_on = 'res.users'

            @changed_by('name', 'city')
            @mapping
            def name(self):
                pass

        class FryMapperInherit(Component):
            _inherit = 'fry.mapper'

            @changed_by('email')
            @mapping
            def email(self):
                pass

        self._build_components(FryMapper, FryMapperInherit)

        name_def = MappingDefinition(changed_by=set(('name', 'city')),
                                     only_create=False)
        email_def = MappingDefinition(changed_by=set(('email',)),
                                      only_create=False)

        comp = self.comp_registry['fry.mapper']
        self.assertEqual(comp._map_methods,
                         {'name': name_def,
                          'email': email_def})
Пример #5
0
    def test_mapping_decorator(self):
        class KifKrokerMapper(Component):
            _name = "kif.kroker.mapper"
            _inherit = "base.mapper"

            @changed_by("name", "city")
            @mapping
            @only_create
            def name(self):
                pass

            @changed_by("email")
            @mapping
            def email(self):
                pass

            @changed_by("street")
            @mapping
            def street(self):
                pass

            def no_decorator(self):
                pass

        # build our mapper component
        KifKrokerMapper._build_component(self.comp_registry)

        # what mappings we expect
        name_def = MappingDefinition(changed_by={"name", "city"},
                                     only_create=True)
        email_def = MappingDefinition(changed_by={"email"}, only_create=False)
        street_def = MappingDefinition(changed_by={"street"},
                                       only_create=False)

        # get our component by name in the components registry
        comp = self.comp_registry["kif.kroker.mapper"]
        # _map_methods contains the aggregated mapping methods for a Mapper
        self.assertEqual(
            comp._map_methods,
            {
                "name": name_def,
                "email": email_def,
                "street": street_def
            },
        )
Пример #6
0
    def test_mapping_decorator(self):
        class KifKrokerMapper(Component):
            _name = 'kif.kroker.mapper'
            _inherit = 'base.mapper'

            @changed_by('name', 'city')
            @mapping
            @only_create
            def name(self):
                pass

            @changed_by('email')
            @mapping
            def email(self):
                pass

            @changed_by('street')
            @mapping
            def street(self):
                pass

            def no_decorator(self):
                pass

        # build our mapper component
        KifKrokerMapper._build_component(self.comp_registry)

        # what mappings we expect
        name_def = MappingDefinition(changed_by=set(('name', 'city')),
                                     only_create=True)
        email_def = MappingDefinition(changed_by=set(('email',)),
                                      only_create=False)
        street_def = MappingDefinition(changed_by=set(('street',)),
                                       only_create=False)

        # get our component by name in the components registry
        comp = self.comp_registry['kif.kroker.mapper']
        # _map_methods contains the aggregated mapping methods for a Mapper
        self.assertEqual(comp._map_methods,
                         {'name': name_def,
                          'email': email_def,
                          'street': street_def,
                          })
Пример #7
0
    def test_several_bases_cumul(self):
        class FryMapper(Component):
            _name = "fry.mapper"
            _inherit = "base.mapper"
            _apply_on = "res.users"

            @changed_by("name", "city")
            @mapping
            def name(self):
                pass

            @only_create
            @mapping
            def street(self):
                pass

            @only_create
            @mapping
            def zip(self):
                pass

        class FarnsworthMapper(Component):
            _name = "farnsworth.mapper"
            _inherit = "base.mapper"
            _apply_on = "res.users"

            @changed_by("email")
            @mapping
            def name(self):
                pass

            @changed_by("street")
            @mapping
            def city(self):
                pass

            @mapping
            def zip(self):
                pass

        class ThirdMapper(Component):
            _name = "third.mapper"
            _inherit = ["fry.mapper", "farnsworth.mapper"]
            _apply_on = "res.users"

            @changed_by("email", "street")
            @mapping
            def name(self):
                pass

            @mapping
            def email(self):
                pass

        self._build_components(FryMapper, FarnsworthMapper, ThirdMapper)

        name_def = MappingDefinition(
            changed_by={"name", "city", "email", "street"}, only_create=False)
        street_def = MappingDefinition(changed_by=set(), only_create=True)
        city_def = MappingDefinition(changed_by={"street"}, only_create=False)
        email_def = MappingDefinition(changed_by=set(), only_create=False)
        zip_def = MappingDefinition(changed_by=set(), only_create=True)

        comp = self.comp_registry["third.mapper"]
        self.assertEqual(comp._map_methods["name"], name_def)
        self.assertEqual(comp._map_methods["street"], street_def)
        self.assertEqual(comp._map_methods["city"], city_def)
        self.assertEqual(comp._map_methods["email"], email_def)
        self.assertEqual(comp._map_methods["zip"], zip_def)
Пример #8
0
    def test_several_bases_cumul(self):
        class FryMapper(Component):
            _name = 'fry.mapper'
            _inherit = 'base.mapper'
            _apply_on = 'res.users'

            @changed_by('name', 'city')
            @mapping
            def name(self):
                pass

            @only_create
            @mapping
            def street(self):
                pass

            @only_create
            @mapping
            def zip(self):
                pass

        class FarnsworthMapper(Component):
            _name = 'farnsworth.mapper'
            _inherit = 'base.mapper'
            _apply_on = 'res.users'

            @changed_by('email')
            @mapping
            def name(self):
                pass

            @changed_by('street')
            @mapping
            def city(self):
                pass

            @mapping
            def zip(self):
                pass

        class ThirdMapper(Component):
            _name = 'third.mapper'
            _inherit = ['fry.mapper', 'farnsworth.mapper']
            _apply_on = 'res.users'

            @changed_by('email', 'street')
            @mapping
            def name(self):
                pass

            @mapping
            def email(self):
                pass

        self._build_components(FryMapper, FarnsworthMapper, ThirdMapper)

        name_def = MappingDefinition(changed_by=set(('name', 'city',
                                                     'email', 'street')),
                                     only_create=False)
        street_def = MappingDefinition(changed_by=set([]),
                                       only_create=True)
        city_def = MappingDefinition(changed_by=set(('street',)),
                                     only_create=False)
        email_def = MappingDefinition(changed_by=set([]),
                                      only_create=False)
        zip_def = MappingDefinition(changed_by=set([]),
                                    only_create=True)

        comp = self.comp_registry['third.mapper']
        self.assertEqual(comp._map_methods['name'], name_def)
        self.assertEqual(comp._map_methods['street'], street_def)
        self.assertEqual(comp._map_methods['city'], city_def)
        self.assertEqual(comp._map_methods['email'], email_def)
        self.assertEqual(comp._map_methods['zip'], zip_def)