Esempio n. 1
0
    def setUp(self):
        super(TestDefaultBinder, self).setUp()

        self.backend_record = self.env['test.backend'].create({
            'version': '1',
            'name': 'Test'
        })
        self.connector_env = ConnectorEnvironment(self.backend_record,
                                                  'connector.test.binding')
        self.binder = self.connector_env.get_connector_unit(Binder)
Esempio n. 2
0
 def _get_base_adapter(self):
     """
     Get an adapter to test the backend connection
     """
     self.ensure_one()
     env = self.env
     session = ConnectorSession(env.cr, env.uid, context=env.context)
     environment = ConnectorEnvironment(self, session, None)
     return DmsAdapter(environment)
Esempio 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')
Esempio n. 4
0
    def export_payment_methods(self):

        session = ConnectorEnvironment(self,  self._name)
        import_start_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        backend_id = self
        from_date = None
        self.env['payment.acquirer'].with_delay(
            priority=1).export_PaymentMethod_details(backend_id)

        return True
Esempio n. 5
0
    def export_invoice(self):

        session = ConnectorEnvironment(self,  self._name)
        import_start_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        backend_id = self
        from_date = None
        self.env['account.invoice'].with_delay(
            priority=1).export_invoice_details(backend_id)

        return True
def get_environment(session, model_name, backend_id):
    """ Create an environment to work with.  """
    backend_record = session.env['easypost.backend'].browse(backend_id)
    env = ConnectorEnvironment(backend_record, session, model_name)
    lang = backend_record.default_lang_id
    lang_code = lang.code if lang else 'en_US'
    if lang_code == session.context.get('lang'):
        return env
    else:
        with env.session.change_context(lang=lang_code):
            return env
Esempio n. 7
0
    def test_create_environment_no_connector_env(self):
        session = mock.MagicMock(name='Session')
        backend_record = mock.Mock(name='BackendRecord')
        backend = mock.Mock(name='Backend')
        backend_record.get_backend.return_value = backend
        model = 'res.user'

        connector_env = ConnectorEnvironment.create_environment(
            backend_record, session, model)

        self.assertEqual(type(connector_env), ConnectorEnvironment)
Esempio n. 8
0
 def import_taxrate(self):
     session = ConnectorEnvironment(self,  self._name)
     import_start_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
     backend_id = self.id
     from_date = None
     self.env['account.tax'].with_delay(priority=1).rate_import_batch(
         model_name='account.tax', backend_id=backend_id,
         filters={'from_date': from_date,
                  'to_date': import_start_time}
     )
     return True
Esempio n. 9
0
 def import_payment_method(self):
     session = ConnectorEnvironment(self,  self._name)
     import_start_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
     backend_id = self.id
     from_date = None
     self.env['payment.acquirer'].with_delay(priority=1).PaymentMethod_import_batch(
         model_name='payment.acquirer', backend_id=backend_id,
         filters={'from_date': from_date,
                  'to_date': import_start_time}
     )
     return True
Esempio n. 10
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
Esempio n. 11
0
class TestDefaultBinder(TransactionCase):
    """ Test the default binder implementation"""
    def setUp(self):
        super(TestDefaultBinder, self).setUp()

        backend_model = self.env['test.backend'].with_context(
            test_connector_units=True)
        self.backend_record = backend_model.create({
            'version': '1',
            'name': 'Test'
        })
        self.connector_env = ConnectorEnvironment(self.backend_record,
                                                  'connector.test.binding')
        self.binder = self.connector_env.get_connector_unit(Binder)

    def test_default_binder(self):
        """ Small scenario with the default binder """
        test_record = self.env['connector.test.record'].create({})
        test_binding = self.env['connector.test.binding'].create({
            'backend_id':
            self.backend_record.id,
            'odoo_id':
            test_record.id,
        })

        # bind the test binding to external id = 99
        self.binder.bind(99, test_binding)
        # find the odoo binding bound to external record 99
        binding = self.binder.to_internal(99)
        self.assertEqual(binding, test_binding)
        # find the odoo record bound to external record 99
        record = self.binder.to_internal(99, unwrap=True)
        self.assertEqual(record, test_record)
        # find the external record bound to odoo binding
        external_id = self.binder.to_external(test_binding)
        self.assertEqual(external_id, 99)
        # find the external record bound to odoo record
        external_id = self.binder.to_external(test_record, wrap=True)
        self.assertEqual(external_id, 99)
        self.assertEqual(self.binder.unwrap_model(), 'connector.test.record')
        # unwrapping the binding should give the same binding
        self.assertEqual(self.binder.unwrap_binding(test_binding), test_record)
Esempio n. 12
0
 def get_environment(self, binding_model_name):
     self.ensure_one()
     return ConnectorEnvironment(self, binding_model_name)
Esempio 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)
Esempio n. 14
0
def get_environment(session, model_name, backend_id):
    model = session.env.get('prestashop.backend')
    backend_record = model.browse(backend_id)
    return ConnectorEnvironment(backend_record, session, model_name)
Esempio n. 15
0
 def get_environment(self, model_name):
     self.ensure_one()
     yield ConnectorEnvironment(self, model_name)