def test_unit_for_other_model(self):
        class ModelUnit(ConnectorUnit):
            _model_name = 'res.partner'

        class ModelBinder(ConnectorUnit):
            _model_name = 'res.partner'

        session = mock.MagicMock(name='Session')
        backend_record = mock.Mock(name='BackendRecord')
        backend = mock.Mock(name='Backend')
        backend_record.get_backend.return_value = backend
        # backend.get_class() is tested in test_backend.py
        backend.get_class.return_value = ModelUnit
        connector_env = connector.ConnectorEnvironment(backend_record, session,
                                                       'res.users')
        unit = ConnectorUnit(connector_env)
        # returns an instance of ModelUnit with a new connector_env
        # for the different model
        new_unit = unit.unit_for(ModelUnit, model='res.partner')
        self.assertEqual(type(new_unit), ModelUnit)
        self.assertNotEqual(new_unit.connector_env, connector_env)
        self.assertEqual(new_unit.connector_env.model_name, 'res.partner')

        backend.get_class.return_value = ModelBinder
        # returns an instance of ModelBinder with a new connector_env
        # for the different model
        new_unit = unit.binder_for(model='res.partner')
        self.assertEqual(type(new_unit), ModelBinder)
        self.assertNotEqual(new_unit.connector_env, connector_env)
        self.assertEqual(new_unit.connector_env.model_name, 'res.partner')
def mock_connector_unit(env):
    session = ConnectorSession(env.cr, env.uid, context=env.context)
    backend_record = mock.Mock(name='BackendRecord')
    backend = mock.Mock(name='Backend')
    backend_record.get_backend.return_value = backend
    connector_env = connector.ConnectorEnvironment(backend_record, session,
                                                   'res.users')
    return ConnectorUnit(connector_env)
Beispiel #3
0
    def test_instance(self):

        class ModelUnit(ConnectorUnit):
            _model_name = 'res.users'

        session = ConnectorSession(self.env.cr, self.env.uid,
                                   context=self.env.context)
        backend_record = mock.Mock(name='BackendRecord')
        backend = mock.Mock(name='Backend')
        backend_record.get_backend.return_value = backend
        connector_env = connector.ConnectorEnvironment(backend_record,
                                                       session,
                                                       'res.users')
        unit = ConnectorUnit(connector_env)
        self.assertEqual(unit.model, self.env['res.users'])
        self.assertEqual(unit.env, self.env)
        self.assertEqual(unit.localcontext, self.env.context)