Ejemplo n.º 1
0
 def setUp(self):
     super(test_backend_register, self).setUp()
     self.service = 'calamitorium'
     self.version = '1.14'
     self.parent = Backend(self.service)
     self.backend = Backend(parent=self.parent, version=self.version)
     self.session = ConnectorSession(self.cr, self.uid)
Ejemplo n.º 2
0
    def test_repr(self):
        parent = Backend(self.service)
        self.assertEqual(str(parent), "Backend('calamitorium')")
        self.assertEqual(repr(parent), "<Backend 'calamitorium'>")

        backend = Backend(parent=parent, version='1.14')
        self.assertEqual(str(backend), "Backend('calamitorium', '1.14')")
        self.assertEqual(repr(backend), "<Backend 'calamitorium', '1.14'>")
Ejemplo n.º 3
0
 def setUp(self):
     super(test_mapper_recordsets, self).setUp()
     self.backend = mock.Mock(wraps=Backend('x', version='y'),
                              name='backend')
     backend_record = mock.Mock()
     backend_record.get_backend.return_value = self.backend
     backend_record.env = self.env
     self.connector_env = ConnectorEnvironment(backend_record,
                                               'res.partner')
Ejemplo n.º 4
0
 def setUp(self):
     super(test_mapper_binding, self).setUp()
     self.session = ConnectorSession(self.cr, self.uid)
     self.backend = mock.Mock(wraps=Backend('x', version='y'),
                              name='backend')
     backend_record = mock.Mock()
     backend_record.get_backend.return_value = self.backend
     self.connector_env = ConnectorEnvironment(backend_record, self.session,
                                               'res.partner')
     self.country_binder = mock.Mock(name='country_binder')
     self.country_binder.return_value = self.country_binder
     self.backend.get_class.return_value = self.country_binder
Ejemplo n.º 5
0
class test_backend_register(common.TransactionCase):
    """ Test registration of classes on the Backend"""
    def setUp(self):
        super(test_backend_register, self).setUp()
        self.service = 'calamitorium'
        self.version = '1.14'
        self.parent = Backend(self.service)
        self.backend = Backend(parent=self.parent, version=self.version)
        self.session = ConnectorSession(self.cr, self.uid)

    def tearDown(self):
        super(test_backend_register, self).tearDown()
        BACKENDS.backends.clear()
        del self.backend._class_entries[:]

    def test_register_class(self):
        class BenderBinder(Binder):
            _model_name = 'res.users'

        self.backend.register_class(BenderBinder)
        ref = self.backend.get_class(Binder, self.session, 'res.users')
        self.assertEqual(ref, BenderBinder)

    def test_register_class_decorator(self):
        @self.backend
        class ZoidbergMapper(ExportMapper):
            _model_name = 'res.users'

        ref = self.backend.get_class(ExportMapper, self.session, 'res.users')
        self.assertEqual(ref, ZoidbergMapper)

    def test_register_class_parent(self):
        """ It should get the parent's class when no class is defined"""
        @self.parent
        class FryBinder(Binder):
            _model_name = 'res.users'

        ref = self.backend.get_class(Binder, self.session, 'res.users')
        self.assertEqual(ref, FryBinder)

    def test_no_register_error(self):
        """ Error when asking for a class and none is found"""
        with self.assertRaises(NoConnectorUnitError):
            self.backend.get_class(BackendAdapter, self.session, 'res.users')

    def test_get_class_installed_module(self):
        """ Only class from an installed module should be returned """
        class LambdaUnit(ConnectorUnit):
            _model_name = 'res.users'

        @self.backend
        class LambdaYesUnit(LambdaUnit):
            _model_name = 'res.users'

        class LambdaNoUnit(LambdaUnit):
            _model_name = 'res.users'

        # trick the origin of the class, let it think
        # that it comes from the odoo module 'not installed module'
        LambdaNoUnit._module = 'not installed module'
        self.backend(LambdaNoUnit)

        matching_cls = self.backend.get_class(LambdaUnit, self.session,
                                              'res.users')
        self.assertEqual(matching_cls, LambdaYesUnit)

    def test_get_class_replacing_module(self):
        """ Returns the replacing ConnectorUnit"""
        class LambdaUnit(ConnectorUnit):
            _model_name = 'res.users'

        @self.backend
        class LambdaNoUnit(LambdaUnit):
            _model_name = 'res.users'

        @self.backend(replacing=LambdaNoUnit)
        class LambdaYesUnit(LambdaUnit):
            _model_name = 'res.users'

        matching_cls = self.backend.get_class(LambdaUnit, self.session,
                                              'res.users')
        self.assertEqual(matching_cls, LambdaYesUnit)

    def test_get_class_replacing_uninstalled_module(self):
        """ Does not return the replacing ConnectorUnit of an
        uninstalled module """
        class LambdaUnit(ConnectorUnit):
            _model_name = 'res.users'

        @self.backend
        class LambdaYesUnit(LambdaUnit):
            _model_name = 'res.users'

        class LambdaNoUnit(LambdaUnit):
            _model_name = 'res.users'

        # trick the origin of the class, let it think
        # that it comes from the Odoo module 'not installed module'
        LambdaNoUnit._module = 'not installed module'
        self.backend(LambdaNoUnit, replacing=LambdaYesUnit)

        matching_cls = self.backend.get_class(LambdaUnit, self.session,
                                              'res.users')
        self.assertEqual(matching_cls, LambdaYesUnit)

    def test_get_class_replacing_diamond(self):
        """ Replace several classes in a diamond fashion """
        class LambdaUnit(ConnectorUnit):
            _model_name = 'res.users'

        @self.backend
        class LambdaNoUnit(LambdaUnit):
            _model_name = 'res.users'

        @self.backend
        class LambdaNo2Unit(LambdaUnit):
            _model_name = 'res.users'

        @self.backend(replacing=(LambdaNoUnit, LambdaNo2Unit))
        class LambdaYesUnit(LambdaUnit):
            _model_name = 'res.users'

        matching_cls = self.backend.get_class(LambdaUnit, self.session,
                                              'res.users')
        self.assertEqual(matching_cls, LambdaYesUnit)

    def test_get_class_replacing_unregistered(self):
        """ Replacing an unregistered class raise ValueError """
        class LambdaUnit(ConnectorUnit):
            _model_name = 'res.users'

        with self.assertRaises(ValueError):

            @self.backend(replacing=LambdaUnit)
            class LambdaNoUnit(LambdaUnit):
                _model_name = 'res.users'

    def test_get_class_replacing_self(self):
        """ A class should not be able to replace itself """
        class LambdaUnit(ConnectorUnit):
            _model_name = 'res.users'

        @self.backend
        class LambdaRecurseUnit(LambdaUnit):
            _model_name = 'res.users'

        with self.assertRaises(ValueError):
            self.backend.register_class(LambdaRecurseUnit,
                                        replacing=LambdaRecurseUnit)
Ejemplo n.º 6
0
 def test_backend_version(self):
     """ Find a backend with a version """
     parent = Backend(self.service)
     backend = Backend(parent=parent, version='1.14')
     found_ref = get_backend(self.service, version='1.14')
     self.assertEqual(backend, found_ref)
Ejemplo n.º 7
0
 def test_get_backend(self):
     """ Find a backend """
     backend = Backend(self.service)
     found_ref = get_backend(self.service)
     self.assertEqual(backend, found_ref)
Ejemplo n.º 8
0
 def test_no_service(self):
     """ Should raise an error because no service or parent is defined"""
     with self.assertRaises(ValueError):
         Backend(version='1.14')
Ejemplo n.º 9
0
 def test_parent(self):
     """ Bind the backend to a parent backend"""
     version = '1.14'
     backend = Backend(self.service)
     child_backend = Backend(parent=backend, version=version)
     self.assertEqual(child_backend.service, backend.service)
Ejemplo n.º 10
0
 def test_new_backend(self):
     """ Create a backend"""
     version = '1.14'
     backend = Backend(self.service, version=version)
     self.assertEqual(backend.service, self.service)
     self.assertEqual(backend.version, version)
Ejemplo n.º 11
0
# -*- coding: utf-8 -*-
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.addons.connector.backend import Backend

test_backend = Backend('test_connector')

test_backend_1 = Backend(parent=test_backend, version='1')
Ejemplo n.º 12
0
# -*- coding: utf-8 -*-
# Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.addons.connector.backend import Backend

jira = Backend('jira')
""" Generic QoQa Backend. """

jira_7_2_0 = Backend(parent=jira, version='7.2.0')
""" Backend for version 7.2.0 of Jira """
Ejemplo n.º 13
0
    def test_mapping_record_children(self):
        """ Map a record with children, using defined MapChild """

        backend = Backend('backend', '42')

        @backend
        class LineMapper(ImportMapper):
            _model_name = 'res.currency.rate'
            direct = [('name', 'name')]

            @mapping
            def price(self, record):
                return {'rate': record['rate'] * 2}

            @only_create
            @mapping
            def discount(self, record):
                return {'test': .5}

        @backend
        class SaleLineImportMapChild(ImportMapChild):
            _model_name = 'res.currency.rate'

            def format_items(self, items_values):
                return [('ABC', values) for values in items_values]

        @backend
        class ObjectMapper(ImportMapper):
            _model_name = 'res.currency'

            direct = [('name', 'name')]

            children = [('lines', 'line_ids', 'res.currency.rate')]

        backend_record = mock.Mock()
        backend_record.get_backend.side_effect = lambda *a: backend
        backend_record.env = self.env
        env = ConnectorEnvironment(backend_record, 'res.currency')

        record = {
            'name':
            'SO1',
            'lines': [{
                'name': '2013-11-07',
                'rate': 10
            }, {
                'name': '2013-11-08',
                'rate': 20
            }]
        }
        mapper = ObjectMapper(env)
        map_record = mapper.map_record(record)
        expected = {
            'name':
            'SO1',
            'line_ids': [('ABC', {
                'name': '2013-11-07',
                'rate': 20
            }), ('ABC', {
                'name': '2013-11-08',
                'rate': 40
            })]
        }
        self.assertEqual(map_record.values(), expected)
        expected = {
            'name':
            'SO1',
            'line_ids': [('ABC', {
                'name': '2013-11-07',
                'rate': 20,
                'test': .5
            }), ('ABC', {
                'name': '2013-11-08',
                'rate': 40,
                'test': .5
            })]
        }
        self.assertEqual(map_record.values(for_create=True), expected)