当前位置: 首页>>代码示例>>Python>>正文


Python ConnectorSession.is_module_installed方法代码示例

本文整理汇总了Python中openerp.addons.connector.session.ConnectorSession.is_module_installed方法的典型用法代码示例。如果您正苦于以下问题:Python ConnectorSession.is_module_installed方法的具体用法?Python ConnectorSession.is_module_installed怎么用?Python ConnectorSession.is_module_installed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openerp.addons.connector.session.ConnectorSession的用法示例。


在下文中一共展示了ConnectorSession.is_module_installed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_connector_session

# 需要导入模块: from openerp.addons.connector.session import ConnectorSession [as 别名]
# 或者: from openerp.addons.connector.session.ConnectorSession import is_module_installed [as 别名]
class test_connector_session(common.TransactionCase):
    """ Test ConnectorSession """

    def setUp(self):
        super(test_connector_session, self).setUp()
        self.context = {"lang": "fr_FR"}
        self.session = ConnectorSession(self.cr, self.uid, context=self.context)

    def test_env(self):
        """ Check the session properties """
        session = self.session
        self.assertEqual(session.cr, session.env.cr)
        self.assertEqual(session.uid, session.env.uid)
        self.assertEqual(session.context, session.env.context)
        self.assertEqual(session.pool, session.env.registry)

    def test_from_env(self):
        """ ConnectorSession.from_env(env) """
        session = ConnectorSession.from_env(self.env)
        self.assertEqual(session.cr, self.env.cr)
        self.assertEqual(session.uid, self.env.uid)
        self.assertEqual(session.context, self.env.context)
        self.assertEqual(session.pool, self.env.registry)

    def test_change_user(self):
        """
        Change the user and check if it is reverted correctly at the end
        """
        original_uid = self.session.uid
        original_env = self.session.env
        new_uid = self.env.ref("base.user_demo").id
        with self.session.change_user(new_uid):
            # a new openerp.api.Environment is generated with the user
            self.assertNotEqual(self.session.env, original_env)
            self.assertEqual(self.session.uid, new_uid)
        self.assertEqual(self.session.env, original_env)
        self.assertEqual(self.session.uid, original_uid)

    def test_model_with_transaction(self):
        """ Use a method on a model from the pool """
        res_users = self.registry("res.users").search_count(self.cr, self.uid, [])
        sess_res_users_obj = self.session.pool.get("res.users")
        sess_res_users = sess_res_users_obj.search_count(self.cr, self.uid, [])
        self.assertEqual(sess_res_users, res_users)

    def test_new_model_with_transaction(self):
        """ Use a method on a model from the new api """
        res_users = self.env["res.users"].search_count([])
        sess_res_users_model = self.session.env["res.users"]
        sess_res_users = sess_res_users_model.search_count([])
        self.assertEqual(sess_res_users, res_users)

    def test_change_context(self):
        """ Change the context, it is reverted at the end """
        test_key = "test_key"
        self.assertNotIn(test_key, self.session.context)
        with self.session.change_context({test_key: "value"}):
            self.assertEqual(self.session.context.get("test_key"), "value")
        self.assertNotIn(test_key, self.session.context)

    def test_change_context_keyword(self):
        """ Change the context by keyword, it is reverted at the end """
        test_key = "test_key"
        self.assertNotIn(test_key, self.session.context)
        with self.session.change_context(test_key="value"):
            self.assertEqual(self.session.context.get("test_key"), "value")
        self.assertNotIn(test_key, self.session.context)

    def test_change_context_uninitialized(self):
        """ Change the context on a session not initialized with a context """
        session = ConnectorSession(self.cr, self.uid)
        test_key = "test_key"
        with session.change_context({test_key: "value"}):
            self.assertEqual(session.context.get("test_key"), "value")
        self.assertNotIn(test_key, session.context)

    def test_is_module_installed(self):
        """ Test on an installed module """
        self.assertTrue(self.session.is_module_installed("connector"))

    def test_is_module_uninstalled(self):
        """ Test on an installed module """
        self.assertFalse(self.session.is_module_installed("lambda"))

    def test_is_module_installed_cache_not_propagated(self):
        """ Test if the cache is well different for the different modules """
        self.assertTrue(self.session.is_module_installed("connector"))
        self.assertFalse(self.session.is_module_installed("#dummy#"))

    def test_is_module_installed_cache_invalidation(self):
        """ Test on an invalidation of cache about installed modules """
        module = self.env["ir.module.module"]
        domain = [("name", "=", "base")]
        self.assertTrue(self.session.is_module_installed("base"))
        # only to check that the cache works, the in validation is done only
        # if the field state is modified by write method, UGLY but no other
        # solution
        self.env.cr.execute("UPDATE ir_module_module " "SET state='uninstalled' " "WHERE name='base'")
        self.assertTrue(self.session.is_module_installed("base"))
        module.search(domain).state = "uninstalled"
#.........这里部分代码省略.........
开发者ID:borni-dhifi,项目名称:odoo-magento-modules,代码行数:103,代码来源:test_session.py

示例2: test_connector_session

# 需要导入模块: from openerp.addons.connector.session import ConnectorSession [as 别名]
# 或者: from openerp.addons.connector.session.ConnectorSession import is_module_installed [as 别名]
class test_connector_session(common.TransactionCase):
    """ Test ConnectorSession """

    def setUp(self):
        super(test_connector_session, self).setUp()
        self.context = {'lang': 'fr_FR'}
        self.session = ConnectorSession(self.cr,
                                        self.uid,
                                        context=self.context)

    def test_env(self):
        """ Check the session properties """
        session = self.session
        self.assertEqual(session.cr, session.env.cr)
        self.assertEqual(session.uid, session.env.uid)
        self.assertEqual(session.context, session.env.context)
        self.assertEqual(session.pool, session.env.registry)

    def test_from_env(self):
        """ ConnectorSession.from_env(env) """
        session = ConnectorSession.from_env(self.env)
        self.assertEqual(session.cr, self.env.cr)
        self.assertEqual(session.uid, self.env.uid)
        self.assertEqual(session.context, self.env.context)
        self.assertEqual(session.pool, self.env.registry)

    def test_change_user(self):
        """
        Change the user and check if it is reverted correctly at the end
        """
        original_uid = self.session.uid
        original_env = self.session.env
        new_uid = self.env.ref('base.user_demo').id
        with self.session.change_user(new_uid):
            # a new openerp.api.Environment is generated with the user
            self.assertNotEqual(self.session.env, original_env)
            self.assertEqual(self.session.uid, new_uid)
        self.assertEqual(self.session.env, original_env)
        self.assertEqual(self.session.uid, original_uid)

    def test_model_with_transaction(self):
        """ Use a method on a model from the pool """
        res_users = self.registry('res.users').search_count(self.cr,
                                                            self.uid,
                                                            [])
        sess_res_users_obj = self.session.pool.get('res.users')
        sess_res_users = sess_res_users_obj.search_count(self.cr,
                                                         self.uid,
                                                         [])
        self.assertEqual(sess_res_users, res_users)

    def test_new_model_with_transaction(self):
        """ Use a method on a model from the new api """
        res_users = self.env['res.users'].search_count([])
        sess_res_users_model = self.session.env['res.users']
        sess_res_users = sess_res_users_model.search_count([])
        self.assertEqual(sess_res_users, res_users)

    def test_change_context(self):
        """ Change the context, it is reverted at the end """
        test_key = 'test_key'
        self.assertNotIn(test_key, self.session.context)
        with self.session.change_context({test_key: 'value'}):
            self.assertEqual(self.session.context.get('test_key'), 'value')
        self.assertNotIn(test_key, self.session.context)

    def test_change_context_keyword(self):
        """ Change the context by keyword, it is reverted at the end """
        test_key = 'test_key'
        self.assertNotIn(test_key, self.session.context)
        with self.session.change_context(test_key='value'):
            self.assertEqual(self.session.context.get('test_key'), 'value')
        self.assertNotIn(test_key, self.session.context)

    def test_change_context_uninitialized(self):
        """ Change the context on a session not initialized with a context """
        session = ConnectorSession(self.cr, self.uid)
        test_key = 'test_key'
        with session.change_context({test_key: 'value'}):
            self.assertEqual(session.context.get('test_key'), 'value')
        self.assertNotIn(test_key, session.context)

    def test_is_module_installed(self):
        """ Test on an installed module """
        self.assertTrue(self.session.is_module_installed('connector'))

    def test_is_module_uninstalled(self):
        """ Test on an installed module """
        self.assertFalse(self.session.is_module_installed('lambda'))

    def test_is_module_installed_cache_not_propagated(self):
        """ Test if the cache is well different for the different modules """
        self.assertTrue(self.session.is_module_installed('connector'))
        self.assertFalse(self.session.is_module_installed('#dummy#'))
开发者ID:alangwansui,项目名称:odoo_magento_connector,代码行数:96,代码来源:test_session.py


注:本文中的openerp.addons.connector.session.ConnectorSession.is_module_installed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。