def test_login(self): res_users_obj = self.registry('res.users') res = res_users_obj.authenticate( common.get_db_name(), 'admin', 'admin', None) uid = res self.assertTrue(res, "Basic login must works as expected") token = "123456" res = res_users_obj.authenticate( common.get_db_name(), 'admin', token, None) self.assertFalse(res) # mimic what the new controller do when it find a value in # the http header (HTTP_REMODE_USER) res_users_obj.write(self.cr, self.uid, uid, {'sso_key': token}) # Here we need to mock the cursor since the login is natively done # inside its own connection with mock_cursor(self.cr): # We can verifies that the given (uid, token) is authorized for # the database res_users_obj.check(common.get_db_name(), uid, token) # we are able to login with the new token res = res_users_obj.authenticate( common.get_db_name(), 'admin', token, None) self.assertTrue(res)
def setUp(self): super(TestAPI, self).setUp() self.db_name = get_db_name() self.phantom_env = api.Environment(self.registry.test_cr, self.uid, {}) self.demo_user = self.phantom_env.ref(USER_DEMO) self.admin_user = self.phantom_env.ref(USER_ADMIN) self.model_name = "res.partner"
def test_empty_session(self): """ Create a session without transaction """ self.assertEqual(self.session_hdl.db_name, common.get_db_name()) self.assertEqual(self.session_hdl.uid, ADMIN_USER_ID) self.assertEqual(self.session_hdl.context, self.context)
def setUp(self): import openerp.modules super(TestTemplating, self).setUp() self._pool = openerp.modules.registry.RegistryManager.get(common.get_db_name()) self._init = self._pool._init # f**k off self._pool._init = False
def environment(): """ Return an environment with a new cursor for the current database; the cursor is committed and closed after the context block. """ reg = registry(common.get_db_name()) with reg.cursor() as cr: yield api.Environment(cr, SUPERUSER_ID, {}) cr.commit()
def test_with_session(self): """ Create a session from the handler """ with self.session_hdl.session() as session: pool = registry.RegistryManager.get(common.get_db_name()) self.assertIsNotNone(session.cr) self.assertEqual(session.pool, pool) self.assertEqual(session.context, self.session_hdl.context)
def setUp(self): super(TestAdvisoryLock, self).setUp() self.registry2 = RegistryManager.get(common.get_db_name()) self.cr2 = self.registry2.cursor() self.env2 = api.Environment(self.cr2, self.env.uid, {}) @self.addCleanup def reset_cr2(): # rollback and close the cursor, and reset the environments self.env2.reset() self.cr2.rollback() self.cr2.close()
def test_02_uninstall(self): """ Check a few things showing the module is uninstalled. """ with environment() as env: module = env['ir.module.module'].search([('name', '=', MODULE)]) assert len(module) == 1 module.button_uninstall() Registry.new(common.get_db_name(), update_module=True) with environment() as env: self.assertNotIn('test_uninstall.model', env.registry) self.assertFalse(env['ir.model.data'].search([('module', '=', MODULE)])) self.assertFalse(env['ir.model.fields'].search([('model', '=', MODEL)]))
def test_02_uninstall(self): """ Check a few things showing the module is uninstalled. """ with environment() as env: module = env['ir.module.module'].search([('name', '=', MODULE)]) assert len(module) == 1 module.button_uninstall() RegistryManager.new(common.get_db_name(), update_module=True) with environment() as env: self.assertNotIn('test_uninstall.model', env.registry) self.assertFalse(env['ir.model.data'].search([('module', '=', MODULE)])) self.assertFalse(env['ir.model.fields'].search([('model', '=', MODEL)]))
def setUp(self): super(TestImportMagentoConcurrentSync, self).setUp() self.registry2 = RegistryManager.get(get_db_name()) self.cr2 = self.registry2.cursor() self.env2 = api.Environment(self.cr2, self.env.uid, {}) backend2 = mock.Mock(name='Backend Record') backend2._name = 'magento.backend' backend2.id = self.backend_id self.backend2 = backend2 self.connector_session2 = ConnectorSession.from_env(self.env2) @self.addCleanup def reset_cr2(): # rollback and close the cursor, and reset the environments self.env2.reset() self.cr2.rollback() self.cr2.close()
def setUp(self): super(TestImportMagentoConcurrentSync, self).setUp() self.registry2 = RegistryManager.get(get_db_name()) self.cr2 = self.registry2.cursor() self.env2 = api.Environment(self.cr2, self.env.uid, {}) backend2 = mock.MagicMock(name='Backend Record') backend2._name = 'magento.backend' backend2.id = self.backend_id self.backend2 = backend2 self.connector_session2 = ConnectorSession.from_env(self.env2) @self.addCleanup def reset_cr2(): # rollback and close the cursor, and reset the environments self.env2.reset() self.cr2.rollback() self.cr2.close()
def registry(model): return openerp.modules.registry.RegistryManager.get(common.get_db_name())[model]
def reload_registry(): openerp.modules.registry.RegistryManager.new(common.get_db_name(), update_module=True)
def get_module(module_name): registry = openerp.modules.registry.RegistryManager.get( common.get_db_name()) return registry.get(module_name)
def reload_registry(): openerp.modules.registry.RegistryManager.new( common.get_db_name(), update_module=True)
def get_module(module_name): registry = openerp.modules.registry.RegistryManager.get(common.get_db_name()) return registry.get(module_name)
def registry(): return openerp.modules.registry.RegistryManager.get(common.get_db_name())
def setUp(self): super(test_connector_session_handler, self).setUp() self.context = {'lang': 'fr_FR'} self.session_hdl = ConnectorSessionHandler(common.get_db_name(), ADMIN_USER_ID, context=self.context)
def open_session(self): self.session.open(db=get_db_name())
def cursor(): return openerp.modules.registry.RegistryManager.get(common.get_db_name()).cursor()
def setUp(self): super(test_connector_session_handler, self).setUp() self.context = {"lang": "fr_FR"} self.session_hdl = ConnectorSessionHandler(common.get_db_name(), ADMIN_USER_ID, context=self.context)