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)
Exemple #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'>")
 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)
Exemple #4
0
 def setUp(self):
     super(test_mapper_recordsets, 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')
 def setUp(self):
     super(TestCheckpoint, self).setUp()
     self.session = ConnectorSession(self.cr, self.uid)
     self.backend = Backend('dummy', version='1.0')
     self.backend_record = mock.Mock()
     self.backend_record._name = 'connector.backend'
     self.backend_record.id = 1
     self.backend_record.get_backend.return_value = self.backend
     self.partner = self.env.ref('base.main_partner')
Exemple #6
0
    def test_mapping_record_children_no_map_child(self):
        """ Map a record with children, using default 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 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
        env = ConnectorEnvironment(backend_record, self.session,
                                   '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': [(0, 0, {'name': '2013-11-07',
                                         'rate': 20}),
                                 (0, 0, {'name': '2013-11-08',
                                         'rate': 40})]
                    }
        self.assertEqual(map_record.values(), expected)
        expected = {'name': 'SO1',
                    'line_ids': [(0, 0, {'name': '2013-11-07',
                                         'rate': 20,
                                         'test': .5}),
                                 (0, 0, {'name': '2013-11-08',
                                         'rate': 40,
                                         'test': .5})]
                    }
        self.assertEqual(map_record.values(for_create=True), expected)
 def setUp(self):
     super(test_mapper_binding, self).setUp()
     self.session = ConnectorSession(self.cr, self.uid)
     self.Partner = self.registry('res.partner')
     self.backend = mock.Mock(wraps=Backend('x', version='y'),
                              name='backend')
     backend_record = mock.Mock()
     backend_record.get_backend.return_value = self.backend
     self.env = Environment(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
    def setUp(self):
        super(TestDefaultBinder, self).setUp()

        class PartnerBinder(Binder):
            "we use already existing fields for the binding"
            _model_name = 'res.partner'
            _external_field = 'ref'
            _sync_date_field = 'date'
            _backend_field = 'color'
            _openerp_field = 'id'

        self.session = ConnectorSession(self.cr, self.uid)
        self.backend = Backend('dummy', version='1.0')
        backend_record = mock.Mock()
        backend_record.id = 1
        backend_record.get_backend.return_value = self.backend
        self.connector_env = ConnectorEnvironment(
            backend_record, self.session, 'res.partner')
        self.partner_binder = PartnerBinder(self.connector_env)
Exemple #9
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)
Exemple #10
0
 def test_get_backend(self):
     """ Find a backend """
     backend = Backend(self.service)
     found_ref = get_backend(self.service)
     self.assertEqual(backend, found_ref)
Exemple #11
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')
Exemple #12
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)
Exemple #13
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)
Exemple #14
0
# -*- coding: utf-8 -*-
# Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from openerp.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 """
Exemple #15
0
    def test_mapping_record_children_filters(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}

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

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

            def skip_item(self, map_record):
                '''Filter by the values before the mapping'''
                record = map_record.source
                return (record['rate'] > 35)

            def skip_add_item(self, item_values):
                '''Filter by the values after the mapping'''
                return (item_values['rate'] < 30)

        @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
        env = ConnectorEnvironment(backend_record, self.session,
                                   'res.currency')

        record = {'name': 'SO1',
                  'lines': [{'name': '2013-11-07',
                             'rate': 10},
                            {'name': '2013-11-08',
                             'rate': 20},
                            {'name': '2013-11-09',
                             'rate': 30},
                            {'name': '2013-11-10',
                             'rate': 40}]
                  }
        mapper = ObjectMapper(env)
        map_record = mapper.map_record(record)
        expected = {'name': 'SO1',
                    'line_ids': [('ABC', {'name': '2013-11-08',
                                          'rate': 40}),
                                 ('ABC', {'name': '2013-11-09',
                                          'rate': 60})]
                    }
        self.assertEqual(map_record.values(), expected)
Exemple #16
0
# -*- coding: utf-8 -*-
# © 2013 Akretion (http://www.akretion.com)
# Raphaël Valyi <*****@*****.**>
# Sébastien BEAU <*****@*****.**>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.addons.connector.backend import Backend

nosql = Backend('nosql')
""" Generic Nosql Backend """
Exemple #17
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 OpenERP module 'not installed module'
        LambdaNoUnit._openerp_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 OpenERP module 'not installed module'
        LambdaNoUnit._openerp_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)
# -*- coding: utf-8 -*-
# Copyright 2017 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <*****@*****.**>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp.addons.connector.backend import Backend
from openerp.addons.connector_locomotivecms.backend import locomotive

shopinvader = Backend(parent=locomotive, version='shopinvader')
""" Shopinvader Backend"""

shopinvader_v1 = Backend(parent=shopinvader, version='shopinvader_v1')
# -*- coding: utf-8 -*-
# Copyright 2017 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <*****@*****.**>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from openerp.addons.connector.backend import Backend


locomotive = Backend('locomotive')
""" LocomotiveCMS Backend"""

locomotive_v3 = Backend(parent=locomotive, version='locomotive_v3')
""" LocomotiveCMS Backend"""
# -*- coding: utf-8 -*-
# © 2016 Akretion (http://www.akretion.com)
# Sébastien BEAU <*****@*****.**>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.addons.connector.backend import Backend
from openerp.addons.connector_nosql.backend import nosql

algolia = Backend(parent=nosql)
""" Algolia Backend"""

algolia = Backend(parent=algolia, version='algolia_v1')
""" Algolia Backend"""