[IMP] test_mail: Add multi company test from _redirect_to_record
This commit is contained in:
@@ -12,6 +12,7 @@ tests independently to functional aspects of other models. """,
|
||||
'depends': ['test_performance', 'mail', 'mail_bot'],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'security/test_mail_security.xml',
|
||||
'data/data.xml',
|
||||
],
|
||||
'demo': [
|
||||
|
||||
@@ -148,3 +148,13 @@ class MailCC(models.Model):
|
||||
_inherit = ['mail.thread.cc']
|
||||
|
||||
name = fields.Char()
|
||||
|
||||
|
||||
class MailMultiCompany(models.Model):
|
||||
""" This model can be used in multi company tests"""
|
||||
_name = 'mail.test.multi.company'
|
||||
_description = "Test Multi Company Mail"
|
||||
_inherit = 'mail.thread'
|
||||
|
||||
name = fields.Char()
|
||||
company_id = fields.Many2one('res.company')
|
||||
|
||||
@@ -14,4 +14,5 @@ access_mail_test_portal,mail.test.portal,model_mail_test,base.group_portal,1,1,0
|
||||
access_mail_test_user,mail.test.user,model_mail_test,base.group_user,1,1,1,1
|
||||
access_mail_test_cc_portal,mail.test.cc.portal,model_mail_test_cc,base.group_portal,1,0,0,0
|
||||
access_mail_test_cc_user,mail.test.cc.user,model_mail_test_cc,base.group_user,1,1,1,1
|
||||
|
||||
access_mail_test_multi_company_user,mail.test.multi.company.user,model_mail_test_multi_company,base.group_user,1,1,1,1
|
||||
access_mail_test_multi_company_portal,mail.test.multi.company.portal,model_mail_test_multi_company,base.group_portal,1,0,0,0
|
||||
|
||||
|
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
|
||||
<record id="mail_test_multi_company_rule" model="ir.rule">
|
||||
<field name="name">Mail Test Multi Company</field>
|
||||
<field name="model_id" ref="test_mail.model_mail_test_multi_company"/>
|
||||
<field eval="True" name="global"/>
|
||||
<field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
@@ -19,3 +19,4 @@ from . import test_discuss
|
||||
from . import test_performance
|
||||
from . import test_res_users
|
||||
from . import test_odoobot
|
||||
from . import test_multi_company
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from werkzeug.urls import url_decode, url_parse
|
||||
from odoo.tests.common import HttpCase
|
||||
|
||||
|
||||
class TestMultiCompany(HttpCase):
|
||||
|
||||
def test_redirect_to_records(self):
|
||||
|
||||
self.authenticate('admin', 'admin')
|
||||
|
||||
self.company_A = self.env['res.company'].create({
|
||||
'name': 'Company A',
|
||||
'user_ids': [(4, self.ref('base.user_admin'))],
|
||||
})
|
||||
|
||||
self.company_B = self.env['res.company'].create({
|
||||
'name': 'Company B',
|
||||
})
|
||||
|
||||
self.multi_company_record = self.env['mail.test.multi.company'].create({
|
||||
'name': 'Multi Company Record',
|
||||
'company_id': self.company_A.id,
|
||||
})
|
||||
|
||||
# Test Case 1
|
||||
# Logged into company 1, try accessing record in company A
|
||||
# _redirect_to_record should add company A in allowed_company_ids
|
||||
response = self.url_open('/mail/view?model=%s&res_id=%s' % (
|
||||
self.multi_company_record._name,
|
||||
self.multi_company_record.id), timeout=15)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
fragment = url_parse(response.url).fragment
|
||||
cids = url_decode(fragment)['cids']
|
||||
|
||||
self.assertEqual(cids, '1,%s' % (self.company_A.id))
|
||||
|
||||
# Test Case 2
|
||||
# Logged into company 1, try accessing record in company B
|
||||
# _redirect_to_record should redirect to messaging as the user
|
||||
# doesn't have any access for this company
|
||||
self.multi_company_record.company_id = self.company_B
|
||||
|
||||
response = self.url_open('/mail/view?model=%s&res_id=%s' % (
|
||||
self.multi_company_record._name,
|
||||
self.multi_company_record.id), timeout=15)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
fragment = url_parse(response.url).fragment
|
||||
action = url_decode(fragment)['action']
|
||||
|
||||
self.assertEqual(action, 'mail.action_discuss')
|
||||
Reference in New Issue
Block a user