本文整理汇总了Python中openerp.addons.connector.session.ConnectorSession.change_user方法的典型用法代码示例。如果您正苦于以下问题:Python ConnectorSession.change_user方法的具体用法?Python ConnectorSession.change_user怎么用?Python ConnectorSession.change_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openerp.addons.connector.session.ConnectorSession
的用法示例。
在下文中一共展示了ConnectorSession.change_user方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_connector_session
# 需要导入模块: from openerp.addons.connector.session import ConnectorSession [as 别名]
# 或者: from openerp.addons.connector.session.ConnectorSession import change_user [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_change_user(self):
"""
Change the user and check if it is reverted correctly at the end
"""
original_uid = self.session.uid
new_uid = 2
with self.session.change_user(new_uid):
self.assertEqual(self.session.uid, new_uid)
self.assertEqual(self.session.uid, original_uid)
def test_model_with_transaction(self):
"""
Create a session with a model name, we should be able to access
the model from a transaction
"""
res_users = self.registry('res.users')
self.assertEqual(self.session.pool.get('res.users'), res_users)
示例2: test_connector_session
# 需要导入模块: from openerp.addons.connector.session import ConnectorSession [as 别名]
# 或者: from openerp.addons.connector.session.ConnectorSession import change_user [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_change_user(self):
"""
Change the user and check if it is reverted correctly at the end
"""
original_uid = self.session.uid
new_uid = 2
with self.session.change_user(new_uid):
self.assertEqual(self.session.uid, new_uid)
self.assertEqual(self.session.uid, original_uid)
def test_model_with_transaction(self):
"""
Create a session with a model name, we should be able to access
the model from a transaction
"""
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_change_context(self):
"""
Change the context and check if it is reverted correctly at the end
"""
test_key = 'test_key'
self.assertNotIn(test_key, self.session.context)
with self.session.change_context({test_key: 'value'}):
self.assertIn(test_key, self.session.context)
self.assertNotIn(test_key, self.session.context)
# change the context on a session not initialized with a context
session = ConnectorSession(self.cr, self.uid)
with session.change_context({test_key: 'value'}):
self.assertIn(test_key, session.context)
self.assertNotIn(test_key, session.context)
示例3: test_connector_session
# 需要导入模块: from openerp.addons.connector.session import ConnectorSession [as 别名]
# 或者: from openerp.addons.connector.session.ConnectorSession import change_user [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"
#.........这里部分代码省略.........
示例4: TestJobStorageMultiCompany
# 需要导入模块: from openerp.addons.connector.session import ConnectorSession [as 别名]
# 或者: from openerp.addons.connector.session.ConnectorSession import change_user [as 别名]
class TestJobStorageMultiCompany(common.TransactionCase):
""" Test storage of jobs """
def setUp(self):
super(TestJobStorageMultiCompany, self).setUp()
self.session = ConnectorSession(self.cr, self.uid, context={})
self.queue_job = self.env['queue.job']
grp_connector_manager = self.ref("connector.group_connector_manager")
User = self.env['res.users']
Company = self.env['res.company']
Partner = self.env['res.partner']
self.other_partner_a = Partner.create(
{"name": "My Company a",
"is_company": True,
"email": "[email protected]",
})
self.other_company_a = Company.create(
{"name": "My Company a",
"partner_id": self.other_partner_a.id,
"rml_header1": "My Company Tagline",
"currency_id": self.ref("base.EUR")
})
self.other_user_a = User.create(
{"partner_id": self.other_partner_a.id,
"company_id": self.other_company_a.id,
"company_ids": [(4, self.other_company_a.id)],
"login": "my_login a",
"name": "my user",
"groups_id": [(4, grp_connector_manager)]
})
self.other_partner_b = Partner.create(
{"name": "My Company b",
"is_company": True,
"email": "[email protected]",
})
self.other_company_b = Company.create(
{"name": "My Company b",
"partner_id": self.other_partner_b.id,
"rml_header1": "My Company Tagline",
"currency_id": self.ref("base.EUR")
})
self.other_user_b = User.create(
{"partner_id": self.other_partner_b.id,
"company_id": self.other_company_b.id,
"company_ids": [(4, self.other_company_b.id)],
"login": "my_login_b",
"name": "my user 1",
"groups_id": [(4, grp_connector_manager)]
})
def _create_job(self):
self.cr.execute('delete from queue_job')
job(task_a)
task_a.delay(self.session, 'res.users')
stored = self.queue_job.search([])
self.assertEqual(len(stored), 1)
return stored
def test_job_default_company_id(self):
"""the default company is the one from the current user_id"""
stored = self._create_job()
self.assertEqual(stored.company_id.id,
self.ref("base.main_company"),
'Incorrect default company_id')
with self.session.change_user(self.other_user_b.id):
stored = self._create_job()
self.assertEqual(stored.company_id.id,
self.other_company_b.id,
'Incorrect default company_id')
def test_job_no_company_id(self):
""" if we put an empty company_id in the context
jobs are created without company_id"""
with self.session.change_context({'company_id': None}):
stored = self._create_job()
self.assertFalse(stored.company_id,
' Company_id should be empty')
def test_job_specific_company_id(self):
"""If a company_id specified in the context
it's used by default for the job creation"""
s = self.session
with s.change_context({'company_id': self.other_company_a.id}):
stored = self._create_job()
self.assertEqual(stored.company_id.id,
self.other_company_a.id,
'Incorrect company_id')
def test_job_subscription(self):
# if the job is created without company_id, all members of
# connector.group_connector_manager must be followers
User = self.env['res.users']
with self.session.change_context(company_id=None):
stored = self._create_job()
stored._subscribe_users()
users = User.search(
[('groups_id', '=', self.ref('connector.group_connector_manager'))]
)
self.assertEqual(len(stored.message_follower_ids), len(users))
expected_partners = [u.partner_id for u in users]
#.........这里部分代码省略.........
示例5: test_connector_session
# 需要导入模块: from openerp.addons.connector.session import ConnectorSession [as 别名]
# 或者: from openerp.addons.connector.session.ConnectorSession import change_user [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#'))
示例6: test_job_storage_multi_company
# 需要导入模块: from openerp.addons.connector.session import ConnectorSession [as 别名]
# 或者: from openerp.addons.connector.session.ConnectorSession import change_user [as 别名]
class test_job_storage_multi_company(common.TransactionCase):
""" Test storage of jobs """
def setUp(self):
super(test_job_storage_multi_company, self).setUp()
self.pool = openerp.modules.registry.RegistryManager.get(common.DB)
self.session = ConnectorSession(self.cr, self.uid, context={})
self.queue_job = self.registry('queue.job')
self.other_partner_id_a = self.registry('res.partner').create(self.cr, self.uid, {
"name": "My Company a",
"is_company": True,
"email": "[email protected]",
})
self.other_company_id_a = self.registry('res.company').create(self.cr, self.uid, {
"name": "My Company a",
"partner_id": self.other_partner_id_a,
"rml_header1": "My Company Tagline",
"currency_id": self.ref("base.EUR")
})
self.other_user_id_a = self.registry('res.users').create(self.cr, self.uid, {
"partner_id": self.other_partner_id_a,
"company_id": self.other_company_id_a,
"company_ids": [(4, self.other_company_id_a)],
"login": "my_login a",
"name": "my user",
"groups_id": [
(4, self.ref("connector.group_connector_manager"))]
})
self.other_partner_id_b = self.registry('res.partner').create(self.cr, self.uid, {
"name": "My Company b",
"is_company": True,
"email": "[email protected]",
})
self.other_company_id_b = self.registry('res.company').create(self.cr, self.uid, {
"name": "My Company b",
"partner_id": self.other_partner_id_b,
"rml_header1": "My Company Tagline",
"currency_id": self.ref("base.EUR")
})
self.other_user_id_b = self.registry('res.users').create(self.cr, self.uid, {
"partner_id": self.other_partner_id_b,
"company_id": self.other_company_id_b,
"company_ids": [(4, self.other_company_id_b)],
"login": "my_login_b",
"name": "my user 1",
"groups_id": [
(4, self.ref("connector.group_connector_manager"))]
})
def _create_job(self):
self.cr.execute('delete from queue_job')
job(task_a)
task_a.delay(self.session, 'res.users')
stored = self.queue_job.search(self.cr, self.uid, [])
self.assertEqual(len(stored), 1)
return self.queue_job.browse(self.cr, self.uid, stored[0])
def test_job_default_company_id(self):
"""the default company is the one from the current user_id"""
stored_brw = self._create_job()
self.assertEqual(
stored_brw.company_id.id,
self.ref("base.main_company"),
'Incorrect default company_id')
with self.session.change_user(self.other_user_id_b):
stored_brw = self._create_job()
self.assertEqual(
stored_brw.company_id.id,
self.other_company_id_b,
'Incorrect default company_id')
def test_job_no_company_id(self):
""" if we put an empty company_id in the context
jobs are created without company_id"""
with self.session.change_context({'company_id': None}):
stored_brw = self._create_job()
self.assertFalse(
stored_brw.company_id,
' Company_id should be empty')
def test_job_specific_company_id(self):
"""If a company_id specified in the context
it's used by default for the job creation"""
with self.session.change_context({'company_id': self.other_company_id_a}):
stored_brw = self._create_job()
self.assertEqual(
stored_brw.company_id.id,
self.other_company_id_a,
'Incorrect company_id')
def test_job_subscription(self):
# if the job is created without company_id, all members of
# connector.group_connector_manager must be followers
with self.session.change_context({'company_id': None}):
stored_brw = self._create_job()
self.queue_job. _subscribe_users(self.cr, self.uid, [stored_brw.id])
stored_brw.refresh()
user_ids = self.registry('res.users').search(
self.cr, self.uid, [('groups_id', '=', self.ref('connector.group_connector_manager'))])
self.assertEqual(len(stored_brw.message_follower_ids), len(user_ids))
#.........这里部分代码省略.........