From 7ea21adabe007eff6b5b69aa451d756dff54442b Mon Sep 17 00:00:00 2001 From: lul-odoo Date: Thu, 27 Jun 2019 10:22:55 +0200 Subject: [PATCH] [IMP] test_website: Add multi-company test Purpose ======= This commit tests some behaviors with multi company mode after changes brought by f847a46. Specification ============= The website company should be automatically set in the context as 'allowed_company_ids'. That way, we can remove the switch company menu on the website, which doesn't make a lot of sense. This test enforce this behavior. --- addons/test_website/controllers/main.py | 4 ++++ addons/test_website/tests/__init__.py | 1 + addons/test_website/tests/test_multi_company.py | 16 ++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 addons/test_website/tests/test_multi_company.py diff --git a/addons/test_website/controllers/main.py b/addons/test_website/controllers/main.py index 259072c81ff..ae45d160b06 100644 --- a/addons/test_website/controllers/main.py +++ b/addons/test_website/controllers/main.py @@ -36,3 +36,7 @@ class WebsiteTest(Home): @http.route('/ignore_args/converter//nokw', type='http', auth="public", website=True) def test_ignore_args_converter_nokw(self, a, b='youhou'): return request.make_response(json.dumps(dict(a=a, b=b))) + + @http.route('/multi_company_website', type='http', auth="public", website=True) + def test_company_context(self): + return request.make_response(json.dumps(request.context.get('allowed_company_ids'))) diff --git a/addons/test_website/tests/__init__.py b/addons/test_website/tests/__init__.py index 40d4ece53e7..4bb004cd8f9 100644 --- a/addons/test_website/tests/__init__.py +++ b/addons/test_website/tests/__init__.py @@ -4,3 +4,4 @@ from . import test_controller_args from . import test_reset_views from . import test_views_during_module_operation +from . import test_multi_company diff --git a/addons/test_website/tests/test_multi_company.py b/addons/test_website/tests/test_multi_company.py new file mode 100644 index 00000000000..8c9c6859959 --- /dev/null +++ b/addons/test_website/tests/test_multi_company.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.tests.common import HttpCase, tagged + + +@tagged('post_install', '-at_install') +class TestMultiCompany(HttpCase): + + def test_company_in_context(self): + """ Test website company is set in context """ + website = self.env['website'].browse(1) + company = self.env['res.company'].create({'name': "Adaa"}) + website.company_id = company + response = self.url_open('/multi_company_website') + self.assertEqual(response.json()[0], company.id)