Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Coopdevs OCB mirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Odoo
Coopdevs OCB mirror
Commits
97edd227
Commit
97edd227
authored
5 years ago
by
Victor Feyens
Browse files
Options
Downloads
Patches
Plain Diff
[IMP] base: test multi-company behavior.
parent
7bfcb53d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
odoo/addons/test_new_api/tests/test_company_checks.py
+49
-1
49 additions, 1 deletion
odoo/addons/test_new_api/tests/test_company_checks.py
with
49 additions
and
1 deletion
odoo/addons/test_new_api/tests/test_company_checks.py
+
49
−
1
View file @
97edd227
# -*- coding: utf-8 -*-
from
odoo.exceptions
import
UserError
from
odoo.exceptions
import
UserError
,
AccessError
from
odoo.tests
import
common
...
...
@@ -72,3 +72,51 @@ class TestCompanyCheck(common.TransactionCase):
'
company_id
'
:
self
.
company_b
.
id
,
})
def
test_company_environment
(
self
):
"""
Check the company context on the environment is verified.
"""
self
.
company_c
=
self
.
env
[
'
res.company
'
].
create
({
'
name
'
:
'
Company C
'
})
user
=
self
.
env
[
'
res.users
'
].
create
({
'
name
'
:
'
Test
'
,
'
login
'
:
'
test
'
,
'
company_id
'
:
self
.
company_a
.
id
,
'
company_ids
'
:
(
self
.
company_a
|
self
.
company_c
).
ids
,
})
user
=
user
.
with_user
(
user
).
with_context
(
allowed_company_ids
=
[])
# When accessing company/companies, check raises error if unauthorized/unexisting company.
with
self
.
assertRaises
(
AccessError
):
user
.
with_context
(
allowed_company_ids
=
[
self
.
company_a
.
id
,
self
.
company_b
.
id
,
self
.
company_c
.
id
]).
env
.
companies
with
self
.
assertRaises
(
AccessError
):
user
.
with_context
(
allowed_company_ids
=
[
self
.
company_b
.
id
]).
env
.
company
with
self
.
assertRaises
(
AccessError
):
# crap in company context is not allowed.
user
.
with_context
(
allowed_company_ids
=
[
'
company_qsdf
'
,
'
company564654
'
]).
env
.
companies
# In sudo mode, context check is bypassed.
companies
=
(
self
.
company_a
|
self
.
company_b
)
self
.
assertEqual
(
user
.
sudo
().
with_context
(
allowed_company_ids
=
companies
.
ids
).
env
.
companies
,
companies
)
self
.
assertEqual
(
user
.
sudo
().
with_context
(
allowed_company_ids
=
[
self
.
company_b
.
id
,
'
abc
'
]).
env
.
company
,
self
.
company_b
)
"""
wrong_env = user.sudo().with_context(
allowed_company_ids=[self.company_a.id, self.company_b.id,
'
abc
'
])
wrong_env.env.companies.mapped(
'
name
'
)
# Wrong SQL query due to wrong company id.
"""
# Fallbacks when no allowed_company_ids context key
self
.
assertEqual
(
user
.
env
.
company
,
user
.
company_id
)
self
.
assertEqual
(
user
.
env
.
companies
,
user
.
company_ids
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment